From 5b2455635746c6507e37b8fa8a3185be08f278b1 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Sat, 4 May 2024 12:17:28 +0800 Subject: [PATCH] chore: update workflows config (#96) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What this PR does? 使用 [reusable workflows](https://github.com/halo-sigs/reusable-workflows) 替换原本的配置 ```release-note None ``` --- .github/workflows/build.yml | 127 ------------------------------------ .github/workflows/cd.yaml | 18 +++++ .github/workflows/ci.yaml | 15 +++++ build.gradle | 12 +++- 4 files changed, 42 insertions(+), 130 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/cd.yaml create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 5fecbd0..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,127 +0,0 @@ -name: Build Plugin JAR File - -on: - push: - branches: [ main ] - release: - types: - - created - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - cache: 'gradle' - java-version: 17 - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 18 - - uses: pnpm/action-setup@v2.0.1 - name: Install pnpm - id: pnpm-install - with: - version: 8 - run_install: false - - name: Get pnpm store directory - id: pnpm-cache - run: | - echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/console/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install Frontend Dependencies - run: | - ./gradlew pnpmInstall - - name: Build with Gradle - run: | - # 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 - ./gradlew clean build -x test - - name: Archive plugin-moments jar - uses: actions/upload-artifact@v2 - with: - name: plugin-moments - path: | - build/libs/*.jar - retention-days: 1 - - github-release: - runs-on: ubuntu-latest - needs: build - if: github.event_name == 'release' - steps: - - name: Download plugin-moments jar - uses: actions/download-artifact@v2 - with: - name: plugin-moments - path: build/libs - - name: Get Name of Artifact - id: get_artifact - run: | - ARTIFACT_PATHNAME=$(ls build/libs/*.jar | head -n 1) - ARTIFACT_NAME=$(basename ${ARTIFACT_PATHNAME}) - echo "Artifact pathname: ${ARTIFACT_PATHNAME}" - echo "Artifact name: ${ARTIFACT_NAME}" - echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV - echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV - echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV - - name: Upload a Release Asset - uses: actions/github-script@v2 - if: github.event_name == 'release' - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - console.log('environment', process.versions); - - const fs = require('fs').promises; - - const { repo: { owner, repo }, sha } = context; - console.log({ owner, repo, sha }); - - const releaseId = process.env.RELEASE_ID - const artifactPathName = process.env.ARTIFACT_PATHNAME - const artifactName = process.env.ARTIFACT_NAME - console.log('Releasing', releaseId, artifactPathName, artifactName) - - await github.repos.uploadReleaseAsset({ - owner, repo, - release_id: releaseId, - name: artifactName, - data: await fs.readFile(artifactPathName) - }); - app-store-release: - runs-on: ubuntu-latest - needs: build - if: github.event_name == 'release' - steps: - - uses: actions/checkout@v2 - with: - submodules: true - - name: Download plugin-moments jar - uses: actions/download-artifact@v2 - with: - name: plugin-moments - path: build/libs - - name: Sync to Halo App Store - uses: halo-sigs/app-store-release-action@main - with: - github-token: ${{secrets.GITHUB_TOKEN}} - app-id: ${{secrets.APP_ID}} - release-id: ${{ github.event.release.id }} - assets-dir: "build/libs" - halo-username: ${{ secrets.HALO_USERNAME }} - halo-password: ${{ secrets.HALO_PASSWORD }} diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml new file mode 100644 index 0000000..edf7f67 --- /dev/null +++ b/.github/workflows/cd.yaml @@ -0,0 +1,18 @@ +name: CD + +on: + release: + types: + - published + +jobs: + cd: + uses: halo-sigs/reusable-workflows/.github/workflows/plugin-cd.yaml@v1 + secrets: + halo-username: ${{ secrets.HALO_USERNAME }} + halo-password: ${{ secrets.HALO_PASSWORD }} + permissions: + contents: write + with: + app-id: app-SnwWD + ui-path: "console" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..ce0d7f6 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,15 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + ci: + uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v1 + with: + ui-path: "console" diff --git a/build.gradle b/build.gradle index e0d67cf..131cb2e 100644 --- a/build.gradle +++ b/build.gradle @@ -29,13 +29,19 @@ node { nodeProjectDir = file("${project.projectDir}/console") } -task buildFrontend(type: PnpmTask) { +tasks.register('installDepsForUI', PnpmTask) { + args = ['install'] +} + +tasks.register('buildFrontend', PnpmTask) { args = ['build'] + dependsOn('installDepsForUI') } build { - // build frontend before build - tasks.getByName('compileJava').dependsOn('buildFrontend') + tasks.named('compileJava').configure { + dependsOn('buildFrontend') + } } halo {