Skip to content

Commit ec0f027

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

File tree

3 files changed

+236
-0
lines changed

3 files changed

+236
-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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using GitVersion.Agents;
2+
using GitVersion.Configuration;
3+
using GitVersion.Core.Tests;
4+
using GitVersion.Core.Tests.Helpers;
5+
using GitVersion.Core.Tests.IntegrationTests;
6+
using GitVersion.VersionCalculation;
7+
using Microsoft.Extensions.DependencyInjection;
8+
9+
namespace GitVersion.BuildAgents.Tests.Agents;
10+
11+
internal class AzureScenario4534 : TestBase
12+
{
13+
private IEnvironment environment;
14+
private const string ActualMainBranchName = "master";
15+
private const string ActualDevelopBranchName = "develop";
16+
17+
[SetUp]
18+
public void SetUp()
19+
{
20+
var sp = ConfigureServices(services => services.AddSingleton<AzurePipelines>());
21+
environment = sp.GetRequiredService<IEnvironment>();
22+
environment.SetEnvironmentVariable("TF_BUILD", "true");
23+
environment.SetEnvironmentVariable("BUILD_SOURCEBRANCH", ActualDevelopBranchName);
24+
environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", "123456");
25+
}
26+
27+
[Test]
28+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "Readability")]
29+
public void Scenario4534()
30+
{
31+
const string gitVersionYmlFilePath = "GitVersion.BuildAgents.Tests.Agents.4534.yml";
32+
using (var stream = typeof(AzureScenario4534).Assembly.GetManifestResourceStream(gitVersionYmlFilePath))
33+
{
34+
if (stream is null)
35+
throw new InvalidOperationException($"The configuration file {gitVersionYmlFilePath} was not found in the assembly resources.");
36+
37+
GitVersionConfiguration? gitVersionConfiguration;
38+
using (var reader = new StreamReader(stream))
39+
{
40+
gitVersionConfiguration = new ConfigurationSerializer()
41+
.Deserialize<GitVersionConfiguration?>(reader.ReadToEnd());
42+
}
43+
44+
gitVersionConfiguration.ShouldNotBeNull();
45+
gitVersionConfiguration.DeploymentMode.ShouldBe(DeploymentMode.ContinuousDelivery);
46+
gitVersionConfiguration.Branches.ShouldNotBeNull();
47+
gitVersionConfiguration.Branches.ContainsKey(ConfigurationConstants.MainBranchKey).ShouldBeTrue();
48+
gitVersionConfiguration.Branches.ContainsKey(ConfigurationConstants.DevelopBranchKey).ShouldBeTrue();
49+
using (var fixture = new EmptyRepositoryFixture(ActualMainBranchName))
50+
{
51+
fixture.MakeACommit();
52+
fixture.BranchTo(ActualDevelopBranchName);
53+
fixture.AssertFullSemver("0.1.0-alpha.1");
54+
fixture.GetVersion(gitVersionConfiguration).PreReleaseLabel.ShouldBe(
55+
ActualDevelopBranchName,
56+
$"What is expected?\nTo get \"{ActualDevelopBranchName}\" as \"PreReleaseLabel\" " +
57+
"since the branch name is given via env var BUILD_SOURCEBRANCH.");
58+
fixture.SequenceDiagram.NoteOver(
59+
string.Join(
60+
SysEnv.NewLine,
61+
($"PreReleaseLabel should be '{ActualDevelopBranchName}' as the branch name is " +
62+
"set via environment variable BUILD_SOURCEBRANCH: and this " +
63+
"has been confirmed.").SplitIntoLines(40)),
64+
ActualDevelopBranchName);
65+
}
66+
}
67+
}
68+
}

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)