ci: 同一个 job 里先 build 后 publish,不用 artifact #10

Merged
layue13 merged 1 commits from ci/single-job-publish into master 2026-11-19 06:13:09 +00:00
+7 -35
View File
@@ -57,40 +57,10 @@ jobs:
env:
GRADLE_ARGS: ${{ inputs.gradle-args }}
run: ./gradlew applyPatches build --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain
# 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"
# 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 }}
@@ -99,15 +69,17 @@ 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 (publish-only=true): there is no build job to take a workspace from, so it builds by itself.
# 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