Skip to content

Commit 564267a

Browse files
authored
Correctly use semverify to increment pre-release versions (#46)
1 parent d22573d commit 564267a

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ git push "${REMOTE}" --delete "${RELEASE_TAG}"
345345

346346
# Delete the local branch and tag
347347
git branch -D "${RELEASE_BRANCH}"
348-
git tag -D "${RELEASE_TAG}"
348+
git tag -d "${RELEASE_TAG}"
349349
```
350350

351351
### How is the changelog updated?

lib/create_github_release/tasks/update_version.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def run
4343
# @return [void]
4444
# @api private
4545
def increment_version
46-
`semverify next-#{project.release_type}`
46+
command = "semverify next-#{project.release_type}"
47+
command += ' --pre' if project.pre
48+
command += " --pre-type=#{project.pre_type}" if project.pre_type
49+
`#{command}`
4750
error 'Could not increment version' unless $CHILD_STATUS.success?
4851
end
4952

spec/create_github_release/tasks/update_version_spec.rb

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
RSpec.describe CreateGithubRelease::Tasks::UpdateVersion do
44
let(:release_type) { 'major' }
5+
let(:pre) { false }
6+
let(:pre_type) { nil }
57
let(:task) { described_class.new(project) }
68
let(:project) { CreateGithubRelease::Project.new(options) }
7-
let(:options) { CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = release_type } }
9+
let(:options) do
10+
CreateGithubRelease::CommandLine::Options.new do |o|
11+
o.release_type = release_type
12+
o.pre = pre
13+
o.pre_type = pre_type
14+
end
15+
end
816

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

@@ -29,6 +37,68 @@
2937
end
3038
end
3139

40+
context 'when this is a pre-release when default pre-release type' do
41+
let(:pre) { true }
42+
43+
let(:mocked_commands) do
44+
[
45+
MockedCommand.new('semverify next-major --pre', exitstatus: semverify_exitstatus),
46+
MockedCommand.new('semverify file', stdout: "#{version_file}\n", exitstatus: semverify_file_exitstatus),
47+
MockedCommand.new("git add \"#{version_file}\"", exitstatus: git_exitstatus)
48+
]
49+
end
50+
51+
let(:semverify_exitstatus) { 0 }
52+
let(:semverify_file_exitstatus) { 0 }
53+
let(:git_exitstatus) { 0 }
54+
55+
it 'should increment the version with the --pre flag' do
56+
expect { subject }.not_to raise_error
57+
end
58+
end
59+
60+
context 'when this is an alpha pre-release' do
61+
let(:pre) { true }
62+
let(:pre_type) { 'alpha' }
63+
64+
let(:mocked_commands) do
65+
[
66+
MockedCommand.new('semverify next-major --pre --pre-type=alpha', exitstatus: semverify_exitstatus),
67+
MockedCommand.new('semverify file', stdout: "#{version_file}\n", exitstatus: semverify_file_exitstatus),
68+
MockedCommand.new("git add \"#{version_file}\"", exitstatus: git_exitstatus)
69+
]
70+
end
71+
72+
let(:semverify_exitstatus) { 0 }
73+
let(:semverify_file_exitstatus) { 0 }
74+
let(:git_exitstatus) { 0 }
75+
76+
it 'should increment the version with the --pre and --pre-type=alpha args' do
77+
expect { subject }.not_to raise_error
78+
end
79+
end
80+
81+
context 'when changing the pre-release type to beta' do
82+
let(:release_type) { 'pre' }
83+
let(:pre_type) { 'beta' }
84+
85+
let(:mocked_commands) do
86+
[
87+
MockedCommand.new('semverify next-pre --pre-type=beta', exitstatus: semverify_exitstatus),
88+
MockedCommand.new('semverify file', stdout: "#{version_file}\n", exitstatus: semverify_file_exitstatus),
89+
MockedCommand.new("git add \"#{version_file}\"", exitstatus: git_exitstatus)
90+
]
91+
end
92+
93+
let(:semverify_exitstatus) { 0 }
94+
let(:semverify_file_exitstatus) { 0 }
95+
let(:git_exitstatus) { 0 }
96+
97+
it 'should increment the version with the pre release type and --pre-type=alpha arg' do
98+
expect { subject }.not_to raise_error
99+
end
100+
end
101+
32102
context 'when this is NOT the first release' do
33103
let(:mocked_commands) do
34104
[

0 commit comments

Comments
 (0)