|
| 1 | +--- |
| 2 | +name: image |
| 3 | + |
| 4 | +# Build (and on the right refs, publish) the hypercache-server |
| 5 | +# container image. Three trigger shapes: |
| 6 | +# * pull_request — build only, never push (catches Dockerfile |
| 7 | +# regressions without polluting the registry). |
| 8 | +# * push to main — build + push as `:main` and `:sha-<short>` |
| 9 | +# so consumers can pin to either. |
| 10 | +# * tag push (v*.*.*) — build + push semver-flavored tags |
| 11 | +# (`:v1.2.3`, `:1.2.3`, `:1.2`, `:1`, `:latest`) for stable |
| 12 | +# pinning. |
| 13 | +# Multi-arch linux/amd64 + linux/arm64 via buildx + qemu so |
| 14 | +# operators on Apple Silicon (or k8s nodes on Graviton) get a |
| 15 | +# native binary without emulation. |
| 16 | + |
| 17 | +on: |
| 18 | + pull_request: |
| 19 | + push: |
| 20 | + branches: [ main ] |
| 21 | + tags: [ "v*.*.*" ] |
| 22 | + workflow_dispatch: |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + |
| 28 | +env: |
| 29 | + REGISTRY: ghcr.io |
| 30 | + IMAGE_NAME: ${{ github.repository }}/hypercache-server |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + name: build${{ github.event_name == 'pull_request' && ' (no push)' || ' + push' |
| 35 | + }} |
| 36 | + runs-on: ubuntu-latest |
| 37 | + timeout-minutes: 20 |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v6 |
| 41 | + |
| 42 | + - name: Set up QEMU |
| 43 | + uses: docker/setup-qemu-action@v4 |
| 44 | + |
| 45 | + - name: Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@v4 |
| 47 | + |
| 48 | + # Login is gated on non-PR events. Forks running PR workflows |
| 49 | + # don't have access to GITHUB_TOKEN with packages:write, and |
| 50 | + # we never push from a PR anyway — so skipping the login step |
| 51 | + # avoids an avoidable failure on those events. |
| 52 | + - name: Log in to GHCR |
| 53 | + if: github.event_name != 'pull_request' |
| 54 | + uses: docker/login-action@v4.1.0 |
| 55 | + with: |
| 56 | + registry: ${{ env.REGISTRY }} |
| 57 | + username: ${{ github.actor }} |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + |
| 60 | + # docker/metadata-action computes the tag set + OCI labels |
| 61 | + # from the triggering ref. The semver patterns only match |
| 62 | + # when the ref is a `v*.*.*` tag; on branch/PR pushes they |
| 63 | + # produce no tags and the type=ref/type=sha entries take over. |
| 64 | + # `:latest` is restricted to semver tag pushes — production |
| 65 | + # operators pinning to `:latest` get the highest stable |
| 66 | + # release, never an in-flight main commit. The `latest=false` |
| 67 | + # flavor disables the metadata-action default behavior that |
| 68 | + # would otherwise tag `:latest` on every default-branch push. |
| 69 | + - name: Compute tags and labels |
| 70 | + id: meta |
| 71 | + uses: docker/metadata-action@v6 |
| 72 | + with: |
| 73 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 74 | + tags: | |
| 75 | + type=ref,event=branch |
| 76 | + type=ref,event=pr |
| 77 | + type=sha,format=short |
| 78 | + type=semver,pattern={{version}} |
| 79 | + type=semver,pattern={{major}}.{{minor}} |
| 80 | + type=semver,pattern={{major}} |
| 81 | + type=raw,value=latest,enable=${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') }} |
| 82 | + flavor: | |
| 83 | + latest=false |
| 84 | +
|
| 85 | + - name: Build${{ github.event_name == 'pull_request' && '' || ' + push' }} |
| 86 | + uses: docker/build-push-action@v7.1.0 |
| 87 | + with: |
| 88 | + context: . |
| 89 | + file: cmd/hypercache-server/Dockerfile |
| 90 | + platforms: linux/amd64,linux/arm64 |
| 91 | + push: ${{ github.event_name != 'pull_request' }} |
| 92 | + tags: ${{ steps.meta.outputs.tags }} |
| 93 | + labels: ${{ steps.meta.outputs.labels }} |
| 94 | + # GHA cache speeds re-builds when only Go source changed |
| 95 | + # (the dependency-download layer stays warm). |
| 96 | + cache-from: type=gha |
| 97 | + cache-to: type=gha,mode=max |
0 commit comments