Skip to content

Commit

Permalink
Correctly use semverify to increment pre-release versions (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouball committed Jan 7, 2024
1 parent d22573d commit 564267a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ git push "${REMOTE}" --delete "${RELEASE_TAG}"

# Delete the local branch and tag
git branch -D "${RELEASE_BRANCH}"
git tag -D "${RELEASE_TAG}"
git tag -d "${RELEASE_TAG}"
```

### How is the changelog updated?
Expand Down
5 changes: 4 additions & 1 deletion lib/create_github_release/tasks/update_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def run
# @return [void]
# @api private
def increment_version
`semverify next-#{project.release_type}`
command = "semverify next-#{project.release_type}"
command += ' --pre' if project.pre
command += " --pre-type=#{project.pre_type}" if project.pre_type
`#{command}`
error 'Could not increment version' unless $CHILD_STATUS.success?
end

Expand Down
72 changes: 71 additions & 1 deletion spec/create_github_release/tasks/update_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

RSpec.describe CreateGithubRelease::Tasks::UpdateVersion do
let(:release_type) { 'major' }
let(:pre) { false }
let(:pre_type) { nil }
let(:task) { described_class.new(project) }
let(:project) { CreateGithubRelease::Project.new(options) }
let(:options) { CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = release_type } }
let(:options) do
CreateGithubRelease::CommandLine::Options.new do |o|
o.release_type = release_type
o.pre = pre
o.pre_type = pre_type
end
end

let(:version_file) { 'lib/my_gem/version.rb' }

Expand All @@ -29,6 +37,68 @@
end
end

context 'when this is a pre-release when default pre-release type' do
let(:pre) { true }

let(:mocked_commands) do
[
MockedCommand.new('semverify next-major --pre', exitstatus: semverify_exitstatus),
MockedCommand.new('semverify file', stdout: "#{version_file}\n", exitstatus: semverify_file_exitstatus),
MockedCommand.new("git add \"#{version_file}\"", exitstatus: git_exitstatus)
]
end

let(:semverify_exitstatus) { 0 }
let(:semverify_file_exitstatus) { 0 }
let(:git_exitstatus) { 0 }

it 'should increment the version with the --pre flag' do
expect { subject }.not_to raise_error
end
end

context 'when this is an alpha pre-release' do
let(:pre) { true }
let(:pre_type) { 'alpha' }

let(:mocked_commands) do
[
MockedCommand.new('semverify next-major --pre --pre-type=alpha', exitstatus: semverify_exitstatus),
MockedCommand.new('semverify file', stdout: "#{version_file}\n", exitstatus: semverify_file_exitstatus),
MockedCommand.new("git add \"#{version_file}\"", exitstatus: git_exitstatus)
]
end

let(:semverify_exitstatus) { 0 }
let(:semverify_file_exitstatus) { 0 }
let(:git_exitstatus) { 0 }

it 'should increment the version with the --pre and --pre-type=alpha args' do
expect { subject }.not_to raise_error
end
end

context 'when changing the pre-release type to beta' do
let(:release_type) { 'pre' }
let(:pre_type) { 'beta' }

let(:mocked_commands) do
[
MockedCommand.new('semverify next-pre --pre-type=beta', exitstatus: semverify_exitstatus),
MockedCommand.new('semverify file', stdout: "#{version_file}\n", exitstatus: semverify_file_exitstatus),
MockedCommand.new("git add \"#{version_file}\"", exitstatus: git_exitstatus)
]
end

let(:semverify_exitstatus) { 0 }
let(:semverify_file_exitstatus) { 0 }
let(:git_exitstatus) { 0 }

it 'should increment the version with the pre release type and --pre-type=alpha arg' do
expect { subject }.not_to raise_error
end
end

context 'when this is NOT the first release' do
let(:mocked_commands) do
[
Expand Down

0 comments on commit 564267a

Please sign in to comment.