-
Notifications
You must be signed in to change notification settings - Fork 653
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
[Bug] Tag checkout on GitHub Actions generates unexpected branch #2838
Comments
Thanks for the reproduction. Otherwise, this seems like a duplicate of #2301. |
FYI (for anybody else running into this): Since this only happens with the repo normalization (therefore running on a build agent) enabled, we've currently worked around this by disabling repo normalization. As we're using the msbuild tasks, the normalization can be disabled by specifying |
I did a little more digging and I think I can narrow down the cause. When normalization puts us on a I will try and put together a minimal test to prove that this is what is happening. If this is what it is, we may be able to keep normalization by having an explicit branch configuration for |
This also happens when |
When using 5.8.1 instead of 5.6.11 this problem seems to be fixed. |
@mikeminutillo can you confirm the same? |
I'm facing this bug with 5.8.1 using the MSBuild integration, but it's also reproducible with the command line tool. What I noticed is, that it only happens if I use Sample GitHub CI: |
@ThomasPiskol, thanks for the reproduction! You write that you're able to also reproduce with the command line. Can you please add that or change your current reproduction from the MSBuild task to the command line? That way it's going to be much easier to test locally. |
I tested the following command in a clone of this repository just now and was unable to reproduce the problem: rm -rf .git/gitversion_cache
GIT_BRANCH=main GITHUB_ACTIONS=true gitversion -verbosity verbose -l gitversion.log
cat gitversion.log If someone are able to concoct a series of commands that can reproduce the problem, I'm more than willing to execute those commands locally and debug what's going on. But until a reliable reproduction exists, I can't be of much assistance, I'm afraid. 🤷🏼♂️ |
The crucial environment variable is rm -rf .git/gitversion_cache
GITHUB_REF=refs/tags/1.2.1 GIT_BRANCH=main GITHUB_ACTIONS=true gitversion -verbosity verbose -l gitversion.log
{
"Major": 0,
"Minor": 7,
"Patch": 1,
"PreReleaseTag": "tags-1-2-1.1",
"PreReleaseTagWithDash": "-tags-1-2-1.1",
"PreReleaseLabel": "tags-1-2-1",
"PreReleaseLabelWithDash": "-tags-1-2-1",
"PreReleaseNumber": 1,
"WeightedPreReleaseNumber": 1,
"BuildMetaData": null,
"BuildMetaDataPadded": "",
"FullBuildMetaData": "Branch.tags-1.2.1.Sha.e5973747dacb5fb6aa85c8d98d5879f781f0e3a2",
"MajorMinorPatch": "0.7.1",
"SemVer": "0.7.1-tags-1-2-1.1",
"LegacySemVer": "0.7.1-tags-1-2-1-1",
"LegacySemVerPadded": "0.7.1-tags-1-2-1-0001",
"AssemblySemVer": "0.7.1.0",
"AssemblySemFileVer": "0.7.1.0",
"FullSemVer": "0.7.1-tags-1-2-1.1",
"InformationalVersion": "0.7.1-tags-1-2-1.1+Branch.tags-1.2.1.Sha.e5973747dacb5fb6aa85c8d98d5879f781f0e3a2",
"BranchName": "tags/1.2.1",
"EscapedBranchName": "tags-1-2-1",
"Sha": "e5973747dacb5fb6aa85c8d98d5879f781f0e3a2",
"ShortSha": "e597374",
"NuGetVersionV2": "0.7.1-tags-1-2-1-0001",
"NuGetVersion": "0.7.1-tags-1-2-1-0001",
"NuGetPreReleaseTagV2": "tags-1-2-1-0001",
"NuGetPreReleaseTag": "tags-1-2-1-0001",
"VersionSourceSha": "4525bf0363e9ea47ded9bbc9ba42d8163262c25b",
"CommitsSinceVersionSource": 1,
"CommitsSinceVersionSourcePadded": "0001",
"UncommittedChanges": 0,
"CommitDate": "2022-01-15"
} I'm not sure what the proper solution in this case is. According to the GitHub documentation, the
What came to my mind is to change the GitHubActions class. Currently the it's always returning the value of the
If public override string? GetCurrentBranch(bool usingDynamicRepos)
{
string githubRef = Environment.GetEnvironmentVariable("GITHUB_REF");
if(githubRef != null && githubRef.StartsWith("refs/heads/"))
{
return githubRef;
}
return null;
} Because in this case
@asbjornu What do you think? If this the correct way, I can prepare a PR with this change and some additional test to ensure the correct behaviour. |
We went through some similar trial and error when trying to grab information from GitHub Actions for the Cake.Recipe project. We ended up using the following: It isn't perfect, but it fits that needs that we had. There are times when we had to fallback to using git directly to grab the necessary information, since it simply wasn't available in the environment variables presented by GitHub Actions. |
That seems to be exactly what's going on, @ThomasPiskol. I think your proposed fix is going to be sufficient too. Now, we just need to figure out how to reproduce this in a test so we're sure this bug never pops up again in the future. |
🎉 This issue has been resolved in version 5.10.0 🎉 Your GitReleaseManager bot 📦🚀 |
This appears to have been broken sometime between 5.10.0 and 5.12.0. I've had to lock in GitVersion to 5.10.0 to keep this fix.
|
I can confirm that this problem happens again with 5.12. After downgrading to 5.10, it resolved itself. |
- Need to use 5.10.0 per GitTools/GitVersion#2838 - 6.x will remove NuGetSemVer2
- Need to use 5.10.0 per GitTools/GitVersion#2838 - 6.x will remove NuGetSemVer2
- Need to use 5.10.0 per GitTools/GitVersion#2838 - 6.x will remove NuGetSemVer2
Can it be, that in 6.0.x this is a thing again? Reproduce locally:
|
We have a GitHub Action that triggers on tag push. When it runs, GitVersion generates a version like this:
1.3.0-tags-1-2-1.1+6
. The 1.2.1 tag is defined on the tip of therelease-1.2
branch.When I run GitVersion locally, it generates the expected version
1.2.1
. When I configure my local environment to replicate the GitHub Actions environment, I do get the same incorrect version number.Expected Behavior
When checking out a tag in GitHub actions that relates to a version number, that version number should be generated.
Actual Behavior
Normalization and checking out the
GITHUB_REF
as a branch is causing an unexpected branch to be created and checked out and that is giving us an incorrect version number.Possible Fix
The
GITHUB_REF
environment variable is set to the tag ref (i.e.refs/tags/1.2.1
) but this gets treated like a branch name. Ultimately this ref gets mangled into a canonical name like thisrefs/heads/tags/1.2.1
, and turned into a branch namedtags/1.2.1
. This branch name is used in the SemVer version.Steps to Reproduce
NOTE: The repo experiencing this issue is this one.
This is the cmd script that I have used to reproduce this locally
Context
Your Environment
The text was updated successfully, but these errors were encountered: