|
| 1 | +name: Publish GitHub Container Registry |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: ['ghcr'] |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE_NAME: ${{ github.repository }} |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-and-push-image: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + packages: write |
| 20 | + attestations: write |
| 21 | + id-token: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 |
| 26 | + - name: Log in to the Container registry |
| 27 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 28 | + with: |
| 29 | + registry: ${{ env.REGISTRY }} |
| 30 | + username: ${{ github.actor }} |
| 31 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Extract metadata (tags, labels) for Docker |
| 34 | + id: meta |
| 35 | + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 |
| 36 | + with: |
| 37 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 38 | + # pushes to the default branch get labeled latest, otherwise use tag name |
| 39 | + tags: | |
| 40 | + type=raw,value=latest,enable={{is_default_branch}} |
| 41 | + type=ref,event=tag |
| 42 | +
|
| 43 | + - name: Build and push Docker image |
| 44 | + id: push |
| 45 | + uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 |
| 46 | + with: |
| 47 | + context: . |
| 48 | + push: true |
| 49 | + tags: ${{ steps.meta.outputs.tags }} |
| 50 | + labels: ${{ steps.meta.outputs.labels }} |
| 51 | + |
| 52 | + - name: Generate artifact attestation |
| 53 | + uses: actions/attest-build-provenance@1c608d11d69870c2092266b3f9a6f3abbf17002c # v1.4.3 |
| 54 | + # only publish attestation for our release builds |
| 55 | + if: startsWith(github.ref, 'refs/tags/v') |
| 56 | + with: |
| 57 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 58 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 59 | + push-to-registry: true |
0 commit comments