diff --git a/.github/workflows/ghcr-publish.yml b/.github/workflows/ghcr-publish.yml index e2b7418b..b292c70a 100644 --- a/.github/workflows/ghcr-publish.yml +++ b/.github/workflows/ghcr-publish.yml @@ -18,6 +18,7 @@ on: env: # Use docker.io for Docker Hub if empty REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: @@ -35,20 +36,14 @@ jobs: uses: actions/checkout@v4 with: submodules: 'true' - - - name: Prepare - id: prep - run: | - DOCKER_IMAGE=${REGISTRY}/${{ github.repository_owner }}/sourcebot - VERSION=latest - if [[ $GITHUB_REF == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/v} - fi - TAGS="${DOCKER_IMAGE}:${VERSION}" - if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - TAGS="$TAGS,${DOCKER_IMAGE}:latest" - fi - echo ::set-output name=tags::${TAGS} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer @@ -79,7 +74,8 @@ jobs: push: ${{ github.event_name != 'pull_request' }} platforms: linux/amd64,linux/arm64 file: ./Dockerfile - tags: ${{ steps.prep.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} # Sign the resulting Docker image digest except on PRs. # This will only write to the public Rekor transparency log when the Docker