Skip to content

Commit 7053ce5

Browse files
committed
issue/4534-AzurePipelinesPreReleaseLabel
1 parent f37d7df commit 7053ce5

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
assembly-versioning-scheme: MajorMinorPatch
2+
assembly-file-versioning-scheme: MajorMinorPatch
3+
tag-prefix: ''
4+
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
5+
major-version-bump-message: '\+semver:\s?(breaking|major)'
6+
minor-version-bump-message: '\+semver:\s?(feature|minor)'
7+
patch-version-bump-message: '\+semver:\s?(fix|patch)'
8+
no-bump-message: '\+semver:\s?(none|skip)'
9+
tag-pre-release-weight: 60000
10+
commit-date-format: yyyy-MM-dd
11+
merge-message-formats:
12+
tfs: "^Merged (?:PR (?<PullRequestNumber>\\d+)): Merge '?(?<SourceBranch>[^']+)'? (in)?(to) (?<TargetBranch>.+)"
13+
update-build-number: true
14+
semantic-version-format: Strict
15+
strategies:
16+
- Fallback
17+
- ConfiguredNextVersion
18+
- MergeMessage
19+
- TaggedCommit
20+
- TrackReleaseBranches
21+
- VersionInBranchName
22+
branches:
23+
develop:
24+
mode: ContinuousDelivery
25+
label: develop
26+
increment: Minor
27+
prevent-increment:
28+
of-merged-branch: false
29+
track-merge-target: true
30+
regex: ^(refs/heads/)?develop$
31+
source-branches: []
32+
is-source-branch-for: []
33+
tracks-release-branches: true
34+
is-release-branch: false
35+
is-main-branch: false
36+
pre-release-weight: 0
37+
main:
38+
mode: ContinuousDeployment
39+
label: ''
40+
increment: Patch
41+
prevent-increment:
42+
of-merged-branch: true
43+
track-merge-target: false
44+
regex: ^(refs/heads/)?master$|^(refs/heads/)?main$
45+
source-branches:
46+
- develop
47+
- release
48+
- hotfix
49+
is-source-branch-for: []
50+
tracks-release-branches: false
51+
is-release-branch: false
52+
is-main-branch: true
53+
pre-release-weight: 55000
54+
release:
55+
mode: ManualDeployment
56+
label: rc
57+
increment: None
58+
prevent-increment:
59+
of-merged-branch: true
60+
track-merge-target: false
61+
regex: ^(refs/heads/)?releases?[/-](?<BranchName>.+)
62+
source-branches:
63+
- develop
64+
- main
65+
- support
66+
- release
67+
is-source-branch-for: []
68+
tracks-release-branches: false
69+
is-release-branch: true
70+
is-main-branch: false
71+
pre-release-weight: 30000
72+
feature:
73+
mode: ManualDeployment
74+
label: '{BranchName}'
75+
increment: Inherit
76+
prevent-increment:
77+
of-merged-branch: false
78+
track-merge-target: false
79+
regex: ^(refs/heads/)?features?[/-](?<BranchName>.+)
80+
source-branches:
81+
- develop
82+
- main
83+
- release
84+
- feature
85+
- support
86+
- hotfix
87+
is-source-branch-for: []
88+
is-release-branch: false
89+
is-main-branch: false
90+
pre-release-weight: 30000
91+
pull-request:
92+
mode: ManualDeployment
93+
label: PullRequest{Number}
94+
increment: Inherit
95+
prevent-increment:
96+
of-merged-branch: false
97+
track-merge-target: false
98+
regex: ^(refs/)?(pull-requests|pull|pr|pullrequest)[/-](?<Number>\d*)
99+
source-branches:
100+
- develop
101+
- main
102+
- release
103+
- feature
104+
- support
105+
- hotfix
106+
tracks-release-branches: false
107+
is-source-branch-for: []
108+
is-release-branch: false
109+
is-main-branch: false
110+
pre-release-weight: 30000
111+
hotfix:
112+
mode: ManualDeployment
113+
label: beta
114+
increment: Patch
115+
prevent-increment:
116+
of-merged-branch: true
117+
track-merge-target: false
118+
regex: ^(refs/heads/)?hotfix(es)?[/-](?<BranchName>.+)
119+
source-branches:
120+
- develop
121+
- main
122+
- support
123+
tracks-release-branches: false
124+
is-source-branch-for: []
125+
is-release-branch: true
126+
is-main-branch: false
127+
pre-release-weight: 30000
128+
support:
129+
mode: ContinuousDeployment
130+
label: ''
131+
increment: Patch
132+
prevent-increment:
133+
of-merged-branch: true
134+
track-merge-target: false
135+
regex: ^(refs/heads/)?support[/-](?<BranchName>.+)
136+
source-branches:
137+
- main
138+
- pull-request
139+
- feature
140+
- hotfix
141+
is-source-branch-for: []
142+
tracks-release-branches: false
143+
is-release-branch: false
144+
is-main-branch: true
145+
pre-release-weight: 55000
146+
ignore:
147+
sha: []
148+
mode: ContinuousDelivery
149+
label: '{BranchName}'
150+
increment: Inherit
151+
prevent-increment:
152+
of-merged-branch: false
153+
when-branch-merged: false
154+
when-current-commit-tagged: true
155+
track-merge-target: false
156+
track-merge-message: true
157+
commit-message-incrementing: Enabled
158+
regex: ''
159+
source-branches: []
160+
is-source-branch-for: []
161+
tracks-release-branches: false
162+
is-release-branch: false
163+
is-main-branch: false
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using GitVersion.Agents;
2+
using GitVersion.Core.Tests;
3+
using GitVersion.Core.Tests.Helpers;
4+
using GitVersion.Core.Tests.IntegrationTests;
5+
using GitVersion.VersionCalculation;
6+
using Microsoft.Extensions.DependencyInjection;
7+
8+
namespace GitVersion.Configuration.Tests.Configuration
9+
{
10+
internal class AzureScenario4534 : TestBase
11+
{
12+
private IEnvironment environment;
13+
private AzurePipelines buildServer;
14+
15+
[SetUp]
16+
public void SetUp()
17+
{
18+
var sp = ConfigureServices(services => services.AddSingleton<AzurePipelines>());
19+
this.environment = sp.GetRequiredService<IEnvironment>();
20+
this.buildServer = sp.GetRequiredService<AzurePipelines>();
21+
this.environment.SetEnvironmentVariable("TF_BUILD", "true");
22+
this.environment.SetEnvironmentVariable("BUILD_SOURCEBRANCH", "develop");
23+
this.environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", "123456");
24+
}
25+
26+
[Test]
27+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "Readability")]
28+
public void Scenario4534()
29+
{
30+
const string gitVersionYmlFilePath = "GitVersion.BuildAgents.Tests.Agents.4534.yml";
31+
using (var stream = typeof(AzureScenario4534).Assembly.GetManifestResourceStream(gitVersionYmlFilePath))
32+
{
33+
if (stream is null)
34+
{
35+
throw new InvalidOperationException($"The configuration file {gitVersionYmlFilePath} was not found in the assembly resources.");
36+
}
37+
38+
string configContent;
39+
Dictionary<object, object?> configuration;
40+
GitVersionConfiguration? gitVersionConfiguration;
41+
using (var reader = new StreamReader(stream))
42+
{
43+
configContent = reader.ReadToEnd();
44+
configuration = new ConfigurationSerializer().Deserialize<Dictionary<object, object?>>(configContent);
45+
gitVersionConfiguration = new ConfigurationSerializer().Deserialize<GitVersionConfiguration?>(configContent);
46+
}
47+
48+
configuration.ShouldNotBeNull();
49+
gitVersionConfiguration.ShouldNotBeNull();
50+
configuration.ShouldNotBeEmpty();
51+
configuration.ShouldContainKey("mode");
52+
gitVersionConfiguration.DeploymentMode.ShouldBe(DeploymentMode.ContinuousDelivery);
53+
configuration["mode"].ShouldBe("ContinuousDelivery");
54+
configuration.ShouldContainKey("branches");
55+
gitVersionConfiguration.Branches.ShouldNotBeNull();
56+
gitVersionConfiguration.Branches.ContainsKey("main").ShouldBeTrue();
57+
gitVersionConfiguration.Branches.ContainsKey("develop").ShouldBeTrue();
58+
if (configuration["branches"] is Dictionary<object, object?> branchConfigurations)
59+
{
60+
branchConfigurations.ShouldBeOfType<Dictionary<object, object?>>();
61+
branchConfigurations.ShouldContainKey("main");
62+
branchConfigurations.ShouldContainKey("develop");
63+
using (var fixture = new EmptyRepositoryFixture("master"))
64+
{
65+
fixture.MakeACommit();
66+
fixture.BranchTo("develop");
67+
fixture.AssertFullSemver("0.1.0-alpha.1");
68+
fixture.GetVersion(gitVersionConfiguration).PreReleaseLabel.ShouldBe(
69+
"develop",
70+
"What is expected?\nTo get \"develop\" as \"PreReleaseLabel\" " +
71+
"since the branch name is given via env var BUILD_SOURCEBRANCH.");
72+
fixture.SequenceDiagram.NoteOver(
73+
string.Join(
74+
System.Environment.NewLine,
75+
("PreReleaseLabel should be 'develop' as the branch name is " +
76+
"set via environment variable BUILD_SOURCEBRANCH: and this " +
77+
"has been confirmed.").SplitIntoLines(40)),
78+
"develop");
79+
}
80+
}
81+
else
82+
{
83+
throw new InvalidOperationException("Branches configuration is not a dictionary.");
84+
}
85+
}
86+
}
87+
}
88+
}

src/GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<EmbeddedResource Include="Agents\4534.yml">
4+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5+
</EmbeddedResource>
6+
</ItemGroup>
27
<ItemGroup>
38
<ProjectReference Include="..\GitVersion.BuildAgents\GitVersion.BuildAgents.csproj" />
49
<ProjectReference Include="..\GitVersion.Core.Tests\GitVersion.Core.Tests.csproj" />

0 commit comments

Comments
 (0)