Skip to content

Commit

Permalink
Refactor workflow
Browse files Browse the repository at this point in the history
Signed-off-by: John Niang <[email protected]>
  • Loading branch information
JohnNiang committed Jan 9, 2024
1 parent 0b30c0d commit e9e44d7
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 61 deletions.
61 changes: 61 additions & 0 deletions .github/actions/setup-env/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Setup Environment
description: Setup environment to check and build Halo, including console and core projects.

inputs:
node-version:
description: Node.js version.
required: false
default: "18"

pnpm-version:
description: pnpm version.
required: false
default: "8"

java-version:
description: Java version.
required: false
default: "17"

runs:
using: "composite"
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- uses: pnpm/action-setup@v2
name: Setup pnpm
id: pnpm-install
with:
version: ${{ inputs.pnpm-version }}
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH}}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: "temurin"
cache: "gradle"
java-version: ${{ inputs.java-version }}

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
107 changes: 46 additions & 61 deletions .github/workflows/halo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,65 @@ on:
- "**"
- "!**.md"
release:
types: # This configuration does not affect the page_build event above
- created
types:
- published

jobs:
check:
test:
runs-on: ubuntu-latest
# Default steps
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
cache: 'gradle'
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
console:
- 'console/**'
- name: Check halo
- name: Setup Environment
uses: ./.github/actions/setup-env
- name: Check Halo console
run: make -C console check
- name: Check Halo core
run: ./gradlew check
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Analyze code
if: ${{ github.event_name == 'push' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed.
if: ${{ github.event_name == 'push' && env.SONAR_TOKEN != '' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar --info
- name: Setup console environment
if: steps.changes.outputs.console == 'true'
uses: halo-sigs/actions/admin-env-setup@main
- name: Check console
if: steps.changes.outputs.console == 'true'
run: make -C console check
docker-build-and-push:
build:
runs-on: ubuntu-latest
needs: check
needs: test
steps:
- uses: actions/checkout@v3
- uses: halo-sigs/actions/halo-next-docker-build@main # change the version to specific ref or release tag while the action is stable.
if: github.event_name != 'pull_request'
with:
image-name: ${{ github.event_name == 'release' && 'halo' || 'halo-dev' }}
ghcr-token: ${{ secrets.GHCR_TOKEN }}
dockerhub-user: ${{ secrets.DOCKER_USERNAME }}
dockerhub-token: ${{ secrets.DOCKER_TOKEN }}
push: ${{ github.event_name == 'push' || github.event_name == 'release' }} # we only push to GHCR if the push is to the next branch
console-ref: ${{ github.event_name == 'release' && github.ref || 'main' }}
platforms: linux/amd64,linux/arm64/v8,linux/ppc64le,linux/s390x
- uses: halo-sigs/actions/halo-next-docker-build@main
if: github.event_name == 'pull_request'
with:
image-name: halo-dev
push: false
console-ref: false
load: true
platforms: ""
- name: E2E Testing
if: github.event_name == 'pull_request'
- name: Setup Environment
uses: ./.github/actions/setup-env
- name: Build Halo console
run: make -C console build
- name: Reset version of Halo
if: github.event_name == 'release'
shell: bash
run: |
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod u+x /usr/local/bin/docker-compose
# Set the version with tag name when releasing
version=${{ github.event.release.tag_name }}
version=${version#v}
sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties
- name: Build Halo core
run: ./gradlew clean && ./gradlew downloadPluginPresets && ./gradlew build -x check
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: halo-artifacts
path: application/build/libs
retention-days: 1

repo=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
docker tag ghcr.io/${repo}/halo-dev:pr-${{ github.event.number }} ghcr.io/halo-dev/halo-dev:main
cd e2e && make all
github-release:
runs-on: ubuntu-latest
# if: github.event_name == 'release'
needs: build
steps:
- uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: halo-artifacts
path: application/build/libs
- name: Upload Artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: gh release upload ${{ github.event.release.tag_name }} application/build/libs/*
run: gh release upload v1.5.1 application/build/libs/*

0 comments on commit e9e44d7

Please sign in to comment.