Skip to content

Commit a9a1b00

Browse files
committed
(GH-2456) Add test to cover code change
Without the code change, this test fails with an incorrectly asserted version number, similar to 0.3.0-tags-01, when it should be 0.2.0.
1 parent 5b3eaee commit a9a1b00

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using GitTools.Testing;
6+
using GitVersion.BuildAgents;
7+
using GitVersion.Core.Tests.Helpers;
8+
using LibGit2Sharp;
9+
using NUnit.Framework;
10+
using Shouldly;
11+
12+
namespace GitVersion.App.Tests
13+
{
14+
[TestFixture]
15+
public class TagCheckoutInBuildAgentTests
16+
{
17+
[Test]
18+
public async Task VerifyTagCheckoutOnGitHubActions()
19+
{
20+
var env = new Dictionary<string, string>
21+
{
22+
{ GitHubActions.EnvironmentVariableName, "true" },
23+
{ "GITHUB_REF", "ref/tags/0.2.0" },
24+
};
25+
26+
using var fixture = new EmptyRepositoryFixture();
27+
var remoteRepositoryPath = PathHelper.GetTempPath();
28+
RepositoryFixtureBase.Init(remoteRepositoryPath);
29+
using (var remoteRepository = new Repository(remoteRepositoryPath))
30+
{
31+
remoteRepository.Config.Set("user.name", "Test");
32+
remoteRepository.Config.Set("user.email", "[email protected]");
33+
fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath);
34+
Console.WriteLine("Created git repository at {0}", remoteRepositoryPath);
35+
remoteRepository.MakeATaggedCommit("0.1.0");
36+
Commands.Checkout(remoteRepository, remoteRepository.CreateBranch("develop"));
37+
remoteRepository.MakeACommit();
38+
Commands.Checkout(remoteRepository, remoteRepository.CreateBranch("release/0.2.0"));
39+
remoteRepository.MakeACommit();
40+
Commands.Checkout(remoteRepository, "main");
41+
remoteRepository.MergeNoFF("release/0.2.0", Generate.SignatureNow());
42+
remoteRepository.MakeATaggedCommit("0.2.0");
43+
44+
Commands.Fetch((Repository)fixture.Repository, "origin", new string[0], new FetchOptions(), null);
45+
Commands.Checkout(fixture.Repository, "0.2.0");
46+
}
47+
48+
var programFixture = new ProgramFixture(fixture.RepositoryPath);
49+
programFixture.WithEnv(env.ToArray());
50+
51+
var result = await programFixture.Run();
52+
53+
result.ExitCode.ShouldBe(0);
54+
result.OutputVariables.FullSemVer.ShouldBe("0.2.0");
55+
56+
// Cleanup repository files
57+
DirectoryHelper.DeleteDirectory(remoteRepositoryPath);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)