-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{{branch}} is not set on pull request events #191
Comments
I can reproduce the issue, we ended up just tagging by hand but it feels like we're missing something 👀 |
I have updated the documentation in #192 to have a better understanding to what each global expression stands for: https://github.com/crazy-max/docker-metadata-action/tree/default-branch#global-expressions Here To make this works for push and pull_request events, I think you can just add both for the same tag entry as they can't be both set anyway: - name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: my/repo
tags: |
type=raw,value={{sha}}-amd64
type=raw,value={{branch}}{{base_ref}}-amd64
type=raw,value={{branch}}{{base_ref}}-{{sha}}-amd64 |
Hey @crazy-max I think this isn't quite what we're looking for though. If we have a PR on a branch named I want to avoid tagging by hand though to take advantage of sanitizing the branch name to a valid image tag. |
In this case you need the head ref: - name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: my/repo
tags: |
type=raw,value={{sha}}-amd64
type=raw,value={{branch}}-amd64
type=raw,value={{branch}}-{{sha}}-amd64
type=raw,value={{github.event.pull_request.head.ref}}-amd64,enable=${{ github.event_name == 'pull_request' }}
type=raw,value={{github.event.pull_request.head.ref}}-{{sha}}-amd64,enable=${{ github.event_name == 'pull_request' }} |
I see, so would you still recommend the approach you mentioned earlier to support PRs and pushes to branches? tags: |
type=raw,value={{branch}}{{github.event.pull_request.head.ref}} Also just want to confirm will this still sanitize the branch name, replacing Thanks! |
Yes I think a single entry should work. Let me know.
Unfortunately no, we would need another global expression like But I think this one is still valid and we could add this global exp. |
Gotcha thanks @crazy-max. If it's not sanitizing then I think it isn't a route we can go with and will have to do some custom work around it similar to @scalp42 most likely. It would be great to see this as a global ref that we could easily grab in our pipelines since it seems like a common enough pattern. |
@evandam I know this isn't a solution for your problem, but if I were you, I would probably prefer to tag PRs with the pr number instead of the branch name. Like I find this more descriptive than the branch name itself, as often we just give it any names. Oftenly we even reuse the same branch name as they get deleted after PR merge anyway. |
I agree with @felipecrs, PR number is more reliable. |
Closing this one as pr number is a more reliable pattern. |
Troubleshooting
Before submitting a bug report please read the Troubleshooting doc.
Behaviour
Using
{{branch}}
as outlined in https://github.com/docker/metadata-action#global-expressions does not work when pushing commits to a branch with a PR open.Steps to reproduce this issue
Expected behaviour
Docker tags should be outputted as follows assuming a branch
foo
and sha12345
Actual behaviour
{{branch}}
is empty so the tags are as follows:Configuration
Logs
metadata step of logs with some parts redacted
The text was updated successfully, but these errors were encountered: