docker / metadata-action

GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
https://github.com/marketplace/actions/docker-metadata-action
Apache License 2.0
911 stars 118 forks source link

Disable `main` tag when `latest` is enabled #347

Closed rob93c closed 1 year ago

rob93c commented 1 year ago

Description

While working on my Docker workflow, I noticed that when merging changes to my main (the default branch in my case) 2 tags are created: latest and main.

How can I prevent main's creation?

This is my configuration:

      - name: Extract metadata
        id: metadata
        uses: docker/metadata-action@v5
        with:
          images: |
            rob93c/stickerify
          tags: |
            type=raw,value=latest,enable={{is_default_branch}}
            type=ref,event=branch
            type=ref,event=pr
polarathene commented 1 year ago

Unfortunately it seems handlebars doesn't provide a ! operator, so you'd need the action to also provide {{is_not_default_branch}}, but for now you can hard-code the branch:

Try type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}? That should opt out.

rob93c commented 1 year ago

Hi @polarathene and thank you for your help, I confirm your suggestion works as intended so to me the issue can be closed