Skip to content

Expose pull request head ref as {{branch}} variable #485

Open
@fabn

Description

@fabn

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions