diff --git a/README.md b/README.md index 9185849..f2d97cd 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ You can configure the action with various inputs, a list of which has been provi | tool-version | The version of the tool to run | latest | | release-branch | The name of the master/main branch | master | | dev-branch | The name of the development branch | dev | +| skip-prerelease | Skip prerelease part of the version. When true, release-branch and dev-branch are effectively ignored | false | | minor-identifier | The string used to identify a minor release (wrap with '/' to match using a regular expression) | feature: | | major-identifier | The string used to identify a major release (wrap with '/' to match using a regular expression) | breaking: | | prefix | The prefix used for the version name | | diff --git a/action.yml b/action.yml index 4080496..61700ef 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,10 @@ inputs: description: 'The name of the dev branch' required: true default: dev + skip-prerelease: + description: "Skip prerelease part of the version. When true, release-branch and dev-branch are effectively ignored" + required: true + default: "false" minor-identifier: description: 'The string or regex to identify a minor release commit' required: true @@ -61,6 +65,7 @@ runs: --previous-version \ --release-branch "${{ inputs.release-branch }}" \ --dev-branch "${{ inputs.dev-branch }}" \ + ${{ inputs.skip-prerelease == 'true' && '--skip-prerelease' || '' }} \ --minor-identifier="${{ inputs.minor-identifier }}" \ --major-identifier="${{ inputs.major-identifier }}" \ --version-prefix "${{ inputs.prefix }}") @@ -75,6 +80,8 @@ runs: export VERSION=$(git-version \ --release-branch "${{ inputs.release-branch }}" \ --dev-branch "${{ inputs.dev-branch }}" \ + ${{ inputs.skip-prerelease == 'true' && '--skip-prerelease' || '' }} \ + --skip-prerelease "${{ inputs.skip-prerelease }}" \ --minor-identifier="${{ inputs.minor-identifier }}" \ --major-identifier="${{ inputs.major-identifier }}" \ --version-prefix "${{ inputs.prefix }}") diff --git a/spec/git-version-spec.cr b/spec/git-version-spec.cr index 3ec3e7f..5eb8df3 100644 --- a/spec/git-version-spec.cr +++ b/spec/git-version-spec.cr @@ -71,6 +71,28 @@ describe GitVersion do end end + it "should skip prerelease component in the version number when configured" do + tmp = InTmp.new + + begin + tmp.exec %(git init) + tmp.exec %(git checkout -b master) + tmp.exec %(git commit --no-gpg-sign --allow-empty -m "1") + tmp.exec %(git tag "1.0.0") + + tmp.exec %(git checkout -b my-fancy.branch) + tmp.exec %(git commit --no-gpg-sign --allow-empty -m "2") + + git = GitVersion::Git.new("dev", "master", "feature:", "breaking:", tmp.@tmpdir, "", "", true) + + version = git.get_new_version + + version.should eq("1.0.1") + ensure + tmp.cleanup + end + end + it "should properly bump the version" do tmp = InTmp.new diff --git a/src/git-version.cr b/src/git-version.cr index d49959b..7401d53 100644 --- a/src/git-version.cr +++ b/src/git-version.cr @@ -12,7 +12,8 @@ module GitVersion class Git def initialize(@dev_branch : String, @release_branch : String, @minor_identifier : String, @major_identifier : String, - @folder = FileUtils.pwd, @prefix : String = "", @log_paths : String = "") + @folder = FileUtils.pwd, @prefix : String = "", @log_paths : String = "", + @skip_prerelease : Bool = false) @major_id_is_regex = false @minor_id_is_regex = false if match = /\/(.*)\//.match(@major_identifier) @@ -187,31 +188,33 @@ module GitVersion end end - cb = current_branch_or_tag + if !@skip_prerelease + cb = current_branch_or_tag - if cb == @release_branch - # - elsif cb == @dev_branch - prerelease = [DEV_BRANCH_SUFFIX, commits_distance(previous_tag), current_commit_hash()] of String | Int32 - previous_version = - SemanticVersion.new( - previous_version.major, - previous_version.minor, - previous_version.patch, - SemanticVersion::Prerelease.new(prerelease), - nil - ) - else - branch_sanitized_name = cb.downcase.gsub(/[^a-zA-Z0-9]/, "")[0,30] - prerelease = [branch_sanitized_name, commits_distance(previous_tag), current_commit_hash()] of String | Int32 - previous_version = - SemanticVersion.new( - previous_version.major, - previous_version.minor, - previous_version.patch, - SemanticVersion::Prerelease.new(prerelease), - nil - ) + if cb == @release_branch + # + elsif cb == @dev_branch + prerelease = [DEV_BRANCH_SUFFIX, commits_distance(previous_tag), current_commit_hash()] of String | Int32 + previous_version = + SemanticVersion.new( + previous_version.major, + previous_version.minor, + previous_version.patch, + SemanticVersion::Prerelease.new(prerelease), + nil + ) + else + branch_sanitized_name = cb.downcase.gsub(/[^a-zA-Z0-9]/, "")[0,30] + prerelease = [branch_sanitized_name, commits_distance(previous_tag), current_commit_hash()] of String | Int32 + previous_version = + SemanticVersion.new( + previous_version.major, + previous_version.minor, + previous_version.patch, + SemanticVersion::Prerelease.new(prerelease), + nil + ) + end end return add_prefix(previous_version.to_s) diff --git a/src/main.cr b/src/main.cr index 6de97d0..3631d01 100644 --- a/src/main.cr +++ b/src/main.cr @@ -7,6 +7,7 @@ require "./git-version" previous_version = false dev_branch = "dev" release_branch = "master" +skip_prerelease = false minor_identifier = "feature:" major_identifier = "breaking:" prefix = "" @@ -19,6 +20,7 @@ OptionParser.parse do |parser| parser.on("-f FOLDER", "--folder=FOLDER", "Execute the command in the defined folder") { |f| folder = f } parser.on("-b BRANCH", "--dev-branch=BRANCH", "Specifies the development branch") { |branch| dev_branch = branch } parser.on("-r BRANCH", "--release-branch=BRANCH", "Specifies the release branch") { |branch| release_branch = branch } + parser.on("--skip-prerelease", "Skip the prerelase part of the version") { skip_prerelease=true } parser.on("--minor-identifier=IDENTIFIER", "Specifies the string or regex to identify a minor release commit with") { |identifier| minor_identifier = identifier } parser.on("--major-identifier=IDENTIFIER", @@ -34,7 +36,7 @@ OptionParser.parse do |parser| end end -git = GitVersion::Git.new(dev_branch, release_branch, minor_identifier, major_identifier, folder, prefix, log_paths) +git = GitVersion::Git.new(dev_branch, release_branch, minor_identifier, major_identifier, folder, prefix, log_paths, skip_prerelease) if previous_version puts "#{git.get_previous_version}"