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

Add tests for GitLab CI to ignore branch name for tags #4402

Merged
merged 2 commits into from
Feb 1, 2025

Conversation

Bi0T1N
Copy link
Contributor

@Bi0T1N Bi0T1N commented Jan 31, 2025

Description

This PR adds the missing tests for PR #4187. That PR needs to be merged first since without the changes you'll see two errors:

NUnit Adapter 4.6.0.0: Test execution complete
  GitVersion.BuildAgents.Tests test net9.0 failed with 2 error(s) (1.0s)
    /workspaces/GitVersion/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs(74): error TESTERROR: 
      GetCurrentBranchShouldHandleTags("v1.0.0","v1.0.0",null) (31ms): Error Message: Shouldly.ShouldAssertException : result
          should be null but was
      "v1.0.0"
      Stack Trace:
         at GitVersion.Agents.Tests.GitLabCiTests.GetCurrentBranchShouldHandleTags(String branchName, String commitTag, String expectedResult) in /workspaces/GitVersion/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs:line 74
         at InvokeStub_GitLabCiTests.GetCurrentBranchShouldHandleTags(Object, Span`1)
         at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    /workspaces/GitVersion/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs(74): error TESTERROR: 
      GetCurrentBranchShouldHandleTags("v1.2.1","v1.2.1",null) (1ms): Error Message: Shouldly.ShouldAssertException : result
          should be null but was
      "v1.2.1"
      Stack Trace:
         at GitVersion.Agents.Tests.GitLabCiTests.GetCurrentBranchShouldHandleTags(String branchName, String commitTag, String expectedResult) in /workspaces/GitVersion/src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs:line 74
         at InvokeStub_GitLabCiTests.GetCurrentBranchShouldHandleTags(Object, Span`1)
         at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Test summary: total: 90, failed: 2, succeeded: 88, skipped: 0, duration: 1.0s
Build failed with 2 error(s) in 3.2s

Related Issue

#4186

Motivation and Context

This pull request should help to get PR #4187 merged! With the changes from @AlphaYankee all tests succeed.

How Has This Been Tested?

To verify the behavior of the GitLab CI I created a test project that can be found here with all the relevant CI_* variables in the job log output.

This demonstrates how the tagging works in GitLab (CI_COMMIT_TAG available only in pipelines for tags):

CI_COMMIT_REF_NAME=main
CI_COMMIT_REF_NAME=v1.0.0
CI_COMMIT_TAG=v1.0.0

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

In case of a tag pipeline, return null as branch name instead of the tag
@arturcic
Copy link
Member

@Bi0T1N can you actually push these changes to that PR instead?

@Bi0T1N
Copy link
Contributor Author

Bi0T1N commented Jan 31, 2025

How would I do that? I guess I'd need write permissions in the fork from AlphaYankee.

@arturcic
Copy link
Member

it really depends if he put any branch restrictions on his fork, you just add his fork as another origin and push to his branch.

Another option would be instead of pushing to his branch (if there are set restrictions) you can integrate his changes into your PR (your rebase your branch on top of his), so his commits are first added and yours are on top of his changes, this way you keep his original work and yours

@Bi0T1N Bi0T1N force-pushed the fix-gitlab-ci-tag-pipelines-tests branch from 02f2a47 to 5f0d4e7 Compare January 31, 2025 21:52
@Bi0T1N
Copy link
Contributor Author

Bi0T1N commented Jan 31, 2025

I added the changes from AlphaYankee to my branch by a patch file in the proper way.

@Bi0T1N Bi0T1N force-pushed the fix-gitlab-ci-tag-pipelines-tests branch from 5f0d4e7 to e4cf434 Compare January 31, 2025 22:13
@arturcic arturcic added the bug label Feb 1, 2025
@arturcic arturcic added this to the 6.1.x milestone Feb 1, 2025
@arturcic arturcic merged commit 8050584 into GitTools:main Feb 1, 2025
95 checks passed
Copy link
Contributor

mergify bot commented Feb 1, 2025

Thank you @Bi0T1N for your contribution!

@Bi0T1N Bi0T1N deleted the fix-gitlab-ci-tag-pipelines-tests branch February 1, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants