Skip to content

Scenario for issue/4534-AzurePipelinesPreReleaseLabel #4606

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions src/GitVersion.BuildAgents.Tests/Agents/4534.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: ''
version-in-branch-pattern: (?<version>[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 (?<PullRequestNumber>\\d+)): Merge '?(?<SourceBranch>[^']+)'? (in)?(to) (?<TargetBranch>.+)"
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?[/-](?<BranchName>.+)
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?[/-](?<BranchName>.+)
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)[/-](?<Number>\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)?[/-](?<BranchName>.+)
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[/-](?<BranchName>.+)
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
68 changes: 68 additions & 0 deletions src/GitVersion.BuildAgents.Tests/Agents/AzureScenario4534.cs
Original file line number Diff line number Diff line change
@@ -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<AzurePipelines>());
environment = sp.GetRequiredService<IEnvironment>();
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<GitVersionConfiguration?>(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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<EmbeddedResource Include="Agents\4534.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitVersion.BuildAgents\GitVersion.BuildAgents.csproj" />
<ProjectReference Include="..\GitVersion.Core.Tests\GitVersion.Core.Tests.csproj" />
Expand Down