diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index 2fbd2bebb1..a4955c9804 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -41,26 +41,42 @@ The built-in configuration for the `GitFlow` workflow (`workflow: GitFlow/v1`) l ```yml +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: develop: mode: ContinuousDelivery @@ -72,7 +88,7 @@ branches: track-merge-message: true regex: ^dev(elop)?(ment)?$ source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: true is-release-branch: false @@ -85,7 +101,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -100,10 +116,10 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -111,37 +127,37 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - develop - - main - - release - - support - - hotfix + - develop + - main + - release + - support + - hotfix is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - develop - - main - - release - - feature - - support - - hotfix + - develop + - main + - release + - feature + - support + - hotfix is-source-branch-for: [] pre-release-weight: 30000 hotfix: @@ -150,10 +166,10 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] is-release-branch: true is-main-branch: false @@ -164,9 +180,9 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[\/-](?.+) + regex: "^support[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: false @@ -174,26 +190,35 @@ branches: pre-release-weight: 55000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: true - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - develop - - release - - feature - - pull-request - - hotfix - - support + - main + - develop + - release + - feature + - pull-request + - hotfix + - support is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] +``` +snippet source | anchor + + +The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like: + + + +```yml mode: ContinuousDelivery -label: '{BranchName}' +label: "{BranchName}" increment: Inherit prevent-increment: of-merged-branch: false @@ -208,35 +233,26 @@ is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: false -``` -snippet source | anchor - - -The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like: - - - -```yml assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: main: label: '' @@ -245,7 +261,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -262,9 +278,9 @@ branches: when-current-commit-tagged: false track-merge-target: false track-merge-message: true - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -272,53 +288,62 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - main - - release + - main + - release is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - main - - release - - feature + - main + - release + - feature is-source-branch-for: [] pre-release-weight: 30000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: false - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - release - - feature - - pull-request + - main + - release + - feature + - pull-request is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] +``` +snippet source | anchor + + +The preview built-in configuration (experimental usage only) for the `TrunkBased` workflow (`workflow: TrunkBased/preview1`) looks like: + + + +```yml mode: ContinuousDelivery -label: '{BranchName}' +label: "{BranchName}" increment: Inherit prevent-increment: of-merged-branch: false @@ -333,31 +358,22 @@ is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: false -``` -snippet source | anchor - - -The preview built-in configuration (experimental usage only) for the `TrunkBased` workflow (`workflow: TrunkBased/preview1`) looks like: - - - -```yml assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- ConfiguredNextVersion -- Mainline + - ConfiguredNextVersion + - Mainline branches: main: mode: ContinuousDeployment @@ -367,7 +383,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -376,73 +392,57 @@ branches: pre-release-weight: 55000 feature: mode: ContinuousDelivery - label: '{BranchName}' + label: "{BranchName}" increment: Minor prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 hotfix: mode: ContinuousDelivery - label: '{BranchName}' + label: "{BranchName}" increment: Patch prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] is-release-branch: true is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - main - - feature - - hotfix + - main + - feature + - hotfix is-source-branch-for: [] pre-release-weight: 30000 unknown: increment: Patch prevent-increment: when-current-commit-tagged: false - regex: (?.+) + regex: "(?.+)" source-branches: - - main + - main is-source-branch-for: [] pre-release-weight: 30000 ignore: sha: [] paths: [] -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 ``` snippet source | anchor diff --git a/docs/input/docs/workflows/GitFlow/v1.yml b/docs/input/docs/workflows/GitFlow/v1.yml index dd44250ac5..63c7855dc8 100644 --- a/docs/input/docs/workflows/GitFlow/v1.yml +++ b/docs/input/docs/workflows/GitFlow/v1.yml @@ -1,23 +1,39 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: develop: mode: ContinuousDelivery @@ -29,7 +45,7 @@ branches: track-merge-message: true regex: ^dev(elop)?(ment)?$ source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: true is-release-branch: false @@ -42,7 +58,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -57,10 +73,10 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -68,37 +84,37 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - develop - - main - - release - - support - - hotfix + - develop + - main + - release + - support + - hotfix is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - develop - - main - - release - - feature - - support - - hotfix + - develop + - main + - release + - feature + - support + - hotfix is-source-branch-for: [] pre-release-weight: 30000 hotfix: @@ -107,10 +123,10 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] is-release-branch: true is-main-branch: false @@ -121,9 +137,9 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[\/-](?.+) + regex: "^support[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: false @@ -131,37 +147,21 @@ branches: pre-release-weight: 55000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: true - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - develop - - release - - feature - - pull-request - - hotfix - - support + - main + - develop + - release + - feature + - pull-request + - hotfix + - support is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] -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/docs/input/docs/workflows/GitHubFlow/v1.yml b/docs/input/docs/workflows/GitHubFlow/v1.yml index be7da3a729..b45381a41a 100644 --- a/docs/input/docs/workflows/GitHubFlow/v1.yml +++ b/docs/input/docs/workflows/GitHubFlow/v1.yml @@ -1,23 +1,39 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: main: label: '' @@ -26,7 +42,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -43,9 +59,9 @@ branches: when-current-commit-tagged: false track-merge-target: false track-merge-message: true - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -53,64 +69,48 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - main - - release + - main + - release is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - main - - release - - feature + - main + - release + - feature is-source-branch-for: [] pre-release-weight: 30000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: false - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - release - - feature - - pull-request + - main + - release + - feature + - pull-request is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] -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/docs/input/docs/workflows/TrunkBased/preview1.yml b/docs/input/docs/workflows/TrunkBased/preview1.yml index c261444d9f..0b8cfcda4f 100644 --- a/docs/input/docs/workflows/TrunkBased/preview1.yml +++ b/docs/input/docs/workflows/TrunkBased/preview1.yml @@ -1,19 +1,35 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- ConfiguredNextVersion -- Mainline + - ConfiguredNextVersion + - Mainline branches: main: mode: ContinuousDeployment @@ -23,7 +39,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -32,70 +48,54 @@ branches: pre-release-weight: 55000 feature: mode: ContinuousDelivery - label: '{BranchName}' + label: "{BranchName}" increment: Minor prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 hotfix: mode: ContinuousDelivery - label: '{BranchName}' + label: "{BranchName}" increment: Patch prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] is-release-branch: true is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - main - - feature - - hotfix + - main + - feature + - hotfix is-source-branch-for: [] pre-release-weight: 30000 unknown: increment: Patch prevent-increment: when-current-commit-tagged: false - regex: (?.+) + regex: "(?.+)" source-branches: - - main + - main is-source-branch-for: [] pre-release-weight: 30000 ignore: sha: [] paths: [] -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/Directory.Packages.props b/src/Directory.Packages.props index 049122f0ac..2abada83a1 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -40,6 +40,7 @@ + @@ -48,7 +49,6 @@ - diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationHelperTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationHelperTests.cs new file mode 100644 index 0000000000..fee64851b1 --- /dev/null +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationHelperTests.cs @@ -0,0 +1,82 @@ +namespace GitVersion.Configuration.Tests; + +[TestFixture] +public class ConfigurationHelperTests +{ + [Test] + public void Override_Replaces_Nested_Dictionary_With_Scalar_Value() + { + Dictionary original = + new() + { + ["key"] = new Dictionary { ["nested"] = "value" } + }; + var helper = new ConfigurationHelper(original); + + IReadOnlyDictionary source = + new Dictionary + { + ["key"] = "override" + }; + + helper.Override(source); + + helper.Dictionary["key"].ShouldBe("override"); + } + + [Test] + public void Override_Merges_Nested_Dictionaries_Recursively() + { + Dictionary original = + new() + { + ["key"] = new Dictionary + { + ["a"] = 1, + ["b"] = 2 + } + }; + var helper = new ConfigurationHelper(original); + + IReadOnlyDictionary source = + new Dictionary + { + ["key"] = new Dictionary + { + ["b"] = 3, + ["c"] = 4 + } + }; + + helper.Override(source); + + var nested = (IDictionary)helper.Dictionary["key"]!; + nested["a"].ShouldBe(1); + nested["b"].ShouldBe(3); + nested["c"].ShouldBe(4); + } + + [Test] + public void Override_Clones_New_Nested_Dictionaries() + { + Dictionary original = []; + var helper = new ConfigurationHelper(original); + + Dictionary sourceNested = + new() + { + ["a"] = 1 + }; + IReadOnlyDictionary source = + new Dictionary + { + ["key"] = sourceNested + }; + + helper.Override(source); + sourceNested["a"] = 2; + + var nested = (IDictionary)helper.Dictionary["key"]!; + nested["a"].ShouldBe(1); + } +} diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index dd44250ac5..63c7855dc8 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -1,23 +1,39 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: develop: mode: ContinuousDelivery @@ -29,7 +45,7 @@ branches: track-merge-message: true regex: ^dev(elop)?(ment)?$ source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: true is-release-branch: false @@ -42,7 +58,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -57,10 +73,10 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -68,37 +84,37 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - develop - - main - - release - - support - - hotfix + - develop + - main + - release + - support + - hotfix is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - develop - - main - - release - - feature - - support - - hotfix + - develop + - main + - release + - feature + - support + - hotfix is-source-branch-for: [] pre-release-weight: 30000 hotfix: @@ -107,10 +123,10 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] is-release-branch: true is-main-branch: false @@ -121,9 +137,9 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[\/-](?.+) + regex: "^support[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: false @@ -131,37 +147,21 @@ branches: pre-release-weight: 55000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: true - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - develop - - release - - feature - - pull-request - - hotfix - - support + - main + - develop + - release + - feature + - pull-request + - hotfix + - support is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] -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.Configuration.Tests/Configuration/IgnoreConfigurationTests.cs b/src/GitVersion.Configuration.Tests/Configuration/IgnoreConfigurationTests.cs index 1eccacccca..799a3c502f 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/IgnoreConfigurationTests.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/IgnoreConfigurationTests.cs @@ -1,5 +1,7 @@ +using System.Globalization; using GitVersion.Core.Tests.Helpers; -using YamlDotNet.Core; +using GitVersion.VersionCalculation; +using SharpYaml; namespace GitVersion.Configuration.Tests; @@ -24,7 +26,7 @@ public void CanDeserialize() configuration.Ignore.ShouldNotBeNull(); configuration.Ignore.Shas.ShouldNotBeEmpty(); configuration.Ignore.Shas.ShouldBe(["b6c0c9fda88830ebcd563e500a5a7da5a1658e98"]); - configuration.Ignore.Before.ShouldBe(DateTimeOffset.Parse("2015-10-23T12:23:15")); + configuration.Ignore.Before.ShouldBe(DateTimeOffset.Parse("2015-10-23T12:23:15", CultureInfo.InvariantCulture)); } [Test] @@ -71,6 +73,17 @@ public void WhenBadDateFormatShouldFail() Should.Throw(() => serializer.ReadConfiguration(yaml)); } + [Test] + public void ShouldSupportScalarVersionStrategiesOverrideFormat() + { + const string yaml = "strategies: ConfiguredNextVersion, TaggedCommit"; + + var configuration = serializer.ReadConfiguration(yaml); + + configuration.ShouldNotBeNull(); + configuration.VersionStrategy.ShouldBe(VersionStrategies.ConfiguredNextVersion | VersionStrategies.TaggedCommit); + } + [Test] public void NewInstanceShouldBeEmpty() { diff --git a/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml b/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml index dd44250ac5..63c7855dc8 100644 --- a/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml +++ b/src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml @@ -1,23 +1,39 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: develop: mode: ContinuousDelivery @@ -29,7 +45,7 @@ branches: track-merge-message: true regex: ^dev(elop)?(ment)?$ source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: true is-release-branch: false @@ -42,7 +58,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -57,10 +73,10 @@ branches: of-merged-branch: true when-current-commit-tagged: false track-merge-target: false - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -68,37 +84,37 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - develop - - main - - release - - support - - hotfix + - develop + - main + - release + - support + - hotfix is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - develop - - main - - release - - feature - - support - - hotfix + - develop + - main + - release + - feature + - support + - hotfix is-source-branch-for: [] pre-release-weight: 30000 hotfix: @@ -107,10 +123,10 @@ branches: increment: Inherit prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main - - support + - main + - support is-source-branch-for: [] is-release-branch: true is-main-branch: false @@ -121,9 +137,9 @@ branches: prevent-increment: of-merged-branch: true track-merge-target: false - regex: ^support[\/-](?.+) + regex: "^support[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: false @@ -131,37 +147,21 @@ branches: pre-release-weight: 55000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: true - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - develop - - release - - feature - - pull-request - - hotfix - - support + - main + - develop + - release + - feature + - pull-request + - hotfix + - support is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] -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.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml b/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml index be7da3a729..b45381a41a 100644 --- a/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml +++ b/src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml @@ -1,23 +1,39 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- Fallback -- ConfiguredNextVersion -- MergeMessage -- TaggedCommit -- TrackReleaseBranches -- VersionInBranchName + - Fallback + - ConfiguredNextVersion + - MergeMessage + - TaggedCommit + - TrackReleaseBranches + - VersionInBranchName branches: main: label: '' @@ -26,7 +42,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -43,9 +59,9 @@ branches: when-current-commit-tagged: false track-merge-target: false track-merge-message: true - regex: ^releases?[\/-](?.+) + regex: "^releases?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] tracks-release-branches: false is-release-branch: true @@ -53,64 +69,48 @@ branches: pre-release-weight: 30000 feature: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - main - - release + - main + - release is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - main - - release - - feature + - main + - release + - feature is-source-branch-for: [] pre-release-weight: 30000 unknown: mode: ManualDeployment - label: '{BranchName}' + label: "{BranchName}" increment: Inherit prevent-increment: when-current-commit-tagged: false track-merge-message: false - regex: (?.+) + regex: "(?.+)" source-branches: - - main - - release - - feature - - pull-request + - main + - release + - feature + - pull-request is-source-branch-for: [] is-main-branch: false ignore: sha: [] paths: [] -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.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml b/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml index c261444d9f..0b8cfcda4f 100644 --- a/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml +++ b/src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml @@ -1,19 +1,35 @@ +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 assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch -tag-prefix: '[vV]?' -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-prefix: "[vV]?" +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: {} update-build-number: true semantic-version-format: Strict strategies: -- ConfiguredNextVersion -- Mainline + - ConfiguredNextVersion + - Mainline branches: main: mode: ContinuousDeployment @@ -23,7 +39,7 @@ branches: of-merged-branch: true track-merge-target: false track-merge-message: true - regex: ^master$|^main$ + regex: "^master$|^main$" source-branches: [] is-source-branch-for: [] tracks-release-branches: false @@ -32,70 +48,54 @@ branches: pre-release-weight: 55000 feature: mode: ContinuousDelivery - label: '{BranchName}' + label: "{BranchName}" increment: Minor prevent-increment: when-current-commit-tagged: false track-merge-message: true - regex: ^features?[\/-](?.+) + regex: "^features?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] is-main-branch: false pre-release-weight: 30000 hotfix: mode: ContinuousDelivery - label: '{BranchName}' + label: "{BranchName}" increment: Patch prevent-increment: when-current-commit-tagged: false - regex: ^hotfix(es)?[\/-](?.+) + regex: "^hotfix(es)?[\\/-](?.+)" source-branches: - - main + - main is-source-branch-for: [] is-release-branch: true is-main-branch: false pre-release-weight: 30000 pull-request: mode: ContinuousDelivery - label: PullRequest{Number} + label: "PullRequest{Number}" increment: Inherit prevent-increment: of-merged-branch: true when-current-commit-tagged: false track-merge-message: true - regex: ^(pull-requests|pull|pr)[\/-](?\d*) + regex: "^(pull-requests|pull|pr)[\\/-](?\\d*)" source-branches: - - main - - feature - - hotfix + - main + - feature + - hotfix is-source-branch-for: [] pre-release-weight: 30000 unknown: increment: Patch prevent-increment: when-current-commit-tagged: false - regex: (?.+) + regex: "(?.+)" source-branches: - - main + - main is-source-branch-for: [] pre-release-weight: 30000 ignore: sha: [] paths: [] -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.Configuration/BranchConfiguration.cs b/src/GitVersion.Configuration/BranchConfiguration.cs index 699f67fcd5..96a211a889 100644 --- a/src/GitVersion.Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Configuration/BranchConfiguration.cs @@ -8,72 +8,72 @@ internal record BranchConfiguration : IBranchConfiguration { [JsonPropertyName("mode")] [JsonPropertyDescription("The deployment mode for this branch. Can be 'ManualDeployment', 'ContinuousDelivery', 'ContinuousDeployment'.")] - public DeploymentMode? DeploymentMode { get; internal init; } + public DeploymentMode? DeploymentMode { get; set; } [JsonPropertyName("label")] [JsonPropertyDescription("The label to use for this branch. Use the value {BranchName} or similar as a placeholder to insert a named capture group from RegularExpression (fx. the branch name).")] - public string? Label { get; internal init; } + public string? Label { get; set; } [JsonPropertyName("increment")] [JsonPropertyDescription("The increment strategy for this branch. Can be 'Inherit', 'Patch', 'Minor', 'Major', 'None'.")] - public IncrementStrategy Increment { get; internal init; } + public IncrementStrategy Increment { get; set; } [JsonIgnore] IPreventIncrementConfiguration IBranchConfiguration.PreventIncrement => PreventIncrement; [JsonPropertyName("prevent-increment")] [JsonPropertyDescription("The prevent increment configuration section.")] - public PreventIncrementConfiguration PreventIncrement { get; internal init; } = new(); + public PreventIncrementConfiguration PreventIncrement { get; set; } = new(); [JsonPropertyName("track-merge-target")] [JsonPropertyDescription("Strategy which will look for tagged merge commits directly off the current branch.")] - public bool? TrackMergeTarget { get; internal init; } + public bool? TrackMergeTarget { get; set; } [JsonPropertyName("track-merge-message")] [JsonPropertyDescription("This property is a branch related property and gives the user the possibility to control the behavior of whether the merge commit message will be interpreted as a next version or not.")] - public bool? TrackMergeMessage { get; internal init; } + public bool? TrackMergeMessage { get; set; } [JsonPropertyName("commit-message-incrementing")] [JsonPropertyDescription("Sets whether it should be possible to increment the version with special syntax in the commit message. Can be 'Disabled', 'Enabled' or 'MergeMessageOnly'.")] - public CommitMessageIncrementMode? CommitMessageIncrementing { get; internal init; } + public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; } [JsonPropertyName("regex")] [JsonPropertyDescription("The regular expression pattern to use to match this branch.")] [JsonPropertyFormat(Format.Regex)] - public string? RegularExpression { get; internal init; } + public string? RegularExpression { get; set; } [JsonIgnore] string? IBranchConfiguration.RegularExpression => RegularExpression; [JsonPropertyName("source-branches")] [JsonPropertyDescription("The source branches for this branch.")] - public HashSet SourceBranches { get; internal init; } = []; + public HashSet SourceBranches { get; set; } = []; [JsonIgnore] IReadOnlyCollection IBranchConfiguration.SourceBranches => SourceBranches; [JsonPropertyName("is-source-branch-for")] [JsonPropertyDescription("The branches that this branch is a source branch.")] - public HashSet IsSourceBranchFor { get; internal init; } = []; + public HashSet IsSourceBranchFor { get; set; } = []; [JsonIgnore] IReadOnlyCollection IBranchConfiguration.IsSourceBranchFor => IsSourceBranchFor; [JsonPropertyName("tracks-release-branches")] [JsonPropertyDescription("Indicates this branch configuration represents develop in GitFlow.")] - public bool? TracksReleaseBranches { get; internal init; } + public bool? TracksReleaseBranches { get; set; } [JsonPropertyName("is-release-branch")] [JsonPropertyDescription("Indicates this branch configuration represents a release branch in GitFlow.")] - public bool? IsReleaseBranch { get; internal init; } + public bool? IsReleaseBranch { get; set; } [JsonPropertyName("is-main-branch")] [JsonPropertyDescription("When using Mainline mode, this indicates that this branch is a mainline. By default main and support/* are mainlines.")] - public bool? IsMainBranch { get; internal init; } + public bool? IsMainBranch { get; set; } [JsonPropertyName("pre-release-weight")] [JsonPropertyDescription("Provides a way to translate the PreReleaseLabel to a number.")] - public int? PreReleaseWeight { get; internal init; } + public int? PreReleaseWeight { get; set; } public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration) { diff --git a/src/GitVersion.Configuration/ConfigurationHelper.cs b/src/GitVersion.Configuration/ConfigurationHelper.cs index 0410558782..46917a12d9 100644 --- a/src/GitVersion.Configuration/ConfigurationHelper.cs +++ b/src/GitVersion.Configuration/ConfigurationHelper.cs @@ -45,54 +45,33 @@ public void Override(IReadOnlyDictionary value) private static void Merge(IDictionary dictionary, IReadOnlyDictionary anotherDictionary) { - foreach (var item in dictionary) + foreach (var (key, sourceValue) in anotherDictionary) { - switch (item.Value) + if (dictionary.TryGetValue(key, out var currentValue) + && currentValue is IDictionary currentDictionary + && sourceValue is IReadOnlyDictionary sourceDictionary) { - case IDictionary anotherDictionaryValue: - { - if (anotherDictionary.TryGetValue(item.Key, out var value) && value is IReadOnlyDictionary dictionaryValue) - { - Merge(anotherDictionaryValue, dictionaryValue); - } - - break; - } - case null or string or IList: - { - if (anotherDictionary.TryGetValue(item.Key, out var value)) - { - dictionary[item.Key] = value; - } - - break; - } + Merge(currentDictionary, sourceDictionary); + continue; } + + dictionary[key] = sourceValue is IReadOnlyDictionary nestedDictionary + ? CloneDictionary(nestedDictionary) + : sourceValue; } + } - foreach (var item in anotherDictionary) - { - switch (item.Value) - { - case IReadOnlyDictionary when dictionary.ContainsKey(item.Key): - continue; - case IReadOnlyDictionary dictionaryValue: - { - Dictionary anotherDictionaryValue = []; - Merge(anotherDictionaryValue, dictionaryValue); - dictionary.Add(item.Key, anotherDictionaryValue); - break; - } - case null or string or IList: - { - if (!dictionary.ContainsKey(item.Key)) - { - dictionary.Add(item.Key, item.Value); - } + private static Dictionary CloneDictionary(IReadOnlyDictionary dictionary) + { + Dictionary cloned = []; - break; - } - } + foreach (var (key, value) in dictionary) + { + cloned[key] = value is IReadOnlyDictionary nestedDictionary + ? CloneDictionary(nestedDictionary) + : value; } + + return cloned; } } diff --git a/src/GitVersion.Configuration/ConfigurationProvider.cs b/src/GitVersion.Configuration/ConfigurationProvider.cs index 0605dc07a8..d0ce12c659 100644 --- a/src/GitVersion.Configuration/ConfigurationProvider.cs +++ b/src/GitVersion.Configuration/ConfigurationProvider.cs @@ -2,7 +2,7 @@ using GitVersion.Configuration.Workflows; using GitVersion.Extensions; using GitVersion.Logging; -using YamlDotNet.Core; +using SharpYaml; namespace GitVersion.Configuration; diff --git a/src/GitVersion.Configuration/ConfigurationSerializer.cs b/src/GitVersion.Configuration/ConfigurationSerializer.cs index 5517252772..e3fa4b13e5 100644 --- a/src/GitVersion.Configuration/ConfigurationSerializer.cs +++ b/src/GitVersion.Configuration/ConfigurationSerializer.cs @@ -1,46 +1,111 @@ -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; -using YamlDotNet.Serialization.TypeInspectors; +using SharpYaml; namespace GitVersion.Configuration; internal class ConfigurationSerializer : IConfigurationSerializer { - private static IDeserializer Deserializer => new DeserializerBuilder() - .WithNamingConvention(HyphenatedNamingConvention.Instance) - .WithTypeConverter(VersionStrategiesConverter.Instance) - .WithTypeInspector(inspector => new JsonPropertyNameInspector(inspector)) - .Build(); - - private static ISerializer Serializer => new SerializerBuilder() - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull) - .WithTypeInspector(inspector => new JsonPropertyNameInspector(inspector)) - .WithNamingConvention(HyphenatedNamingConvention.Instance).Build(); - - public T Deserialize(string input) => Deserializer.Deserialize(input); - public string Serialize(object graph) => Serializer.Serialize(graph); + private static readonly ConfigurationYamlContext GeneratedContext = ConfigurationYamlContext.Default; + + private static readonly YamlSerializerOptions SerializerOptions = new() + { + PropertyNamingPolicy = HyphenatedJsonNamingPolicy.Instance, + DefaultIgnoreCondition = YamlIgnoreCondition.WhenWritingNull, + Converters = [VersionStrategiesConverter.Instance] + }; + + public T Deserialize(string input) + { + if (typeof(T) == typeof(Dictionary)) + { + var graph = YamlSerializer.Deserialize>(input, SerializerOptions); + return (T)(object)ConvertToObjectDictionary(graph); + } + + if (typeof(T) == typeof(GitVersionConfiguration)) + { + try + { + return (T)(object)YamlSerializer.Deserialize(input, GeneratedContext)!; + } + catch (Exception exception) when (exception is not YamlException) + { + throw new YamlException(exception.Message, exception); + } + } + + return YamlSerializer.Deserialize(input, SerializerOptions)!; + } + + public string Serialize(object graph) + => YamlSerializer.Serialize(graph, SerializerOptions); + public IGitVersionConfiguration? ReadConfiguration(string input) => Deserialize(input); - private sealed class JsonPropertyNameInspector(ITypeInspector innerTypeDescriptor) : TypeInspectorSkeleton + private static Dictionary ConvertToObjectDictionary(IReadOnlyDictionary? source) { - public override string GetEnumName(Type enumType, string name) => innerTypeDescriptor.GetEnumName(enumType, name); + if (source is null) return []; - public override string GetEnumValue(object enumValue) => innerTypeDescriptor.GetEnumValue(enumValue); + Dictionary result = []; + foreach (var item in source) + { + result[item.Key] = ConvertValue(item.Value); + } - public override IEnumerable GetProperties(Type type, object? container) => - innerTypeDescriptor.GetProperties(type, container) - .Where(p => p.GetCustomAttribute() == null) - .Select(IPropertyDescriptor (p) => + return result; + } + + private static object? ConvertValue(object? value) => value switch + { + IReadOnlyDictionary dictionary => ConvertToObjectDictionary(dictionary), + IDictionary dictionary => ConvertToObjectDictionary(new Dictionary(dictionary)), + IList list => ConvertList(list), + _ => value + }; + + private static List ConvertList(IList list) + { + List result = []; + foreach (var item in list) + { + result.Add(ConvertValue(item)); + } + + return result; + } + + private sealed class HyphenatedJsonNamingPolicy : JsonNamingPolicy + { + public static JsonNamingPolicy Instance { get; } = new HyphenatedJsonNamingPolicy(); + + public override string ConvertName(string name) + { + if (string.IsNullOrEmpty(name)) return name; + + var builder = new StringBuilder(name.Length + 8); + for (var index = 0; index < name.Length; index++) + { + var current = name[index]; + if (char.IsUpper(current)) { - var descriptor = new PropertyDescriptor(p); - var member = p.GetCustomAttribute(); - if (member is not null) + var hasPrevious = index > 0; + var hasNext = index + 1 < name.Length; + var previousIsLowerOrDigit = hasPrevious && (char.IsLower(name[index - 1]) || char.IsDigit(name[index - 1])); + var nextIsLower = hasNext && char.IsLower(name[index + 1]); + + if (hasPrevious && (previousIsLowerOrDigit || nextIsLower)) { - descriptor.Name = member.Name; + builder.Append('-'); } - return descriptor; - }) - .OrderBy(p => p.Order); + builder.Append(char.ToLowerInvariant(current)); + } + else + { + builder.Append(current); + } + } + + return builder.ToString(); + } } } diff --git a/src/GitVersion.Configuration/ConfigurationYamlContext.cs b/src/GitVersion.Configuration/ConfigurationYamlContext.cs new file mode 100644 index 0000000000..e76e9dde15 --- /dev/null +++ b/src/GitVersion.Configuration/ConfigurationYamlContext.cs @@ -0,0 +1,13 @@ +using SharpYaml; +using SharpYaml.Serialization; + +namespace GitVersion.Configuration; + +[YamlSourceGenerationOptions( + DefaultIgnoreCondition = YamlIgnoreCondition.WhenWritingNull, + Converters = [typeof(VersionStrategiesConverter)])] +[YamlSerializable(typeof(GitVersionConfiguration))] +[YamlSerializable(typeof(BranchConfiguration))] +[YamlSerializable(typeof(PreventIncrementConfiguration))] +[YamlSerializable(typeof(IgnoreConfiguration))] +internal partial class ConfigurationYamlContext : YamlSerializerContext; diff --git a/src/GitVersion.Configuration/GitVersion.Configuration.csproj b/src/GitVersion.Configuration/GitVersion.Configuration.csproj index f4a84de083..79f5abf2d5 100644 --- a/src/GitVersion.Configuration/GitVersion.Configuration.csproj +++ b/src/GitVersion.Configuration/GitVersion.Configuration.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/GitVersion.Configuration/GitVersionConfiguration.cs b/src/GitVersion.Configuration/GitVersionConfiguration.cs index 6e3a49bf9c..7e35964d78 100644 --- a/src/GitVersion.Configuration/GitVersionConfiguration.cs +++ b/src/GitVersion.Configuration/GitVersionConfiguration.cs @@ -10,49 +10,49 @@ internal sealed record GitVersionConfiguration : BranchConfiguration, IGitVersio { [JsonPropertyName("workflow")] [JsonPropertyDescription("The base template of the configuration to use. Possible values are: 'GitFlow/v1' or 'GitHubFlow/v1'")] - public string? Workflow { get; internal init; } + public string? Workflow { get; set; } [JsonPropertyName("assembly-versioning-scheme")] [JsonPropertyDescription($"The scheme to use when setting AssemblyVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to '{NameOfDefaultAssemblyVersioningScheme}'.")] [JsonPropertyDefault(DefaultAssemblyVersioningScheme)] - public AssemblyVersioningScheme? AssemblyVersioningScheme { get; internal init; } + public AssemblyVersioningScheme? AssemblyVersioningScheme { get; set; } [JsonPropertyName("assembly-file-versioning-scheme")] [JsonPropertyDescription($"The scheme to use when setting AssemblyFileVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to '{NameOfDefaultAssemblyFileVersioningScheme}'.")] [JsonPropertyDefault(DefaultAssemblyFileVersioningScheme)] - public AssemblyFileVersioningScheme? AssemblyFileVersioningScheme { get; internal init; } + public AssemblyFileVersioningScheme? AssemblyFileVersioningScheme { get; set; } [JsonPropertyName("assembly-informational-format")] [JsonPropertyDescription($"Specifies the format of AssemblyInformationalVersion. Defaults to '{DefaultAssemblyInformationalFormat}'.")] [JsonPropertyDefault($"'{DefaultAssemblyInformationalFormat}'")] - public string? AssemblyInformationalFormat { get; internal init; } + public string? AssemblyInformationalFormat { get; set; } [JsonPropertyName("assembly-versioning-format")] [JsonPropertyDescription("Specifies the format of AssemblyVersion and overwrites the value of assembly-versioning-scheme.")] - public string? AssemblyVersioningFormat { get; internal init; } + public string? AssemblyVersioningFormat { get; set; } [JsonPropertyName("assembly-file-versioning-format")] [JsonPropertyDescription("Specifies the format of AssemblyFileVersion and overwrites the value of assembly-file-versioning-scheme.")] - public string? AssemblyFileVersioningFormat { get; internal init; } + public string? AssemblyFileVersioningFormat { get; set; } [JsonPropertyName("tag-prefix")] [JsonPropertyDescription($"A regular expression which is used to trim Git tags before processing. Defaults to '{RegexPatterns.Configuration.DefaultTagPrefixRegexPattern}'")] [JsonPropertyDefault(RegexPatterns.Configuration.DefaultTagPrefixRegexPattern)] [JsonPropertyFormat(Format.Regex)] - public string? TagPrefixPattern { get; internal init; } + public string? TagPrefixPattern { get; set; } [JsonPropertyName("version-in-branch-pattern")] [JsonPropertyDescription($"A regular expression which is used to determine the version number in the branch name or commit message (e.g., v1.0.0-LTS). Defaults to '{RegexPatterns.Configuration.DefaultVersionInBranchRegexPattern}'.")] [JsonPropertyDefault(RegexPatterns.Configuration.DefaultVersionInBranchRegexPattern)] [JsonPropertyFormat(Format.Regex)] - public string? VersionInBranchPattern { get; internal init; } + public string? VersionInBranchPattern { get; set; } [JsonPropertyName("next-version")] [JsonPropertyDescription("Allows you to bump the next version explicitly. Useful for bumping main or a feature branch with breaking changes")] public string? NextVersion { get => nextVersion; - internal init => + set => nextVersion = int.TryParse(value, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out var major) ? $"{major}.0" : value; @@ -63,39 +63,39 @@ public string? NextVersion [JsonPropertyDescription($"The regular expression to match commit messages with to perform a major version increment. Defaults to '{RegexPatterns.VersionCalculation.DefaultMajorRegexPattern}'")] [JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultMajorRegexPattern)] [JsonPropertyFormat(Format.Regex)] - public string? MajorVersionBumpMessage { get; internal init; } + public string? MajorVersionBumpMessage { get; set; } [JsonPropertyName("minor-version-bump-message")] [JsonPropertyDescription($"The regular expression to match commit messages with to perform a minor version increment. Defaults to '{RegexPatterns.VersionCalculation.DefaultMinorRegexPattern}'")] [JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultMinorRegexPattern)] [JsonPropertyFormat(Format.Regex)] - public string? MinorVersionBumpMessage { get; internal init; } + public string? MinorVersionBumpMessage { get; set; } [JsonPropertyName("patch-version-bump-message")] [JsonPropertyDescription($"The regular expression to match commit messages with to perform a patch version increment. Defaults to '{RegexPatterns.VersionCalculation.DefaultPatchRegexPattern}'")] [JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultPatchRegexPattern)] [JsonPropertyFormat(Format.Regex)] - public string? PatchVersionBumpMessage { get; internal init; } + public string? PatchVersionBumpMessage { get; set; } [JsonPropertyName("no-bump-message")] [JsonPropertyDescription($"Used to tell GitVersion not to increment when in Mainline development mode. Defaults to '{RegexPatterns.VersionCalculation.DefaultNoBumpRegexPattern}'")] [JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultNoBumpRegexPattern)] [JsonPropertyFormat(Format.Regex)] - public string? NoBumpMessage { get; internal init; } + public string? NoBumpMessage { get; set; } [JsonPropertyName("tag-pre-release-weight")] [JsonPropertyDescription($"The pre-release weight in case of tagged commits. Defaults to {StringDefaultTagPreReleaseWeight}.")] - public int? TagPreReleaseWeight { get; internal init; } + public int? TagPreReleaseWeight { get; set; } [JsonPropertyName("commit-date-format")] [JsonPropertyDescription($"The format to use when calculating the commit date. Defaults to '{DefaultCommitDateFormat}'. See [Standard Date and Time Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings).")] [JsonPropertyDefault(DefaultCommitDateFormat)] [System.Diagnostics.CodeAnalysis.StringSyntax("DateTimeFormat")] - public string? CommitDateFormat { get; internal init; } + public string? CommitDateFormat { get; set; } [JsonPropertyName("merge-message-formats")] [JsonPropertyDescription("Custom merge message formats to enable identification of merge messages that do not follow the built-in conventions.")] - public Dictionary MergeMessageFormats { get; internal init; } = []; + public Dictionary MergeMessageFormats { get; set; } = []; [JsonIgnore] IReadOnlyDictionary IGitVersionConfiguration.MergeMessageFormats => MergeMessageFormats; @@ -103,12 +103,12 @@ public string? NextVersion [JsonPropertyName("update-build-number")] [JsonPropertyDescription($"Whether to update the build number in the project file. Defaults to {StringDefaultUpdateBuildNumber}.")] [JsonPropertyDefault(DefaultUpdateBuildNumber)] - public bool UpdateBuildNumber { get; internal init; } = DefaultUpdateBuildNumber; + public bool UpdateBuildNumber { get; set; } = DefaultUpdateBuildNumber; [JsonPropertyName("semantic-version-format")] [JsonPropertyDescription($"Specifies the semantic version format that is used when parsing the string. Can be 'Strict' or 'Loose'. Defaults to '{StringDefaultSemanticVersionFormat}'.")] [JsonPropertyDefault(DefaultSemanticVersionFormat)] - public SemanticVersionFormat SemanticVersionFormat { get; internal init; } + public SemanticVersionFormat SemanticVersionFormat { get; set; } [JsonIgnore] VersionStrategies IGitVersionConfiguration.VersionStrategy => VersionStrategies.Length == 0 @@ -116,7 +116,7 @@ public string? NextVersion [JsonPropertyName("strategies")] [JsonPropertyDescription($"Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: '{nameof(VersionCalculation.VersionStrategies.ConfiguredNextVersion)}', '{nameof(VersionCalculation.VersionStrategies.MergeMessage)}', '{nameof(VersionCalculation.VersionStrategies.TaggedCommit)}', '{nameof(VersionCalculation.VersionStrategies.TrackReleaseBranches)}', '{nameof(VersionCalculation.VersionStrategies.VersionInBranchName)}' and '{nameof(VersionCalculation.VersionStrategies.Mainline)}'.")] - public VersionStrategies[] VersionStrategies { get; internal init; } = []; + public VersionStrategies[] VersionStrategies { get; set; } = []; [JsonIgnore] IReadOnlyDictionary IGitVersionConfiguration.Branches @@ -124,14 +124,14 @@ IReadOnlyDictionary IGitVersionConfiguration.Branc [JsonPropertyName("branches")] [JsonPropertyDescription("The header for all the individual branch configuration.")] - public Dictionary Branches { get; internal init; } = []; + public Dictionary Branches { get; set; } = []; [JsonIgnore] IIgnoreConfiguration IGitVersionConfiguration.Ignore => Ignore; [JsonPropertyName("ignore")] [JsonPropertyDescription("The header property for the ignore configuration.")] - public IgnoreConfiguration Ignore { get; internal init; } = new(); + public IgnoreConfiguration Ignore { get; set; } = new(); public override IBranchConfiguration Inherit(IBranchConfiguration configuration) => throw new NotSupportedException(); diff --git a/src/GitVersion.Configuration/IgnoreConfiguration.cs b/src/GitVersion.Configuration/IgnoreConfiguration.cs index 822588b3ee..a145a22ad6 100644 --- a/src/GitVersion.Configuration/IgnoreConfiguration.cs +++ b/src/GitVersion.Configuration/IgnoreConfiguration.cs @@ -6,7 +6,7 @@ namespace GitVersion.Configuration; internal record IgnoreConfiguration : IIgnoreConfiguration { [JsonIgnore] - public DateTimeOffset? Before { get; init; } + public DateTimeOffset? Before { get; set; } [JsonPropertyName("commits-before")] [JsonPropertyDescription("Commits before this date will be ignored. Format: yyyy-MM-ddTHH:mm:ss.")] @@ -14,7 +14,7 @@ internal record IgnoreConfiguration : IIgnoreConfiguration public string? BeforeString { get => Before?.ToString("yyyy-MM-ddTHH:mm:ssZ"); - init => Before = value is null ? null : DateTimeOffset.Parse(value, CultureInfo.InvariantCulture); + set => Before = value is null ? null : DateTimeOffset.Parse(value, CultureInfo.InvariantCulture); } [JsonIgnore] @@ -22,13 +22,13 @@ public string? BeforeString [JsonPropertyName("sha")] [JsonPropertyDescription("A sequence of SHAs to be excluded from the version calculations.")] - public HashSet Shas { get; init; } = []; + public HashSet Shas { get; set; } = []; IReadOnlySet IIgnoreConfiguration.Paths => Paths; [JsonPropertyName("paths")] [JsonPropertyDescription("A sequence of file paths to be excluded from the version calculations.")] - public HashSet Paths { get; init; } = []; + public HashSet Paths { get; set; } = []; [JsonIgnore] public bool IsEmpty => Before == null && Shas.Count == 0 && Paths.Count == 0; diff --git a/src/GitVersion.Configuration/PreventIncrementConfiguration.cs b/src/GitVersion.Configuration/PreventIncrementConfiguration.cs index 757647293b..37661d9762 100644 --- a/src/GitVersion.Configuration/PreventIncrementConfiguration.cs +++ b/src/GitVersion.Configuration/PreventIncrementConfiguration.cs @@ -6,13 +6,13 @@ internal class PreventIncrementConfiguration : IPreventIncrementConfiguration { [JsonPropertyName("of-merged-branch")] [JsonPropertyDescription("Prevent increment when branch merged.")] - public bool? OfMergedBranch { get; internal init; } + public bool? OfMergedBranch { get; set; } [JsonPropertyName("when-branch-merged")] [JsonPropertyDescription("Prevent increment when branch merged.")] - public bool? WhenBranchMerged { get; internal init; } + public bool? WhenBranchMerged { get; set; } [JsonPropertyName("when-current-commit-tagged")] [JsonPropertyDescription("This branch related property controls the behavior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true.")] - public bool? WhenCurrentCommitTagged { get; internal init; } + public bool? WhenCurrentCommitTagged { get; set; } } diff --git a/src/GitVersion.Configuration/VersionStrategiesConverter.cs b/src/GitVersion.Configuration/VersionStrategiesConverter.cs index 9f82f82c70..0f80eb1631 100644 --- a/src/GitVersion.Configuration/VersionStrategiesConverter.cs +++ b/src/GitVersion.Configuration/VersionStrategiesConverter.cs @@ -1,54 +1,103 @@ using GitVersion.VersionCalculation; -using YamlDotNet.Core; -using YamlDotNet.Core.Events; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; +using SharpYaml; +using SharpYaml.Serialization; namespace GitVersion.Configuration; -internal class VersionStrategiesConverter : IYamlTypeConverter +internal sealed class VersionStrategiesConverter : YamlConverter { - public static readonly IYamlTypeConverter Instance = new VersionStrategiesConverter(); + public static YamlConverter Instance { get; } = new VersionStrategiesConverter(); - public bool Accepts(Type type) => type == typeof(VersionStrategies[]); + private static readonly IReadOnlyDictionary NormalizedStrategies = + Enum.GetValues() + .ToDictionary(value => Normalize(value.ToString()), value => value, StringComparer.Ordinal); - public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) + public override VersionStrategies[] Read(YamlReader reader) { List strategies = []; - if (parser.TryConsume(out _)) + if (reader.TokenType == YamlTokenType.StartSequence) { - while (!parser.TryConsume(out _)) + reader.Read(); + while (reader.TokenType != YamlTokenType.EndSequence) { - var data = parser.Consume().Value; + if (reader.TokenType != YamlTokenType.Scalar) + { + throw new YamlException(reader.SourceName, reader.Start, reader.End, "Expected a scalar value while reading version strategies."); + } - var strategy = Enum.Parse(data); - strategies.Add(strategy); + strategies.Add(ParseStrategy(reader.GetScalarValue())); + reader.Read(); } + + reader.Read(); + return [.. strategies]; + } + + if (reader.TokenType != YamlTokenType.Scalar) + { + throw new YamlException(reader.SourceName, reader.Start, reader.End, "Expected a scalar or sequence while reading version strategies."); + } + + var scalar = reader.GetScalarValue(); + reader.Read(); + + foreach (var item in SplitScalarList(scalar)) + { + strategies.Add(ParseStrategy(item)); + } + + return [.. strategies]; + } + + public override void Write(YamlWriter writer, VersionStrategies[]? value) + { + if (value is null) + { + writer.WriteNullValue(); + return; } - else + + writer.WriteStartSequence(); + foreach (var strategy in value) { - var data = parser.Consume().Value; + writer.WriteString(strategy.ToString()); + } + writer.WriteEndSequence(); + } - var deserializer = new DeserializerBuilder() - .WithNamingConvention(UnderscoredNamingConvention.Instance) - .Build(); + private static IEnumerable SplitScalarList(string scalar) + { + var trimmed = scalar.Trim(); + if (trimmed.Length == 0) yield break; - strategies = deserializer.Deserialize>(data); + if (trimmed.StartsWith('[') && trimmed.EndsWith(']')) + { + trimmed = trimmed[1..^1]; } - return strategies.ToArray(); + foreach (var item in trimmed.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)) + { + yield return item; + } } - public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) + private static VersionStrategies ParseStrategy(string value) { - var strategies = (VersionStrategies[])value!; + if (Enum.TryParse(value, ignoreCase: false, out var exactMatch)) + { + return exactMatch; + } - var s = new SerializerBuilder() - .JsonCompatible() - .Build(); - var data = s.Serialize(strategies); + var normalizedValue = Normalize(value); + if (NormalizedStrategies.TryGetValue(normalizedValue, out var normalizedMatch)) + { + return normalizedMatch; + } - emitter.Emit(new Scalar(data)); + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown version strategy value."); } + + private static string Normalize(string value) + => new(value.Where(char.IsLetterOrDigit).Select(char.ToUpperInvariant).ToArray()); }