-
Notifications
You must be signed in to change notification settings - Fork 119
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
Use correct commit sha for PRs? #206
Comments
No, You can check this behavior by adding the following step in your workflow to trace the context: - name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1 In your case you might want jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: "my-repo/my-image"
tags: |
type=ref,event=branch,suffix=-{{ sha }}
type=ref,event=pr,suffix=-${{ github.event.pull_request.head.sha }}
Also on PR event your don't have access to secrets so you don't push your image anyway? Maybe it's a private repo and you're using OIDC? |
Sure but the point remains the same, it's a commit that doesn't exist in the repo 😅 Right I mentioned the workaround like you mentioned works for tags, but unaware of anything for labels and it's just a tricky thing to have to account for whenever we want to reference the git sha. I was just hoping it would be possible to tweak https://github.com/docker/metadata-action/blob/master/src/main.ts#L19 to be something like |
Sorry I missed your case with labels. So yes you can override them with: jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: "my-repo/my-image"
tags: |
type=ref,event=branch,suffix=-{{ sha }}
type=ref,event=pr,suffix=-${{ github.event.pull_request.head.sha }}
labels:
org.opencontainers.image.revision=${{ github.event.pull_request.head.sha }} See https://github.com/docker/metadata-action#overwrite-labels |
Oh gotcha thanks for the link. Not sure if this is an issue though? Looks like it adds a label rather than replacing
|
Got it, that works thank you! Any thoughts on being able to set the commit sha for PRs specifically? I think it would be a great quality of life improvement. |
what @evandam said, it'd be great if we could fetch the "real" SHA of the PR vs some temporary SHA that doesn't really match to anything 😅 |
I also have this issue. I think its because the workflow in my case is triggered from the merged PR and then an auto commit and tag is performed after that. So the SHA then points to the second to the last commit which is what triggered the workflow, but the SHA does not match the tag. |
Agree @scalp42, It is not event respecting the checkout commit. I have used |
Should this issue be re-opened since the change was reverted? |
Behaviour
Hey folks, similar to #191 a bit, when running a workflow on a PR event, the
{{ sha }}
refers to the temporary merge commit to the target branch, not the commit that was pushed to trigger the event.I realize this is a pretty common situation with GitHub actions, but it ends up with Docker tags/labels that don't map back to any real commits. It would be really useful if this action automatically used
github.event.pull_request.head.sha
for PR events. I think it would have to be set for the tags{{ sha }}
value and the auto-generated labelorg.opencontainers.image.revision
.I'm aware we can work around the tags situation by using
type=raw
and passing a value based ongithub.event.pull_request.head.sha
, but it feels a bit error-prone.I'm unaware of a workaround for overriding the
org.opencontainers.image.revision
label, though.Steps to reproduce this issue
See example workflow and run on a PR
Expected behaviour
Tags with the correct sha in a PR (same with org.opencontainers.image.revision label)
Actual behaviour
Tags are created with the merge commit of the PR to the target branch (same with org.opencontainers.image.revision)
The text was updated successfully, but these errors were encountered: