|
| 1 | +# Scrye — Docker Hub publishing. |
| 2 | +# |
| 3 | +# Two independent publishing paths (CLAUDE.md locked decision §6): |
| 4 | +# |
| 5 | +# 1. Tagged main releases — a push of a semver tag (v*.*.*) builds the |
| 6 | +# multi-arch image and pushes it as <dockerhub-user>/scrye:<version> (the tag |
| 7 | +# without its leading "v") and <dockerhub-user>/scrye:latest. The release job |
| 8 | +# refuses to run unless the tagged commit is reachable from main, so only |
| 9 | +# real releases cut from main ever reach :<version>/:latest. |
| 10 | +# |
| 11 | +# 2. dev continuous build — when a pull request is MERGED into dev, the |
| 12 | +# multi-arch image is built and pushed as the single moving tag |
| 13 | +# <dockerhub-user>/scrye:dev, always overwritten. This is NOT a versioned or |
| 14 | +# stable tag; it just mirrors the state of dev after each merged PR. It does |
| 15 | +# NOT fire on other pushes to the dev ref (e.g. conflict-resolution commits |
| 16 | +# on an open, unmerged PR) or on PRs that are closed without merging. |
| 17 | +# |
| 18 | +# The multi-arch build itself is defined once in .github/actions/build-image and |
| 19 | +# reused by both jobs (and by ci.yml's build-only check). Credentials come from |
| 20 | +# the DOCKERHUB_USERNAME / DOCKERHUB_TOKEN repository secrets. |
| 21 | +name: Publish |
| 22 | + |
| 23 | +on: |
| 24 | + push: |
| 25 | + tags: |
| 26 | + - "v*.*.*" |
| 27 | + # The :dev tag publishes only when a pull request is actually merged into dev, |
| 28 | + # never on a bare push to the dev ref. types:[closed] fires on both merge and |
| 29 | + # close-without-merge; the merged==true gate lives on the dev job below. |
| 30 | + pull_request: |
| 31 | + types: [closed] |
| 32 | + branches: |
| 33 | + - dev |
| 34 | + |
| 35 | +# Least privilege: reading the repo is all either job needs. Registry auth is |
| 36 | +# handled with the Docker Hub secrets, not the GITHUB_TOKEN. |
| 37 | +permissions: |
| 38 | + contents: read |
| 39 | + |
| 40 | +# Serialize builds per ref. Distinct release tags have distinct refs so they |
| 41 | +# never cancel each other; each merged-PR :dev build runs under its own PR ref. |
| 42 | +concurrency: |
| 43 | + group: publish-${{ github.ref }} |
| 44 | + cancel-in-progress: true |
| 45 | + |
| 46 | +jobs: |
| 47 | + release: |
| 48 | + name: Tagged release → Docker Hub (:<version> + :latest) |
| 49 | + if: startsWith(github.ref, 'refs/tags/v') |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - name: Checkout (full history to verify the tag is on main) |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + |
| 57 | + # A tag can be pushed from any commit; a release must come from main. |
| 58 | + # Fetch main and confirm the tagged commit is an ancestor of its tip |
| 59 | + # before building anything. |
| 60 | + - name: Verify the tagged commit is on main |
| 61 | + run: | |
| 62 | + git fetch --no-tags origin main |
| 63 | + if ! git merge-base --is-ancestor "$GITHUB_SHA" FETCH_HEAD; then |
| 64 | + echo "::error::Tag ${GITHUB_REF_NAME} points at a commit that is not on main; refusing to publish a release." |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + # <dockerhub-user>/scrye:<version> uses the tag without its leading "v" |
| 69 | + # (v1.4.0 -> 1.4.0). |
| 70 | + - name: Derive the version from the tag |
| 71 | + id: version |
| 72 | + run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 73 | + |
| 74 | + - name: Log in to Docker Hub |
| 75 | + uses: docker/login-action@v3 |
| 76 | + with: |
| 77 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 78 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 79 | + |
| 80 | + - name: Build and push (:<version> + :latest) |
| 81 | + uses: ./.github/actions/build-image |
| 82 | + with: |
| 83 | + push: "true" |
| 84 | + tags: | |
| 85 | + <dockerhub-user>/scrye:${{ steps.version.outputs.version }} |
| 86 | + <dockerhub-user>/scrye:latest |
| 87 | +
|
| 88 | + dev: |
| 89 | + name: dev branch → Docker Hub (:dev continuous build) |
| 90 | + # Only when a PR is genuinely merged into dev. types:[closed] also fires when |
| 91 | + # a PR is closed without merging, so gate on merged==true; base.ref is pinned |
| 92 | + # to dev as belt-and-suspenders alongside the on: pull_request branch filter. |
| 93 | + if: >- |
| 94 | + github.event_name == 'pull_request' && |
| 95 | + github.event.pull_request.merged == true && |
| 96 | + github.event.pull_request.base.ref == 'dev' |
| 97 | + runs-on: ubuntu-latest |
| 98 | + steps: |
| 99 | + # Build the merge commit that actually landed on dev (the PR result), not |
| 100 | + # the ephemeral refs/pull/N/merge preview ref. |
| 101 | + - name: Checkout the merged commit on dev |
| 102 | + uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + ref: ${{ github.event.pull_request.merge_commit_sha }} |
| 105 | + |
| 106 | + - name: Log in to Docker Hub |
| 107 | + uses: docker/login-action@v3 |
| 108 | + with: |
| 109 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 110 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 111 | + |
| 112 | + - name: Build and push (:dev) |
| 113 | + uses: ./.github/actions/build-image |
| 114 | + with: |
| 115 | + push: "true" |
| 116 | + tags: <dockerhub-user>/scrye:dev |
0 commit comments