From a450cdaa1eec3ce2ebf088344122428fb75ddaf2 Mon Sep 17 00:00:00 2001 From: 9swampy Date: Sat, 28 Jun 2025 21:08:11 +0100 Subject: [PATCH] issue/4534-AzurePipelinesPreReleaseLabel --- .../Agents/4534.yml | 163 ++++++++++++++++++ .../Agents/AzureScenario4534.cs | 68 ++++++++ .../GitVersion.BuildAgents.Tests.csproj | 5 + 3 files changed, 236 insertions(+) create mode 100644 src/GitVersion.BuildAgents.Tests/Agents/4534.yml create mode 100644 src/GitVersion.BuildAgents.Tests/Agents/AzureScenario4534.cs diff --git a/src/GitVersion.BuildAgents.Tests/Agents/4534.yml b/src/GitVersion.BuildAgents.Tests/Agents/4534.yml new file mode 100644 index 0000000000..8f4ee3994f --- /dev/null +++ b/src/GitVersion.BuildAgents.Tests/Agents/4534.yml @@ -0,0 +1,163 @@ +assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +tag-prefix: '' +version-in-branch-pattern: (?[vV]?\d+(\.\d+)?(\.\d+)?).* +major-version-bump-message: '\+semver:\s?(breaking|major)' +minor-version-bump-message: '\+semver:\s?(feature|minor)' +patch-version-bump-message: '\+semver:\s?(fix|patch)' +no-bump-message: '\+semver:\s?(none|skip)' +tag-pre-release-weight: 60000 +commit-date-format: yyyy-MM-dd +merge-message-formats: + tfs: "^Merged (?:PR (?\\d+)): Merge '?(?[^']+)'? (in)?(to) (?.+)" +update-build-number: true +semantic-version-format: Strict +strategies: +- Fallback +- ConfiguredNextVersion +- MergeMessage +- TaggedCommit +- TrackReleaseBranches +- VersionInBranchName +branches: + develop: + mode: ContinuousDelivery + label: develop + increment: Minor + prevent-increment: + of-merged-branch: false + track-merge-target: true + regex: ^(refs/heads/)?develop$ + source-branches: [] + is-source-branch-for: [] + tracks-release-branches: true + is-release-branch: false + is-main-branch: false + pre-release-weight: 0 + main: + mode: ContinuousDeployment + label: '' + increment: Patch + prevent-increment: + of-merged-branch: true + track-merge-target: false + regex: ^(refs/heads/)?master$|^(refs/heads/)?main$ + source-branches: + - develop + - release + - hotfix + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: false + is-main-branch: true + pre-release-weight: 55000 + release: + mode: ManualDeployment + label: rc + increment: None + prevent-increment: + of-merged-branch: true + track-merge-target: false + regex: ^(refs/heads/)?releases?[/-](?.+) + source-branches: + - develop + - main + - support + - release + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: true + is-main-branch: false + pre-release-weight: 30000 + feature: + mode: ManualDeployment + label: '{BranchName}' + increment: Inherit + prevent-increment: + of-merged-branch: false + track-merge-target: false + regex: ^(refs/heads/)?features?[/-](?.+) + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + is-source-branch-for: [] + is-release-branch: false + is-main-branch: false + pre-release-weight: 30000 + pull-request: + mode: ManualDeployment + label: PullRequest{Number} + increment: Inherit + prevent-increment: + of-merged-branch: false + track-merge-target: false + regex: ^(refs/)?(pull-requests|pull|pr|pullrequest)[/-](?\d*) + source-branches: + - develop + - main + - release + - feature + - support + - hotfix + tracks-release-branches: false + is-source-branch-for: [] + is-release-branch: false + is-main-branch: false + pre-release-weight: 30000 + hotfix: + mode: ManualDeployment + label: beta + increment: Patch + prevent-increment: + of-merged-branch: true + track-merge-target: false + regex: ^(refs/heads/)?hotfix(es)?[/-](?.+) + source-branches: + - develop + - main + - support + tracks-release-branches: false + is-source-branch-for: [] + is-release-branch: true + is-main-branch: false + pre-release-weight: 30000 + support: + mode: ContinuousDeployment + label: '' + increment: Patch + prevent-increment: + of-merged-branch: true + track-merge-target: false + regex: ^(refs/heads/)?support[/-](?.+) + source-branches: + - main + - pull-request + - feature + - hotfix + is-source-branch-for: [] + tracks-release-branches: false + is-release-branch: false + is-main-branch: true + pre-release-weight: 55000 +ignore: + sha: [] +mode: ContinuousDelivery +label: '{BranchName}' +increment: Inherit +prevent-increment: + of-merged-branch: false + when-branch-merged: false + when-current-commit-tagged: true +track-merge-target: false +track-merge-message: true +commit-message-incrementing: Enabled +regex: '' +source-branches: [] +is-source-branch-for: [] +tracks-release-branches: false +is-release-branch: false +is-main-branch: false diff --git a/src/GitVersion.BuildAgents.Tests/Agents/AzureScenario4534.cs b/src/GitVersion.BuildAgents.Tests/Agents/AzureScenario4534.cs new file mode 100644 index 0000000000..b27674ded8 --- /dev/null +++ b/src/GitVersion.BuildAgents.Tests/Agents/AzureScenario4534.cs @@ -0,0 +1,68 @@ +using GitVersion.Agents; +using GitVersion.Configuration; +using GitVersion.Core.Tests; +using GitVersion.Core.Tests.Helpers; +using GitVersion.Core.Tests.IntegrationTests; +using GitVersion.VersionCalculation; +using Microsoft.Extensions.DependencyInjection; + +namespace GitVersion.BuildAgents.Tests.Agents; + +internal class AzureScenario4534 : TestBase +{ + private IEnvironment environment; + private const string ActualMainBranchName = "master"; + private const string ActualDevelopBranchName = "develop"; + + [SetUp] + public void SetUp() + { + var sp = ConfigureServices(services => services.AddSingleton()); + environment = sp.GetRequiredService(); + environment.SetEnvironmentVariable("TF_BUILD", "true"); + environment.SetEnvironmentVariable("BUILD_SOURCEBRANCH", ActualDevelopBranchName); + environment.SetEnvironmentVariable("BUILD_BUILDNUMBER", "123456"); + } + + [Test] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0063:Use simple 'using' statement", Justification = "Readability")] + public void Scenario4534() + { + const string gitVersionYmlFilePath = "GitVersion.BuildAgents.Tests.Agents.4534.yml"; + using (var stream = typeof(AzureScenario4534).Assembly.GetManifestResourceStream(gitVersionYmlFilePath)) + { + if (stream is null) + throw new InvalidOperationException($"The configuration file {gitVersionYmlFilePath} was not found in the assembly resources."); + + GitVersionConfiguration? gitVersionConfiguration; + using (var reader = new StreamReader(stream)) + { + gitVersionConfiguration = new ConfigurationSerializer() + .Deserialize(reader.ReadToEnd()); + } + + gitVersionConfiguration.ShouldNotBeNull(); + gitVersionConfiguration.DeploymentMode.ShouldBe(DeploymentMode.ContinuousDelivery); + gitVersionConfiguration.Branches.ShouldNotBeNull(); + gitVersionConfiguration.Branches.ContainsKey(ConfigurationConstants.MainBranchKey).ShouldBeTrue(); + gitVersionConfiguration.Branches.ContainsKey(ConfigurationConstants.DevelopBranchKey).ShouldBeTrue(); + using (var fixture = new EmptyRepositoryFixture(ActualMainBranchName)) + { + fixture.MakeACommit(); + fixture.BranchTo(ActualDevelopBranchName); + fixture.AssertFullSemver("0.1.0-alpha.1"); + fixture.GetVersion(gitVersionConfiguration).PreReleaseLabel.ShouldBe( + ActualDevelopBranchName, + $"What is expected?\nTo get \"{ActualDevelopBranchName}\" as \"PreReleaseLabel\" " + + "since the branch name is given via env var BUILD_SOURCEBRANCH."); + fixture.SequenceDiagram.NoteOver( + string.Join( + SysEnv.NewLine, + ($"PreReleaseLabel should be '{ActualDevelopBranchName}' as the branch name is " + + "set via environment variable BUILD_SOURCEBRANCH: and this " + + "has been confirmed.").SplitIntoLines(40)), + ActualDevelopBranchName); + } + } + } +} diff --git a/src/GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj b/src/GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj index b7253b713e..aa18076537 100644 --- a/src/GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj +++ b/src/GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj @@ -1,4 +1,9 @@ + + + Always + +