Skip to content

Commit

Permalink
GitTools#4017 - added Approval tests for default Configuration Workflows
Browse files Browse the repository at this point in the history
If the configuration for a workflow will change the unit test will fail and will require to accept the new changes. These changes are then copied to the docs
  • Loading branch information
arturcic committed Jul 17, 2024
1 parent 7819c9b commit 9ea1b88
Show file tree
Hide file tree
Showing 11 changed files with 471 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/input/docs/workflows/GitFlow/v1.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
Expand Down
8 changes: 4 additions & 4 deletions docs/input/docs/workflows/GitHubFlow/v1.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
Expand Down Expand Up @@ -57,12 +57,12 @@ branches:
increment: Inherit
prevent-increment:
when-current-commit-tagged: false
track-merge-message: true
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- main
- release
is-source-branch-for: []
track-merge-message: true
is-main-branch: false
pre-release-weight: 30000
pull-request:
Expand All @@ -73,28 +73,28 @@ branches:
of-merged-branch: true
when-current-commit-tagged: false
label-number-pattern: '[/-](?<number>\d+)'
track-merge-message: true
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
- release
- feature
is-source-branch-for: []
track-merge-message: true
pre-release-weight: 30000
unknown:
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
prevent-increment:
when-current-commit-tagged: false
track-merge-message: false
regex: (?<BranchName>.+)
source-branches:
- main
- release
- feature
- pull-request
is-source-branch-for: []
track-merge-message: false
is-main-branch: false
ignore:
sha: []
Expand Down
33 changes: 27 additions & 6 deletions docs/input/docs/workflows/TrunkBased/preview1.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
Expand All @@ -12,55 +12,74 @@ merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies:
- Mainline
- ConfiguredNextVersion
- Mainline
branches:
main:
mode: ContinuousDeployment
label: ''
increment: Patch
prevent-increment:
of-merged-branch: true
when-current-commit-tagged: true
track-merge-target: false
track-merge-message: true
regex: ^master$|^main$
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
feature:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Minor
regex: ^features?[/-](?<BranchName>.+)
prevent-increment:
when-current-commit-tagged: false
track-merge-message: true
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- main
is-source-branch-for: []
is-main-branch: false
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Patch
regex: ^hotfix(es)?[/-](?<BranchName>.+)
prevent-increment:
when-current-commit-tagged: false
regex: ^hotfix(es)?[/-](?<BranchName>.+)
source-branches:
- main
is-source-branch-for: []
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
prevent-increment:
of-merged-branch: true
when-current-commit-tagged: false
label-number-pattern: '[/-](?<number>\d+)'
track-merge-message: true
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
- feature
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
unknown:
increment: Patch
regex: (?<BranchName>.+)
prevent-increment:
when-current-commit-tagged: false
regex: (?<BranchName>.+)
source-branches:
- main
is-source-branch-for: []
pre-release-weight: 30000
ignore:
sha: []
Expand All @@ -75,6 +94,8 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@
<ProjectReference Include="..\GitVersion.Configuration\GitVersion.Configuration.csproj" />
<ProjectReference Include="..\GitVersion.Core.Tests\GitVersion.Core.Tests.csproj" />
</ItemGroup>

<!-- Add the following target to copy the workflow files to the docs folder.
Whenever the Workflow changes, the docs folder will be updated with the latest version.
-->
<Target Name="CopyWorkflowFiles" BeforeTargets="BeforeBuild">
<ItemGroup>
<WorkflowFiles Include="Workflows\approved\**\*.yml" />
</ItemGroup>

<Copy SourceFiles="@(WorkflowFiles)"
DestinationFiles="@(WorkflowFiles->'..\..\docs\input\docs\workflows\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

</Project>
36 changes: 36 additions & 0 deletions src/GitVersion.Configuration.Tests/Workflows/WorkflowsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace GitVersion.Configuration.Tests.Configuration;

[TestFixture]
public class WorkflowsTests
{
private readonly ConfigurationSerializer serializer = new();

private static readonly object[][] Workflows =
[
["GitFlow/v1", GitFlowConfigurationBuilder.New],
["GitHubFlow/v1", GitHubFlowConfigurationBuilder.New],
["TrunkBased/preview1", TrunkBasedConfigurationBuilder.New]
];

[Test(Description = "This test is to ensure that the configuration for workflow is up to date")]
[TestCaseSource(nameof(Workflows))]
public void CheckWorkflowsAreUpdated(string workflow, IConfigurationBuilder configurationBuilder)
{
var configuration = configurationBuilder.Build();

var serializedConfiguration = serializer.Serialize(configuration);
var segments = workflow.Split("/");
var folderName = segments[0];
var fileName = segments[^1];

serializedConfiguration.ShouldMatchApproved(builder => builder
.WithFilenameGenerator((_, _, type, extension) => FilenameGenerator(fileName, type, extension))
.WithFileExtension("yml")
.SubFolder($"approved/{folderName}"));
}

private static string FilenameGenerator(string fileName, string type, string ext) =>
type == "approved"
? $"{fileName}.{ext}"
: $"{fileName}.{type}.{ext}";
}
167 changes: 167 additions & 0 deletions src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
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: {}
update-build-number: true
semantic-version-format: Strict
strategies:
- Fallback
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
develop:
mode: ContinuousDelivery
label: alpha
increment: Minor
prevent-increment:
when-current-commit-tagged: false
track-merge-target: true
track-merge-message: true
regex: ^dev(elop)?(ment)?$
source-branches:
- main
is-source-branch-for: []
tracks-release-branches: true
is-release-branch: false
is-main-branch: false
pre-release-weight: 0
main:
label: ''
increment: Patch
prevent-increment:
of-merged-branch: true
track-merge-target: false
track-merge-message: true
regex: ^master$|^main$
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
release:
mode: ManualDeployment
label: beta
increment: Minor
prevent-increment:
of-merged-branch: true
when-current-commit-tagged: false
track-merge-target: false
regex: ^releases?[/-](?<BranchName>.+)
source-branches:
- main
- support
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:
when-current-commit-tagged: false
track-merge-message: true
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- develop
- main
- release
- support
- hotfix
is-source-branch-for: []
is-main-branch: false
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
prevent-increment:
of-merged-branch: true
when-current-commit-tagged: false
label-number-pattern: '[/-](?<number>\d+)'
track-merge-message: true
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- develop
- main
- release
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
hotfix:
mode: ManualDeployment
label: beta
increment: Inherit
prevent-increment:
when-current-commit-tagged: false
regex: ^hotfix(es)?[/-](?<BranchName>.+)
source-branches:
- main
- support
is-source-branch-for: []
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
support:
label: ''
increment: Patch
prevent-increment:
of-merged-branch: true
track-merge-target: false
regex: ^support[/-](?<BranchName>.+)
source-branches:
- main
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
unknown:
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
prevent-increment:
when-current-commit-tagged: true
regex: (?<BranchName>.+)
source-branches:
- main
- develop
- release
- feature
- pull-request
- hotfix
- support
is-source-branch-for: []
is-main-branch: false
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
Loading

0 comments on commit 9ea1b88

Please sign in to comment.