Skip to content

Commit

Permalink
Merge pull request #235 from simplybusiness/fix-version-handling
Browse files Browse the repository at this point in the history
Fix version handling
  • Loading branch information
peaky76 authored Nov 14, 2024
2 parents 3b2ca25 + e6276ce commit ce3efe1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Bump
SEMVER = /["']*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?["']*/ # rubocop:disable Layout/LineLength
SEPARATOR = /\s*[:=]\s*/
VERSION_KEY = /(?:^|\.|\s|"|')(?:base|version)["']*/
VERSION_KEY = /(?:^|\.|\s|"|'|_*)(?:base|version)(?:_*["']*)/
VERSION_SETTING = Regexp.new(VERSION_KEY.source + SEPARATOR.source + SEMVER.source, Regexp::IGNORECASE).freeze

def initialize(config, level)
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/utils/bump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
allow(commit).to receive(:multiple_files)
end

describe 'VERSION_SETTING' do
it 'matches a lowercase, colon separated semver' do
version = 'version: 1.0.0'
expect(version.match(Bump::VERSION_SETTING)[0]).to eq(version)
end

it 'matches a lowercase, underscored, quote-marked, equal separated semver' do
version = '__version__ = "1.0.0"'
expect(version.match(Bump::VERSION_SETTING)[0]).to eq(version)
end
end

describe '#bump_everything' do
it 'bumps the version and commits the changes' do
allow(head_content).to receive(:content).and_return('version: 1.0.0')
Expand Down Expand Up @@ -86,5 +98,23 @@
)
bump.bump_everything
end

it 'handles python underscored version format' do
allow(head_content).to receive(:content).and_return('__version__ = "1.0.0"')
allow(base_content).to receive(:content).and_return('__version__ = "1.0.0"')

bump = Bump.new(config, 'patch')
expect(commit).to receive(:multiple_files).with(
[
{
path: other_version_file_paths[0], mode: '100644', type: 'blob',
content: '__version__ = "1.0.1"'
},
{ path: version_file_path, mode: '100644', type: 'blob', content: '__version__ = "1.0.1"' }
],
'Bump patch version'
)
bump.bump_everything
end
end
end

0 comments on commit ce3efe1

Please sign in to comment.