question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Use correct commit sha for PRs?

See original GitHub issue

Behaviour

Hey folks, similar to https://github.com/docker/metadata-action/issues/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 label org.opencontainers.image.revision.

Iā€™m aware we can work around the tags situation by using type=raw and passing a value based on github.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)

name: AWS

on:
  push:
    branches: ["main"]
    tags: ["v*"]
  pull_request:
    branches: ["*"]

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=-{{ sha }}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
LMS007commented, May 23, 2022

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.

1reaction
scalp42commented, May 12, 2022

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 šŸ˜…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Pull request details using commit sha #22481 - GitHub
In general commits exist independent of PRs, while PRs contain a set of commits to merge (which may change if the PR is...
Read more >
Get commit SHA in Github actions - Stack Overflow
sha stands for the actual merge commit. Github Variables. Tip: you can print the GitHub variables using the following step: - name:Ā ...
Read more >
How to amend a commit on a GitHub Pull Request
Interactively rebase. Close this PR, commit again on a new branch, open another PR. Wait for someone else to do this for you,...
Read more >
Commits, PRs & reviews
Commit message is first and foremost about the content. You are communicating with fellow developers: Be clear and brief - it's a summary....
Read more >
Updating PRs during review - CockroachDB - Confluence
The command git commit --fixup Ƃ Ƃ takes the SHA of another commit on the command line, which you intend to amend/modify. Then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found