|
| 1 | +name: Publish Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE_NAME: ${{ github.repository }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-and-push: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + packages: write |
| 18 | + attestations: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v6 |
| 24 | + |
| 25 | + - name: Set up Docker Buildx |
| 26 | + uses: docker/setup-buildx-action@v3 |
| 27 | + |
| 28 | + - name: Log in to GitHub Container Registry |
| 29 | + uses: docker/login-action@v3 |
| 30 | + with: |
| 31 | + registry: ${{ env.REGISTRY }} |
| 32 | + username: ${{ github.actor }} |
| 33 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + |
| 35 | + - name: Extract version from tag |
| 36 | + id: version |
| 37 | + run: | |
| 38 | + # Remove 'v' prefix from tag (v4.12.1 -> 4.12.1) |
| 39 | + VERSION=${GITHUB_REF_NAME#v} |
| 40 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 41 | + echo "Version: ${VERSION}" |
| 42 | +
|
| 43 | + - name: Extract metadata for Docker |
| 44 | + id: meta |
| 45 | + uses: docker/metadata-action@v5 |
| 46 | + with: |
| 47 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 48 | + tags: | |
| 49 | + # Full version tag (e.g. 4.12.1) |
| 50 | + type=semver,pattern={{version}} |
| 51 | + # Version tag with v prefix (e.g. v4.12.1) |
| 52 | + type=semver,pattern=v{{version}} |
| 53 | + # Major.minor tag (e.g. 4.12) |
| 54 | + type=semver,pattern={{major}}.{{minor}} |
| 55 | + # Major version tag (e.g. 4) |
| 56 | + type=semver,pattern={{major}} |
| 57 | + # Always tag as latest |
| 58 | + type=raw,value=latest |
| 59 | + # SHA tag for debugging (e.g. sha-abc1234) |
| 60 | + type=sha,prefix=sha- |
| 61 | + labels: | |
| 62 | + org.opencontainers.image.title=Commitizen |
| 63 | + org.opencontainers.image.description=Python commitizen client tool - release management for teams |
| 64 | + org.opencontainers.image.vendor=Commitizen Tools |
| 65 | +
|
| 66 | + - name: Build and push Docker image |
| 67 | + id: push |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + with: |
| 70 | + context: . |
| 71 | + push: true |
| 72 | + tags: ${{ steps.meta.outputs.tags }} |
| 73 | + labels: ${{ steps.meta.outputs.labels }} |
| 74 | + build-args: | |
| 75 | + CZ_VERSION=${{ steps.version.outputs.version }} |
| 76 | + cache-from: type=gha |
| 77 | + cache-to: type=gha,mode=max |
| 78 | + platforms: linux/amd64,linux/arm64 |
| 79 | + |
| 80 | + - name: Generate artifact attestation |
| 81 | + uses: actions/attest-build-provenance@v2 |
| 82 | + with: |
| 83 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 84 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 85 | + push-to-registry: true |
0 commit comments