1+ name : Publish Docker image on GitHub Container Registry
2+ # https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions
3+
4+ on :
5+ workflow_dispatch :
6+ push :
7+ tags :
8+ - " v*.*.*"
9+
10+ env :
11+ REGISTRY : ghcr.io
12+ IMAGE_NAME : ${{ github.repository }}
13+
14+ jobs :
15+ build-and-publish-image :
16+ runs-on : ubuntu-24.04
17+
18+ # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
19+ permissions :
20+ contents : read
21+ packages : write
22+ attestations : write
23+ id-token : write
24+
25+ steps :
26+ - name : Checkout repository
27+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28+ with :
29+ persist-credentials : false # do not keep the token around
30+
31+ # Uses the `docker/login-action` action to log in to the Container registry using
32+ # the account and password that will publish the packages.
33+ - name : Log in to the Container registry
34+ uses : docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
35+ with :
36+ registry : ${{ env.REGISTRY }}
37+ username : ${{ github.actor }}
38+ password : ${{ secrets.GITHUB_TOKEN }}
39+
40+ - name : Extract metadata (tags, labels) for image
41+ id : meta
42+ uses : docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
43+ with :
44+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+ tags : |
46+ type=sha,event=workflow_dispatch,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
47+ type=semver,pattern={{version}}
48+ labels : |
49+ org.opencontainers.image.title=HealthyCode
50+ org.opencontainers.image.description=Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab
51+ org.opencontainers.image.licenses=GPL-3.0-or-later
52+ annotations : |
53+ org.opencontainers.image.title=HealthyCode
54+ org.opencontainers.image.description=Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab
55+ org.opencontainers.image.licenses=GPL-3.0-or-later
56+
57+ - name : Set up Docker Buildx
58+ uses : docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
59+
60+ - name : Build and push Docker image
61+ id : push
62+ uses : docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
63+ with :
64+ context : .
65+ push : true
66+ tags : |
67+ ${{ steps.meta.outputs.tags }}
68+ labels : ${{ steps.meta.outputs.labels }}
69+ annotations : ${{ steps.meta.outputs.annotations }}
70+
71+ - name : Generate artifact attestation for Docker image
72+ uses : actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
73+ with :
74+ subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
75+ subject-digest : ${{ steps.push.outputs.digest }}
76+ push-to-registry : true
0 commit comments