-
Notifications
You must be signed in to change notification settings - Fork 34
context: use actual git ref instead of commit sha #677
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Shouldn't this be fixed on the BuildKit side? |
if (!ref) { | ||
if (!sha) { | ||
throw new Error('Git reference or commit SHA is required'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to actions/checkout behavior: https://github.com/actions/checkout/blob/85e6279cec87321a52edac9c87bce653a07cf6c2/src/ref-helper.ts#L22-L24
I think the logic in BuildKit makes sense. GitHub does support fetching tags with commit sha: https://github.com/actions/checkout/blob/85e6279cec87321a52edac9c87bce653a07cf6c2/src/ref-helper.ts#L79-L128 With the example in PR description it would be And BuildKit could not use this kind of ref anyway with the
I think moby/buildkit#5903 would help for such case. |
We need to check how this works with Ultimately moby/buildkit#5903 is a better fix and we can also see if we can just keep the tags in the git source. |
After discussing offline with @tonistiigi, tags are fetched with commit sha as ref: https://github.com/moby/buildkit/blob/f2ce016376e5e61ff87d95cd20ccdf108fa77230/source/git/source.go#L482-L489 The issue we have in https://github.com/docker/buildx/actions/runs/14474897650/job/40598541434#step:7:495 is because we first parse the definition using the git context that effectively fetch the tags: https://github.com/docker/buildx/actions/runs/14474897650/job/40598541434#step:7:213 But as the source is now cached with only commit as ref, other subsequent checkout don't retain tags as there is no remote lookup: https://github.com/docker/buildx/actions/runs/14474897650/job/40598541434#step:7:499 |
Currently the git reference used with git context for push events (branch or tag) is always set to commit sha. This is problematic as fetching by commit sha does not retrieve tags.
For example in https://github.com/docker/buildx/actions/runs/14474897650/job/40598541434#step:7:495
This workflow runs on push event with
refs/tags/v0.23.0
git reference but hereversion.Version
is set to28c90ea
because BuildKit fetches by commit sha and no tags are fetched.It leads to inconsistency with
actions/checkout
action that fetches by git reference with tags.With this change we are setting the actual git reference and fallback to commit sha if GitHub context does not have a ref (should never happen).
Before:
After:
In the future with CSV support for git context moby/buildkit#5903, we could set both the git reference and commit sha.