Skip to content

Fix checkout of annotated tag loosing annotation#1506

Open
Rycieos wants to merge 1 commit intoactions:mainfrom
Rycieos:bugfix/annotated-tag
Open

Fix checkout of annotated tag loosing annotation#1506
Rycieos wants to merge 1 commit intoactions:mainfrom
Rycieos:bugfix/annotated-tag

Conversation

@Rycieos
Copy link

@Rycieos Rycieos commented Oct 6, 2023

Currently, a check is done after fetch to ensure that the repo state has not changed since the workflow was triggered. This check will reset the checkout to the commit that triggered the workflow, even if the branch or tag has moved since.

The issue is that the check currently sees what "object" the ref points to. For an annotated tag, that is the annotation, not the commit. This means the check always fails for annotated tags, and they are reset to the commit, losing the annotation. Losing the annotation can be fatal, as git describe will only match annotated tags.

The fix is simple: check if the tag points at the right commit, ignoring any other type of object. This is done with the <rev>^{commit} syntax.

From the git-rev-parse docs:

<rev>^{}, e.g. v0.99.8^{commit}
A suffix ^ followed by an object type name enclosed in brace pair means dereference the object at <rev> recursively until an object of type <type> is found or the object cannot be dereferenced anymore (in which case, barf). For example, if <rev> is a commit-ish, <rev>^{commit} describes the corresponding commit object. Similarly, if <rev> is a tree-ish, <rev>^{tree} describes the corresponding tree object. <rev>^0 is a short-hand for <rev>^{commit}.

If the check still fails, we will still reset the tag to the commit, losing the annotation. However, there is no way to truly recover in this situtation, as GitHub does not capture the annotation on workflow start, and since the history has changed, we can not trust the new tag to contain the same data as it did before.

Fixes #290
Closes #697

(I marked this as closing #697 since this fixes the same issue. This fix is better (in my opinion), as this is less of a deviation from the current functionality.)

Currently, a check is done after fetch to ensure that the repo state has
not changed since the workflow was triggered. This check will reset the
checkout to the commit that triggered the workflow, even if the branch
or tag has moved since.

The issue is that the check currently sees what "object" the ref points
to. For an annotated tag, that is the annotation, not the commit. This
means the check always fails for annotated tags, and they are reset to
the commit, losing the annotation. Losing the annotation can be fatal,
as `git describe` will only match annotated tags.

The fix is simple: check if the tag points at the right commit, ignoring
any other type of object. This is done with the <rev>^{commit} syntax.

From the git-rev-parse docs:
> <rev>^{<type>}, e.g. v0.99.8^{commit}
>  A suffix ^ followed by an object type name enclosed in brace pair
>  means dereference the object at <rev> recursively until an object of
>  type <type> is found or the object cannot be dereferenced anymore (in
>  which case, barf). For example, if <rev> is a commit-ish,
>  <rev>^{commit} describes the corresponding commit object. Similarly,
>  if <rev> is a tree-ish, <rev>^{tree} describes the corresponding tree
>  object.  <rev>^0 is a short-hand for <rev>^{commit}.

If the check still fails, we will still reset the tag to the commit,
losing the annotation. However, there is no way to truly recover in this
situtation, as GitHub does not capture the annotation on workflow start,
and since the history has changed, we can not trust the new tag to
contain the same data as it did before.

Fixes actions#290
Closes actions#697
@chrisjenx
Copy link

Not sure on the status of this, but got caught out by this today.

rzr added a commit to rzr/checkout that referenced this pull request Feb 13, 2025
Until a proper fix is released,
I believe this will be helpful to to share this trick to community.

Bug: actions#290
Relate-to: actions#1506
Relate-to: actions#649
Origin: https://github.com/actions/checkout/pulls?q=author%3Arzr
Signed-off-by: Philippe Coval <[email protected]>
rzr added a commit to rzr/checkout that referenced this pull request Feb 13, 2025
Until a proper fix is released,
I believe this will be helpful to to share this trick to community.

Bug: actions#290
Relate-to: actions#1506
Relate-to: actions#649
Origin: actions#2081
Signed-off-by: Philippe Coval <[email protected]>
rzr added a commit to rzr/checkout that referenced this pull request Feb 13, 2025
Until a proper fix is released,
I believe this will be helpful to share this trick to community.

Bug: actions#290
Relate-to: actions#1506
Relate-to: actions#649
Origin: actions#2081
Signed-off-by: Philippe Coval <[email protected]>
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.

Preserve tag annotations

2 participants

Comments