sem_ver_components 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sem_ver_git +1 -1
- data/lib/sem_ver_components/git_hostings/bitbucket.rb +21 -2
- data/lib/sem_ver_components/local_git.rb +8 -0
- data/lib/sem_ver_components/outputs/info.rb +14 -2
- data/lib/sem_ver_components/outputs/semantic_release_generate_notes.rb +14 -30
- data/lib/sem_ver_components/semver.rb +66 -0
- data/lib/sem_ver_components/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd9072dcf7ef8166885ae3f8cf08c3d50cf5b99e557f9c22b51c9523ddb263a
|
4
|
+
data.tar.gz: 66036176a6028833f51c4f5f5118f4d68c934106c8e90dc08f478ae4a57e78d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '049f38d9969d07d80af92c82ec6a70f9e9de84ac1df68e549c72962ce0d63958d182ebb8ae9b966e9371511d2d76fc7539ebb0c62e7f6b0d0d9e2df2a93ee13f'
|
7
|
+
data.tar.gz: 355307ad5bee9481fdc7d7b29c0dad165c5d573ae805a77d2241a1826ee6b6ef35bcf4013b652d56f57b761fe67b00a24e1d2945f8c76d7e7b4354cba7a069da
|
data/bin/sem_ver_git
CHANGED
@@ -17,7 +17,7 @@ git_hosting_plugins = SemVerComponents::Plugins.new(:git_hostings)
|
|
17
17
|
OptionParser.new do |opts|
|
18
18
|
opts.banner = "Usage: #{File.basename($0)} [options]"
|
19
19
|
opts.on('-f', '--from GIT_REF', 'Git reference from which commits are to be analyzed (defaults to first commit)') do |git_ref|
|
20
|
-
git_from = git_ref
|
20
|
+
git_from = git_ref.empty? ? nil : git_ref
|
21
21
|
end
|
22
22
|
opts.on('-g', '--git_hosting GIT_HOSTING', "Specify which kind of git hosting is used. Used to format URLs to commits and comparisons. Possible values are #{git_hosting_plugins.list.sort.join(', ')}. (defaults to #{git_hosting})") do |git_hosting_str|
|
23
23
|
git_hosting = git_hosting_str.to_sym
|
@@ -10,7 +10,7 @@ module SemVerComponents
|
|
10
10
|
# * *git_url* (String): The git URL
|
11
11
|
# * *commit_sha* (String): The commit sha
|
12
12
|
def commit_url(git_url, commit_sha)
|
13
|
-
"#{git_url}/commits/#{commit_sha}"
|
13
|
+
"#{public_url(git_url)}/commits/#{commit_sha}"
|
14
14
|
end
|
15
15
|
|
16
16
|
# Get the URL to compare 2 tags
|
@@ -20,7 +20,26 @@ module SemVerComponents
|
|
20
20
|
# * *tag_1* (String): The first tag
|
21
21
|
# * *tag_2* (String): The second tag
|
22
22
|
def compare_url(git_url, tag_1, tag_2)
|
23
|
-
"#{git_url}/compare/commits?targetBranch=refs%2Ftags%2F#{
|
23
|
+
"#{public_url(git_url)}/compare/commits?targetBranch=refs%2Ftags%2F#{tag_1}&sourceBranch=refs%2Ftags%2F#{tag_2}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Convert the git remote URL to the public URL
|
29
|
+
#
|
30
|
+
# Parameters::
|
31
|
+
# * *git_url* (String): Git remote URL
|
32
|
+
# Result::
|
33
|
+
# * String: The corresponding public URL
|
34
|
+
def public_url(git_url)
|
35
|
+
if git_url =~ /^(.+)\/scm\/([^\/]+)\/(.+)$/
|
36
|
+
base_url = $1
|
37
|
+
project = $2
|
38
|
+
repo = $3
|
39
|
+
"#{base_url}/projects/#{project}/repos/#{repo}"
|
40
|
+
else
|
41
|
+
git_url
|
42
|
+
end
|
24
43
|
end
|
25
44
|
|
26
45
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'sem_ver_components/semver'
|
2
|
+
|
1
3
|
module SemVerComponents
|
2
4
|
|
3
5
|
module Outputs
|
@@ -12,11 +14,12 @@ module SemVerComponents
|
|
12
14
|
# * *commit* (Git::Object::Commit): Corresponding git commit
|
13
15
|
def process(commits_info)
|
14
16
|
# Display bump levels per component
|
15
|
-
commits_info.inject({}) do |components_bump_levels, commit_info|
|
17
|
+
bumps_per_component = commits_info.inject({}) do |components_bump_levels, commit_info|
|
16
18
|
components_bump_levels.merge(commit_info[:components_bump_levels]) do |_component, bump_level_1, bump_level_2|
|
17
19
|
[bump_level_1, bump_level_2].max
|
18
20
|
end
|
19
|
-
end
|
21
|
+
end
|
22
|
+
bumps_per_component.each do |component, bump_level|
|
20
23
|
puts "#{component.nil? ? 'Global' : component}: Bump #{
|
21
24
|
case bump_level
|
22
25
|
when 0
|
@@ -30,6 +33,15 @@ module SemVerComponents
|
|
30
33
|
end
|
31
34
|
} version"
|
32
35
|
end
|
36
|
+
# Compute new version
|
37
|
+
global_bump_level = bumps_per_component.values.max
|
38
|
+
if global_bump_level.nil?
|
39
|
+
puts 'No next version'
|
40
|
+
else
|
41
|
+
puts "Next global version#{@local_git.on_release_branch? ? '' : ' (not on release branch)'}: #{
|
42
|
+
Semver.next_version_from(Semver.version_from_git_ref(@local_git.git_from), global_bump_level, pre_release: !@local_git.on_release_branch?)
|
43
|
+
}"
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'time'
|
2
|
+
require 'sem_ver_components/semver'
|
2
3
|
|
3
4
|
module SemVerComponents
|
4
5
|
|
@@ -14,31 +15,10 @@ module SemVerComponents
|
|
14
15
|
# * *commit* (Git::Object::Commit): Corresponding git commit
|
15
16
|
def process(commits_info)
|
16
17
|
# Compute new version
|
17
|
-
new_version =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
major = Integer($1)
|
22
|
-
minor = Integer($2)
|
23
|
-
patch = Integer($3)
|
24
|
-
bump_level = commits_info.map { |commit_info| commit_info[:components_bump_levels].values }.flatten(1).max
|
25
|
-
case bump_level
|
26
|
-
when 0
|
27
|
-
patch += 1
|
28
|
-
when 1
|
29
|
-
minor += 1
|
30
|
-
patch = 0
|
31
|
-
when 2
|
32
|
-
major += 1
|
33
|
-
minor = 0
|
34
|
-
patch = 0
|
35
|
-
else
|
36
|
-
raise "Invalid bump level: #{bump_level}"
|
37
|
-
end
|
38
|
-
"#{major}.#{minor}.#{patch}"
|
39
|
-
else
|
40
|
-
raise "Can't generate release notes from a git ref that is not a semantic release (#{@local_git.git_from})"
|
41
|
-
end
|
18
|
+
new_version = Semver.next_version_from(
|
19
|
+
Semver.version_from_git_ref(@local_git.git_from),
|
20
|
+
commits_info.map { |commit_info| commit_info[:components_bump_levels].values }.flatten(1).max
|
21
|
+
)
|
42
22
|
git_url = @local_git.git.remote('origin').url
|
43
23
|
git_url = git_url[0..-5] if git_url.end_with?('.git')
|
44
24
|
# Reference merge commits: merged commits will not be part of the changelog, but their bump level will be taken into account when reporting the merge commit.
|
@@ -67,10 +47,14 @@ module SemVerComponents
|
|
67
47
|
# If we are dealing with a merge commit, consider the components' bump levels of the merged commits
|
68
48
|
if merge_commits.key?(git_commit_sha)
|
69
49
|
merge_commits[git_commit_sha].each do |merged_commit_sha|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
50
|
+
merged_commit_info = commits_info.find { |search_commit_info| search_commit_info[:commit].sha == merged_commit_sha }
|
51
|
+
# If the merged commit is not part of the list of commits, it means that the merge commit was not rebased on the previous release tag.
|
52
|
+
# In this case we can have some merged commits that are already part of the previous release.
|
53
|
+
# So we can ignore them.
|
54
|
+
unless merged_commit_info.nil?
|
55
|
+
components_bump_levels = components_bump_levels.merge(merged_commit_info[:components_bump_levels]) do |component, bump_level_1, bump_level_2|
|
56
|
+
[bump_level_1, bump_level_2].max
|
57
|
+
end
|
74
58
|
end
|
75
59
|
end
|
76
60
|
end
|
@@ -80,7 +64,7 @@ module SemVerComponents
|
|
80
64
|
commits_per_component[component][bump_level] << git_commit
|
81
65
|
end
|
82
66
|
end
|
83
|
-
puts "# [v#{new_version}](#{@git_hosting.compare_url(git_url, @local_git.git_from, new_version)}) (#{Time.now.utc.strftime('%F %T')})"
|
67
|
+
puts "# [v#{new_version}](#{@git_hosting.compare_url(git_url, @local_git.git_from, "v#{new_version}")}) (#{Time.now.utc.strftime('%F %T')})"
|
84
68
|
puts
|
85
69
|
commits_per_component.sort_by { |component, _component_info| component || '' }.each do |(component, component_info)|
|
86
70
|
puts "## #{component.nil? ? 'Global changes' : "Changes for #{component}"}\n" if commits_per_component.size > 1 || !component.nil?
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module SemVerComponents
|
2
|
+
|
3
|
+
# Helpers giving ways to adapt to semantic versioning conventions
|
4
|
+
module Semver
|
5
|
+
|
6
|
+
# Compute next version from an existing one and a bump level
|
7
|
+
#
|
8
|
+
# Parameters::
|
9
|
+
# * *version* (String): Existing version
|
10
|
+
# * *bump_level* (Integer): The bump level (0: patch, 1: minor, 2: major)
|
11
|
+
# * *pre_release* (Boolean): Should we get a pre-release version (adding a unique metadata)? [default: false]
|
12
|
+
# Result::
|
13
|
+
# * String: The next version
|
14
|
+
def self.next_version_from(version, bump_level, pre_release: false)
|
15
|
+
if version =~ /^(\d+)\.(\d+)\.(\d+)$/
|
16
|
+
major = Integer($1)
|
17
|
+
minor = Integer($2)
|
18
|
+
patch = Integer($3)
|
19
|
+
case bump_level
|
20
|
+
when 0
|
21
|
+
patch += 1
|
22
|
+
when 1
|
23
|
+
minor += 1
|
24
|
+
patch = 0
|
25
|
+
when 2
|
26
|
+
major += 1
|
27
|
+
minor = 0
|
28
|
+
patch = 0
|
29
|
+
else
|
30
|
+
raise "Invalid bump level: #{bump_level}"
|
31
|
+
end
|
32
|
+
"#{major}.#{minor}.#{patch}#{pre_release ? "-#{pre_release_metadata}" : ''}"
|
33
|
+
else
|
34
|
+
raise "Invalid version: #{version}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get a version from a git ref
|
39
|
+
#
|
40
|
+
# Parameters::
|
41
|
+
# * *git_ref* (String): The git ref
|
42
|
+
# Result::
|
43
|
+
# * String: Corresponding version
|
44
|
+
def self.version_from_git_ref(git_ref)
|
45
|
+
if git_ref.nil?
|
46
|
+
'0.0.0'
|
47
|
+
elsif git_ref =~ /^v(\d+\.\d+\.\d+)$/
|
48
|
+
$1
|
49
|
+
else
|
50
|
+
raise "Can't assume version from git ref: #{git_ref}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
# Get a pre-release metadata to be appended to a version
|
57
|
+
#
|
58
|
+
# Result::
|
59
|
+
# * String: The pre-release metadata
|
60
|
+
def self.pre_release_metadata
|
61
|
+
"#{`whoami`.strip}-#{Time.now.utc.strftime('%Y%m%d%H%M%S')}-SNAPSHOT"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sem_ver_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muriel Salvan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/sem_ver_components/outputs/semantic_release_analyze.rb
|
72
72
|
- lib/sem_ver_components/outputs/semantic_release_generate_notes.rb
|
73
73
|
- lib/sem_ver_components/plugins.rb
|
74
|
+
- lib/sem_ver_components/semver.rb
|
74
75
|
- lib/sem_ver_components/version.rb
|
75
76
|
homepage: https://github.com/Muriel-Salvan/sem_ver_components
|
76
77
|
licenses:
|