name: Build on: push: paths-ignore: - '**.md' - 'reports/**' - '.github/ISSUE_TEMPLATE/**' - '.gitignore' pull_request: workflow_dispatch: inputs: module-ref: description: Commit to build (default is the dispatched ref) required: false default: '' gradle-args: description: Extra arguments for the upstream build required: false default: '' publish: 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' permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch }} # Organisation-wide Stratum settings (registry, group, runner routes) are organisation variables. env: STRATUM_PUBLISH_URL: ${{ vars.STRATUM_PUBLISH_URL }} STRATUM_RESOLVE_URL: ${{ vars.STRATUM_RESOLVE_URL }} STRATUM_GROUP_ID: ${{ vars.STRATUM_GROUP_ID }} STRATUM_ROUTES: ${{ vars.STRATUM_ROUTES }} STRATUM_LOCALE: ${{ vars.STRATUM_LOCALE }} jobs: build: 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: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: ref: ${{ inputs.module-ref || github.sha }} submodules: true - uses: ./.github/actions/setup-build - name: Build env: GRADLE_ARGS: ${{ inputs.gradle-args }} run: | set -o pipefail run_build() { ./gradlew applyPatches build --args="$GRADLE_ARGS --no-daemon --console=plain" --no-daemon --console=plain 2>&1 | tee "$RUNNER_TEMP/build.log" } # Spotless 8.x dies at Gradle input fingerprinting on a fraction of runs # (diffplug/spotless#2927). This runner also drops TLS handshakes to maven # mirrors and plugin hosts. Two attempts stay inside the 90 minute timeout. for attempt in 1 2; do if run_build; then exit 0; fi if ! grep -Eq 'roundtripStateInternal or equalityStateInternal|Remote host terminated the handshake|Read timed out|Connection reset|Premature end of Content-Length|failed: timeout' "$RUNNER_TEMP/build.log"; then echo "::error::build failed for a reason other than the known spotless/network flakes; not retrying." exit 1 fi echo "::warning::known flake (spotless#2927 or transport), attempt $attempt; retrying." done exit 1 # 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 }} # 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: if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish-only == 'true' }} runs-on: ubuntu-latest timeout-minutes: 90 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: ref: ${{ inputs.module-ref || github.sha }} 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" exit 1 fi - 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