name: Build and publish Docker image on: push: branches: [dev] tags: - 'v*' pull_request: paths: - 'Dockerfile' - '.github/workflows/docker-publish.yml' workflow_dispatch: inputs: git_tag: description: 'Git tag to build and publish (e.g. v1.2.3). Leave empty to build current HEAD as a dev image.' required: false type: string env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write attestations: write artifact-metadata: write id-token: write steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Log in to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: ./.github/actions/resolve-release-meta id: release_meta with: input-tag: ${{ inputs.git_tag }} - name: Checkout release target uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false ref: ${{ steps.release_meta.outputs.ref }} - name: Extract metadata id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} flavor: | latest=false tags: | # dev branch or manual dispatch without a tag: short commit SHA + dev type=sha,prefix=,format=short,enable=${{ steps.release_meta.outputs.version != '' && steps.release_meta.outputs.nightly == 'true' }} type=raw,value=dev,enable=${{ steps.release_meta.outputs.version != '' && steps.release_meta.outputs.nightly == 'true' }} # git tags (push or manual dispatch with a tag): semver breakdown + latest type=raw,value=latest,enable=${{ steps.release_meta.outputs.version != '' }} type=semver,pattern={{version}},value=${{ steps.release_meta.outputs.version }},enable=${{ steps.release_meta.outputs.version != '' }} type=semver,pattern={{major}}.{{minor}},value=${{ steps.release_meta.outputs.version }},enable=${{ steps.release_meta.outputs.version != '' }} type=semver,pattern={{major}},value=${{ steps.release_meta.outputs.version }},enable=${{ steps.release_meta.outputs.version != '' && !startsWith(steps.release_meta.outputs.version, 'v0.') }} - name: Compute short SHA id: vars run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Setup app uses: ./.github/actions/setup - name: Build site env: VITE_BUILD_HASH: ${{ steps.vars.outputs.short_sha }} VITE_APP_VERSION: ${{ steps.release_meta.outputs.version }} SABLE_BUILD_FLAVOR: ${{ steps.release_meta.outputs.build_flavor }} run: | NODE_OPTIONS=--max_old_space_size=4096 pnpm run build - name: Set up QEMU uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 - name: Build and push Docker image id: push uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 with: context: . push: ${{ github.event_name != 'pull_request' }} platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-contexts: | site-dist=./dist - name: Generate artifact attestation if: github.event_name != 'pull_request' uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1 with: subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} subject-digest: ${{ steps.push.outputs.digest }} push-to-registry: true