Skip to content

Commit 489d431

Browse files
committed
Anchor pre-release regex on end of string
This commit makes a small change to the regex for determining when to build a pre-release to anchor on the end of the string. This means that only full git tags, such as `9.0.0-beta1`, will be matched and not git describe output for releases between tags, like: `9.0.0-beta1-9-g347642bbe` Proper test coverage for version munging is also added. Signed-off-by: Charlie Sharpsteen <charlie@overlookinfratech.com>
1 parent ce43909 commit 489d431

2 files changed

Lines changed: 37 additions & 23 deletions

File tree

lib/vanagon/project/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def version_from_git
199199
# beta, or RC identifier. Substitute "-" for "~" so that dpkg and
200200
# rpm treat this as a pre-release and will upgrade packages to the
201201
# final version.
202-
when /\A\d+\.\d+\.\d+-(?:alpha|beta|rc)\d+/
202+
when /\A\d+\.\d+\.\d+-(?:alpha|beta|rc)\d+\z/
203203
version(git_version.sub('-', '~'))
204204
else
205205
version(git_version.split('-').reject(&:empty?).join('.'))

spec/lib/vanagon/project/dsl_spec.rb

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,58 @@
1313
end
1414

1515
describe '#version_from_git' do
16-
it 'sets the version based on the git describe' do
17-
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform)
18-
proj.instance_eval(project_block)
16+
let(:project) { Vanagon::Project::DSL.new('test-fixture', configdir, platform) }
17+
let(:repo) { double('repo') }
18+
subject { project._project }
19+
20+
before(:each) do
21+
project.instance_eval(project_block)
1922

20-
# Lying is bad. You shouldn't lie. But sometimes when you're
21-
# working with gross abstractions piled into the shape of
22-
# an indescribable cyclopean obelisk, you might have to lie
23-
# a little bit. Instead of trying to mock an entire Git instance,
24-
# we'll just instantiate a Double and allow it to receive calls
25-
# to .describe like it was a valid Git instance.
26-
repo = double("repo")
2723
expect(::Git)
2824
.to receive(:open)
2925
.and_return(repo)
26+
end
3027

28+
it 'sets the version based on the git describe' do
3129
allow(repo)
3230
.to receive(:describe)
3331
.and_return('1.2.3-1234')
3432

35-
proj.version_from_git
36-
expect(proj._project.version).to eq('1.2.3.1234')
33+
project.version_from_git
34+
35+
expect(subject.version).to eq('1.2.3.1234')
3736
end
37+
3838
it 'sets the version based on the git describe with multiple dashes' do
39-
proj = Vanagon::Project::DSL.new('test-fixture', configdir, platform)
40-
proj.instance_eval(project_block)
39+
expect(repo)
40+
.to receive(:describe)
41+
.and_return('1.2.3---1234')
4142

42-
# See previous description of "indescribable cyclopean obelisk"
43-
repo = double("repo")
44-
expect(::Git)
45-
.to receive(:open)
46-
.and_return(repo)
43+
project.version_from_git
44+
45+
expect(subject.version).to eq('1.2.3.1234')
46+
end
47+
48+
%w[alpha1 beta2 rc0].each do |pre_release|
49+
it "munges tagged #{pre_release} pre-release versions to include a tilde" do
50+
expect(repo)
51+
.to receive(:describe)
52+
.and_return("1.2.3-#{pre_release}")
4753

54+
project.version_from_git
55+
56+
expect(subject.version).to eq("1.2.3~#{pre_release}")
57+
end
58+
end
59+
60+
it "does not munge a tilde into un-tagged pre-release versions" do
4861
expect(repo)
4962
.to receive(:describe)
50-
.and_return('1.2.3---1234')
63+
.and_return("1.2.3-beta10-42-gabcdef123")
64+
65+
project.version_from_git
5166

52-
proj.version_from_git
53-
expect(proj._project.version).to eq('1.2.3.1234')
67+
expect(subject.version).to eq("1.2.3.beta10.42.gabcdef123")
5468
end
5569
end
5670

0 commit comments

Comments
 (0)