metadata-action icon indicating copy to clipboard operation
metadata-action copied to clipboard

Expose pull request head ref as `{{branch}}` variable

Open fabn opened this issue 1 year ago • 1 comments

Description

When using {{branch}} variable in a pull_request event the output is '' (as documented).

It would be super useful to have it populated with github.event.pull_request.head.ref to compose tags like the following:

        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ github.repository }}
          tags: |
            type=sha,format=short,prefix={{branch}}-

At the moment I'm doing something like:

        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ github.repository }}
          tags: |
            type=sha,format=short,prefix=${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '{{branch}}' }}-

But it seems a hack to me, is there any drawback in doing that?

fabn avatar Nov 26 '24 12:11 fabn

I think that would be fine but as this could be a breaking change in some cases, would be applied to next major release.

crazy-max avatar Jul 31 '25 13:07 crazy-max