From 8ae404416cecd30d29b3f8eb601eaec2ec90a8fd Mon Sep 17 00:00:00 2001 From: Layue13 Date: Wed, 18 Nov 2026 23:29:47 +0800 Subject: [PATCH 1/3] ci: publish in the build job, reusing the build output --- .github/workflows/build.yml | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d52c3a..b9d3b05 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,11 @@ on: required: false default: '' publish: - description: Publish the package ('true' or 'false') + description: Publish after a successful build ('true' or 'false') + required: false + default: 'false' + publish-only: + description: Skip the build job and only publish (builds by itself first; 'true' or 'false') required: false default: 'false' @@ -40,7 +44,7 @@ env: jobs: build: - if: github.event_name != 'push' || github.ref_name == github.event.repository.default_branch + if: ${{ inputs.publish-only != 'true' && (github.event_name != 'push' || github.ref_name == github.event.repository.default_branch) }} runs-on: ubuntu-latest timeout-minutes: 90 steps: @@ -53,17 +57,31 @@ jobs: env: GRADLE_ARGS: ${{ inputs.gradle-args }} run: ./gradlew applyPatches build --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain + # Publishing reuses the workspace and task outputs of the build above, so nothing is rebuilt. + # The Maven credentials are set only on the two steps below; pull request events never reach them. + - name: Check the publish credentials + if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} + env: + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + run: | + if [[ -z "$MAVEN_USER" || -z "$MAVEN_PASSWORD" ]]; then + echo "::error::MAVEN_USER and MAVEN_PASSWORD are not set; cannot publish" + exit 1 + fi + - name: Publish + if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} + env: + GRADLE_ARGS: ${{ inputs.gradle-args }} + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + run: ./gradlew applyPatches publish --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain - publish: - # Runs only after the build above passed. The Maven credentials exist in this job and nowhere else, - # so a pull request build can never read them. - needs: build - if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} + # Manual re-publish of a commit: there is no build workspace to reuse, so this job builds by itself. + publish-only: + if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish-only == 'true' }} runs-on: ubuntu-latest - timeout-minutes: 30 - env: - MAVEN_USER: ${{ secrets.MAVEN_USER }} - MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + timeout-minutes: 90 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: @@ -71,6 +89,9 @@ jobs: submodules: true - uses: ./.github/actions/setup-build - name: Check the publish credentials + env: + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} run: | if [[ -z "$MAVEN_USER" || -z "$MAVEN_PASSWORD" ]]; then echo "::error::MAVEN_USER and MAVEN_PASSWORD are not set; cannot publish" @@ -79,4 +100,6 @@ jobs: - name: Publish env: GRADLE_ARGS: ${{ inputs.gradle-args }} + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} run: ./gradlew applyPatches publish --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain -- 2.47.3 From 387d0d03bfb0f9300c4ae5e1cacb474324dbe73c Mon Sep 17 00:00:00 2001 From: Layue13 Date: Wed, 18 Nov 2026 23:34:03 +0800 Subject: [PATCH 2/3] ci: skip applyPatches in the reuse publish step --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9d3b05..62609b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,7 +75,9 @@ jobs: GRADLE_ARGS: ${{ inputs.gradle-args }} MAVEN_USER: ${{ secrets.MAVEN_USER }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - run: ./gradlew applyPatches publish --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain + # No applyPatches here: re-applying the patches rewrites work/ and invalidates every cached task of the + # build step above (measured locally: 25s of full rebuild vs 6s). The build step already applied them. + run: ./gradlew publish --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain # Manual re-publish of a commit: there is no build workspace to reuse, so this job builds by itself. publish-only: -- 2.47.3 From 667b4e6aa1f236315d962f2b8377b9fff1fd239b Mon Sep 17 00:00:00 2001 From: Layue13 Date: Wed, 18 Nov 2026 23:52:35 +0800 Subject: [PATCH 3/3] ci: split publish into its own job fed by the build workspace artifact --- .github/workflows/build.yml | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62609b6..917fd38 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,10 +57,40 @@ jobs: env: GRADLE_ARGS: ${{ inputs.gradle-args }} run: ./gradlew applyPatches build --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain - # Publishing reuses the workspace and task outputs of the build above, so nothing is rebuilt. - # The Maven credentials are set only on the two steps below; pull request events never reach them. - - name: Check the publish credentials + # Only pushes and publish dispatches need the workspace afterwards; pull requests stop after the build. + - name: Pack the build workspace if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} + run: tar -czf "$RUNNER_TEMP/workspace.tgz" work build/stratum + - name: Upload the build workspace + if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} + uses: actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 + with: + name: workspace + path: ${{ runner.temp }}/workspace.tgz + retention-days: 1 + if-no-files-found: error + + # Publishes the exact workspace the build job produced, so nothing is rebuilt. The Maven credentials exist in + # this job and nowhere else, so a pull request build can never read them. + publish: + needs: build + if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ inputs.module-ref || github.sha }} + submodules: true + - uses: ./.github/actions/setup-build + - name: Download the build workspace + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a + with: + name: workspace + path: ${{ runner.temp }} + - name: Restore the build workspace + run: tar -xzf "$RUNNER_TEMP/workspace.tgz" + - name: Check the publish credentials env: MAVEN_USER: ${{ secrets.MAVEN_USER }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} @@ -69,17 +99,15 @@ jobs: echo "::error::MAVEN_USER and MAVEN_PASSWORD are not set; cannot publish" exit 1 fi + # No applyPatches: re-applying the patches rewrites work/ and invalidates every cached task of the build. - name: Publish - if: ${{ github.event_name == 'push' || inputs.publish == 'true' }} env: GRADLE_ARGS: ${{ inputs.gradle-args }} MAVEN_USER: ${{ secrets.MAVEN_USER }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - # No applyPatches here: re-applying the patches rewrites work/ and invalidates every cached task of the - # build step above (measured locally: 25s of full rebuild vs 6s). The build step already applied them. run: ./gradlew publish --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain - # Manual re-publish of a commit: there is no build workspace to reuse, so this job builds by itself. + # Manual re-publish of a commit (publish-only=true): there is no build job to take a workspace from, so it builds by itself. publish-only: if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish-only == 'true' }} runs-on: ubuntu-latest -- 2.47.3