diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 5348a09a..cac64124 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,12 +1,21 @@ name: Docker on: - push: + pull_request: branches: - main - tags: - - "v*" - pull_request: + types: + - opened + - reopened + - synchronize + pull_request_target: + branches: + - main + types: + - closed + release: + types: + - published workflow_dispatch: concurrency: @@ -15,7 +24,6 @@ concurrency: permissions: contents: read - packages: write env: REGISTRY: ghcr.io @@ -28,6 +36,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.merge_commit_sha || github.ref }} - name: Set up Go uses: actions/setup-go@v5 @@ -72,8 +82,9 @@ jobs: working-directory: frontend run: pnpm build - image: - name: Build and publish image + image-check: + name: Build image + if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' needs: verify runs-on: ubuntu-latest steps: @@ -86,8 +97,41 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Build + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: false + cache-from: type=gha + provenance: false + sbom: false + + publish: + name: Publish image + if: >- + (github.event_name == 'pull_request_target' && + github.event.pull_request.merged == true) || + (github.event_name == 'release' && + github.event.action == 'published') + needs: verify + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.merge_commit_sha || github.ref }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to GHCR - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -99,10 +143,12 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=false tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable=${{ github.event_name == 'pull_request_target' }} + type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }} + type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'release' }} type=sha,prefix=sha- - name: Build and publish @@ -110,10 +156,10 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} cache-from: type=gha - cache-to: ${{ github.event_name != 'pull_request' && 'type=gha,mode=max' || '' }} + cache-to: type=gha,mode=max provenance: mode=max sbom: true