|
| 1 | +# Build, smoke-test and (on pushes to main) publish this harness's image. |
| 2 | +# |
| 3 | +# The actual build/test/publish logic is centralized in Bowtie's reusable `harness-ci.yml` workflow |
| 4 | +# so that a fix to how we build images reaches every harness at once. |
| 5 | +# This file only wires up the triggers and the small amount of per-repository orchestration |
| 6 | +# (version bookkeeping and Dependabot automerge). |
| 7 | +name: Rebuild Bowtie Image |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + pull_request: |
| 12 | + push: |
| 13 | + branches-ignore: |
| 14 | + - "wip*" |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: images-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +permissions: {} |
| 21 | + |
| 22 | +jobs: |
| 23 | + meta: |
| 24 | + name: Collect the currently published version |
| 25 | + runs-on: ubuntu-latest |
| 26 | + outputs: |
| 27 | + latest-version: ${{ steps.version.outputs.value }} |
| 28 | + steps: |
| 29 | + - name: Install Bowtie |
| 30 | + uses: bowtie-json-schema/bowtie@a0ae283dca0a0d0eb2381a886d5499162f33c82a # main |
| 31 | + |
| 32 | + - name: Compute implementation name |
| 33 | + id: impl |
| 34 | + env: |
| 35 | + GH_REPOSITORY: ${{ github.repository }} |
| 36 | + run: echo "name=${GH_REPOSITORY##*/}" >> "$GITHUB_OUTPUT" |
| 37 | + |
| 38 | + - name: Compute the latest published implementation version |
| 39 | + id: version |
| 40 | + env: |
| 41 | + IMPL_NAME: ${{ steps.impl.outputs.name }} |
| 42 | + run: | |
| 43 | + # Empty on the very first build, before any image has been published. |
| 44 | + version=$(bowtie info --implementation "${IMPL_NAME}" --format json 2>/dev/null | jq -r '.version // empty' || true) |
| 45 | + echo "value=${version}" >> "$GITHUB_OUTPUT" |
| 46 | + echo "Latest published version: ${version:-<none>}" |
| 47 | +
|
| 48 | + ci: |
| 49 | + name: Build |
| 50 | + needs: meta |
| 51 | + # The template repository itself has no real harness to build. |
| 52 | + # Repositories created from it do, so this always runs for them. |
| 53 | + if: github.repository != 'bowtie-json-schema/test-harness-template' |
| 54 | + permissions: |
| 55 | + id-token: write # needed for build provenance attestation |
| 56 | + contents: read # needed for actions/checkout |
| 57 | + attestations: write # needed for build provenance attestation |
| 58 | + packages: write # needed for pushing to ghcr.io |
| 59 | + artifact-metadata: write # needed for build provenance attestation |
| 60 | + uses: bowtie-json-schema/bowtie/.github/workflows/harness-ci.yml@a0ae283dca0a0d0eb2381a886d5499162f33c82a # main |
| 61 | + with: |
| 62 | + # Only publish from pushes to the default branch; PRs build & smoke only. |
| 63 | + publish: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
| 64 | + is-latest: ${{ github.ref == 'refs/heads/main' }} |
| 65 | + # Override any of the following per harness as needed: |
| 66 | + # qemu: false # for toolchains that build multi-arch natively (Go, .NET) |
| 67 | + # smoke-continue-on-error: true # only if the impl can't pass smoke yet |
| 68 | + |
| 69 | + mark-previous-version: |
| 70 | + name: Tag the previous version's release |
| 71 | + needs: [ci, meta, automerge] |
| 72 | + runs-on: ubuntu-latest |
| 73 | + |
| 74 | + # When the freshly built version differs from what was previously |
| 75 | + # published, cut a release (and therefore a git tag) pinned to the previous |
| 76 | + # commit so `build-all` can rebuild that historical version on demand. |
| 77 | + # Skipped on a repository's first push, when there is no previous commit. |
| 78 | + if: | |
| 79 | + ( |
| 80 | + (github.event_name == 'push' && github.ref == 'refs/heads/main') |
| 81 | + || (github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]') |
| 82 | + ) |
| 83 | + && github.event.before != '0000000000000000000000000000000000000000' |
| 84 | + && needs.meta.outputs.latest-version != '' |
| 85 | + && needs.ci.outputs.current-version != needs.meta.outputs.latest-version |
| 86 | + && !cancelled() |
| 87 | +
|
| 88 | + permissions: |
| 89 | + contents: write |
| 90 | + |
| 91 | + env: |
| 92 | + VERSION: ${{ needs.meta.outputs.latest-version }} |
| 93 | + # Either the PR base ref or the previous commit on the branch. |
| 94 | + COMMIT: ${{ github.event.pull_request.base.sha || github.event.before }} |
| 95 | + GH_REPOSITORY: ${{ github.repository }} |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Create a release for the previous implementation version |
| 99 | + env: |
| 100 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + TAG: harness-release-${{ env.VERSION }} |
| 102 | + run: > |
| 103 | + gh api |
| 104 | + --method POST |
| 105 | + -H "Accept: application/vnd.github+json" |
| 106 | + -H "X-GitHub-Api-Version: 2022-11-28" |
| 107 | + "/repos/${GH_REPOSITORY}/releases" |
| 108 | + -f "tag_name=$TAG" |
| 109 | + -f "target_commitish=$COMMIT" |
| 110 | + -f "name=$VERSION" |
| 111 | + -f "body=Automatic release for $VERSION" |
| 112 | + -F "generate_release_notes=true" |
| 113 | +
|
| 114 | + automerge: |
| 115 | + name: Automerge Dependabot PRs |
| 116 | + needs: ci |
| 117 | + runs-on: ubuntu-latest |
| 118 | + |
| 119 | + if: > |
| 120 | + !cancelled() |
| 121 | + && github.event_name == 'pull_request' |
| 122 | + && github.event.pull_request.user.login == 'dependabot[bot]' |
| 123 | + && !contains(github.event.pull_request.labels.*.name, 'github_actions') |
| 124 | +
|
| 125 | + permissions: |
| 126 | + contents: write |
| 127 | + pull-requests: write |
| 128 | + |
| 129 | + steps: |
| 130 | + - name: Automatically merge allowed PRs |
| 131 | + run: gh pr merge --auto --merge "$PR_URL" |
| 132 | + env: |
| 133 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 134 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments