sem_ver_components 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 185deb09195baa6edae7e07fbd2bcc12950e68bdca1e7a2d8dac5701bc7ffeac
4
- data.tar.gz: 201606f2490c02ba2819582bf787c7f8264d577f6c7feeebc1ef9ddfbf41ce0e
3
+ metadata.gz: 387992ffe83f018c9096f517580fc810be55fce48f32ed519091d226aa480fed
4
+ data.tar.gz: 6b624945d92655aee943be4e1f380498b70e0fbb070917a1d1bd7eaacf00d353
5
5
  SHA512:
6
- metadata.gz: 9af95c9e8a9fb2377eafaa277cd730f4a11d698484b6794441b49d88e0022faf7aa77a89fe883a4f5489faafc822e1c522c539b3a4f2061c4d428c43a63ea5cb
7
- data.tar.gz: 373c35bad5e6a655c80fa0a7a2430203309380cf98a645ba99bcefb9bae9cad6fdb777e679dfcfcc0789755e6998c8ad2398d9ab3aca02ba660ff9aa7a9470dc
6
+ metadata.gz: a4d1bf087e0922fe5eaa3439497279d8562fd865527c65f915d61ffe0fe5abd594af4ba6290f085297028dbf903e3c3d428bbb3ef885393ccabad3690b7107f2
7
+ data.tar.gz: dc626df24fc0c635c86aeed396e4eeed80ef11840d65008846dd1c40568f0f6955385d93aa5c2b9cef767dca3b65793e3acd76022dd930dce2fdcdfbe6ea6f55
@@ -60,6 +60,14 @@ module SemVerComponents
60
60
  end
61
61
  end
62
62
 
63
+ # Is the git to ref part of a release branch?
64
+ #
65
+ # Result::
66
+ # * Boolean: Is the git to ref part of a release branch?
67
+ def on_release_branch?
68
+ @git_to == 'master'
69
+ end
70
+
63
71
  end
64
72
 
65
73
  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.each do |component, bump_level|
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
- if @local_git.git_from.nil?
19
- '0.0.1'
20
- elsif @local_git.git_from =~ /^v(\d+)\.(\d+)\.(\d+)$/
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.
@@ -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
@@ -1,5 +1,5 @@
1
1
  module SemVerComponents
2
2
 
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0'
4
4
 
5
5
  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.2.3
4
+ version: 0.3.0
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-01-19 00:00:00.000000000 Z
11
+ date: 2021-01-29 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: