From b9cac67ec7c83fd645a1910583407092995d99b2 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:40:05 +0800 Subject: [PATCH] Update GitHub Actions workflow for release builds --- .github/workflows/build-and-test.yml | 76 +++++++++++++++++++++------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index bff9a446..f6775bfe 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,23 +1,61 @@ -name: Fix Spotless Formatting -on: - workflow_dispatch: # 允许手动触发 +name: Release tagged build + +on: + workflow_dispatch: + push: + tags: [ '*' ] + +permissions: + contents: write jobs: - spotless-fix: + spotless-format: runs-on: ubuntu-latest + outputs: + formatted: ${{ steps.spotless.outputs.formatted }} steps: - - uses: actions/checkout@v2 - - name: Set up JDK - uses: actions/setup-java@v2 - with: - distribution: 'temurin' - java-version: '8' - - name: Run spotlessApply - run: ./gradlew spotlessApply - - name: Commit changes - run: | - git config --global user.name 'GitHub Action' - git config --global user.email 'action@github.com' - git add -A - git commit -m 'Apply spotless formatting' || exit 0 - git push + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Run spotlessApply + id: spotless + run: | + chmod +x gradlew || true + ./gradlew spotlessApply || true + + # 检查是否有文件被格式化 + if [ -n "$(git status --porcelain)" ]; then + echo "Files were formatted by spotless" + echo "formatted=true" >> $GITHUB_OUTPUT + + # 配置 git + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + # 提交格式化更改 + git add . + git commit -m "Apply spotless formatting [skip ci]" + + # 更新 tag 指向新的提交 + # 获取当前 tag + TAG_NAME=${GITHUB_REF#refs/tags/} + git tag -f "${TAG_NAME}" + git push origin "${TAG_NAME}" --force + else + echo "No files needed formatting" + echo "formatted=false" >> $GITHUB_OUTPUT + fi + + release-tags: + needs: spotless-format + uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master + secrets: inherit