.github/workflows/release.yml

100 lines · 3589 bytes

  1name: Release image
  2
  3on:
  4  push:
  5    tags:
  6      - "v*"
  7  workflow_dispatch:
  8
  9env:
 10  REGISTRY: ghcr.io
 11  IMAGE_NAME: ${{ github.repository }}
 12
 13jobs:
 14  publish:
 15    runs-on: ubuntu-latest
 16    permissions:
 17      contents: read
 18      packages: write
 19      id-token: write
 20      attestations: write
 21    steps:
 22      - name: Checkout
 23        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
 24
 25      # The Dockerfile cross-compiles with Go's GOOS/GOARCH from $BUILDPLATFORM,
 26      # so no QEMU emulation is needed for the arm64 image.
 27      - name: Set up Buildx
 28        uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
 29
 30      - name: Log in to ${{ env.REGISTRY }}
 31        uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
 32        with:
 33          registry: ${{ env.REGISTRY }}
 34          username: ${{ github.actor }}
 35          password: ${{ secrets.GITHUB_TOKEN }}
 36
 37      - name: Derive tags and labels
 38        id: meta
 39        uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
 40        with:
 41          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
 42          # A semver tag v1.3.4 publishes 1.3.4, 1.3, 1 and latest.
 43          # A manual run from a branch publishes only that branch name, so
 44          # dispatching from main never moves the latest tag.
 45          tags: |
 46            type=semver,pattern={{version}}
 47            type=semver,pattern={{major}}.{{minor}}
 48            type=semver,pattern={{major}}
 49            type=ref,event=branch
 50          labels: |
 51            org.opencontainers.image.title=SkunkyArt
 52            org.opencontainers.image.description=An alternative frontend for DeviantArt that works entirely without JavaScript
 53
 54      - name: Build and push
 55        id: build
 56        uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
 57        with:
 58          context: .
 59          platforms: linux/amd64,linux/arm64
 60          push: true
 61          tags: ${{ steps.meta.outputs.tags }}
 62          labels: ${{ steps.meta.outputs.labels }}
 63          # Link the tag into the binary, so --help and /api/instance report the
 64          # same version as the image tag.
 65          build-args: |
 66            VERSION=${{ steps.meta.outputs.version }}
 67          cache-from: type=gha
 68          cache-to: type=gha,mode=max
 69
 70      - name: Attest build provenance
 71        uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4
 72        with:
 73          subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
 74          subject-digest: ${{ steps.build.outputs.digest }}
 75          push-to-registry: true
 76
 77  # Binaries for people who do not run the container. The tarballs are built
 78  # in the official Go image so no extra action is pinned, and attached to a
 79  # GitHub release of the tag with the CLI the runner already has.
 80  binaries:
 81    if: startsWith(github.ref, 'refs/tags/v')
 82    runs-on: ubuntu-latest
 83    permissions:
 84      contents: write
 85    steps:
 86      - name: Checkout
 87        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
 88        with:
 89          fetch-depth: 0
 90
 91      - name: Build tarballs
 92        run: docker run --rm -v "$PWD":/src -w /src -e VERSION="${GITHUB_REF_NAME#v}" golang:1.26 make dist
 93
 94      - name: Attach to the release
 95        env:
 96          GH_TOKEN: ${{ github.token }}
 97        run: |
 98          gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 || gh release create "$GITHUB_REF_NAME" --generate-notes
 99          gh release upload "$GITHUB_REF_NAME" dist/*.tar.gz dist/SHA256SUMS --clobber
100