docker / docker/metadata-action

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

Open
#485 1 comment 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/enhancement
Dominant language
TypeScript
Stars
1.1k
Forks
160
Avg merge
4d 17h
Merged PRs (30d)
12

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the {{branch}} variable handling for pull_request events and compare its documented empty output with github.event.pull_request.head.ref. Verify the supplied metadata-action workflow example; done means the variable produces the pull request head ref so it can form the requested tag prefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, github-actions
Domain
ci-cd, devops
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.