Skip to content
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

[FC-41962] jenkins: always resolve tags to rev of the commit that got tagged #201

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ma27
Copy link
Member

@Ma27 Ma27 commented Nov 21, 2024

FC-41962
Closes #200

Previously, we always resolved tags to the commit rev. However if this failed, there was a fallback to the rev of the tag (the output of git ls-remote without the ^{} modifier).

This is a problem in a deployment where we rely on the rev being the commit rev since that's part of the S3 url where the frontend assets are stored. The reason for the fallback that lead to such a deployment error was a timing issue where the first ls-remote failed like this

ssh: Could not resolve hostname gitlab.customer.com: Try again
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

and the second one (resolving to the tag's rev) succeeded.

We now call ls-remote without the ^{} modifier and check if the refspec got resolved to a tag (i.e. refs/tags/...). If that's the case, a second ls-remote is issued with the ^{} modifier to get the rev of the commit that got tagged. If this second call fails, we fail hard to make sure we don't get incorrect results silently.

FC-41962
Closes #200

Previously, we always resolved tags to the commit rev. However if this
failed, there was a fallback to the rev of the tag (the output of `git
ls-remote` without the `^{}` modifier).

This is a problem in a deployment where we rely on the rev being the
commit rev since that's part of the S3 url where the frontend assets are
stored. The reason for the fallback that lead to such a deployment
error was a timing issue where the first `ls-remote` failed like this

    ssh: Could not resolve hostname gitlab.customer.com: Try again
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights
    and the repository exists.

and the second one (resolving to the tag's rev) succeeded.

We now call `ls-remote` without the `^{}` modifier and check if the
refspec got resolved to a tag (i.e. `refs/tags/...`). If that's the
case, a second `ls-remote` is issued with the `^{}` modifier to
get the rev of the commit that got tagged. If this second call fails,
we fail hard to make sure we don't get incorrect results silently.
if full_refspec.startswith("refs/tags/"):
ls_remote_tag = git_ls_remote(url, f"{version}^{{}}")
if ls_remote_tag:
rev = ls_remote_tag[0]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags don't necessarily have their own revision as I've just learned.
So this code would break with such revs.

@Ma27 Ma27 marked this pull request as draft December 2, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git ls-remote Retry can have undesirable behavior on bad timing
2 participants