gfsm 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3daf635392e3b39f025cb94e1a4d73b6d28be9a763e2772b125926414197a81
4
- data.tar.gz: 417a58de2b92bdefd1328ea4ebd812dcc9d2576456e69ad5076eb8ec0eb9ae69
3
+ metadata.gz: 70aaff4098b16dd514bf52ca1ae4991702935d45dbc32d8049d3eb73f6268aab
4
+ data.tar.gz: e72643fcbcac5675f2ad65b0a2af8b9034c289fa923c1da1ce24fcb09629a2d5
5
5
  SHA512:
6
- metadata.gz: bb531a7d063939b9aa8da7b00ae64f9050c5da0000540e9b8284415006608ff33d7e528e1f02a2e5ab7150879c807272690fb1394e9f8e7da8e36596fa57af26
7
- data.tar.gz: 04da15d2f22e288c0caa21d52788807364762ff8ce88edcabe5677ff4c2c29ed3fbc56a553424d246560eec9ccd25704a1d9750e8244ada5c35e7d5f23fbc8c4
6
+ metadata.gz: 1aed0209eb39ccda368a53e7660d5a722e40753fddadfd046e10ecbdf5bd5695de4e54af07fc77c24945090ed978a6c400870b291579c59152854e6cdc6c4d1a
7
+ data.tar.gz: f2953fecd33c22b9cfafaff19ec94cd56b9c8d77fe7f26058979410dd3e30c8ce396330f8d6657d564682dcfe1448a04b0a3627e23b9950db5ab542575304a5c
data/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
data/.gitignore CHANGED
@@ -0,0 +1,113 @@
1
+ # Created by https://www.toptal.com/developers/gitignore/api/macos,visualstudiocode,ruby
2
+ # Edit at https://www.toptal.com/developers/gitignore?templates=macos,visualstudiocode,ruby
3
+
4
+ ### macOS ###
5
+ # General
6
+ .DS_Store
7
+ .AppleDouble
8
+ .LSOverride
9
+
10
+ # Icon must end with two \r
11
+ Icon
12
+
13
+
14
+ # Thumbnails
15
+ ._*
16
+
17
+ # Files that might appear in the root of a volume
18
+ .DocumentRevisions-V100
19
+ .fseventsd
20
+ .Spotlight-V100
21
+ .TemporaryItems
22
+ .Trashes
23
+ .VolumeIcon.icns
24
+ .com.apple.timemachine.donotpresent
25
+
26
+ # Directories potentially created on remote AFP share
27
+ .AppleDB
28
+ .AppleDesktop
29
+ Network Trash Folder
30
+ Temporary Items
31
+ .apdisk
32
+
33
+ ### macOS Patch ###
34
+ # iCloud generated files
35
+ *.icloud
36
+
37
+ ### Ruby ###
38
+ *.gem
39
+ *.rbc
40
+ /.config
41
+ /coverage/
42
+ /InstalledFiles
43
+ /pkg/
44
+ /spec/reports/
45
+ /spec/examples.txt
46
+ /test/tmp/
47
+ /test/version_tmp/
48
+ /tmp/
49
+
50
+ # Used by dotenv library to load environment variables.
51
+ # .env
52
+
53
+ # Ignore Byebug command history file.
54
+ .byebug_history
55
+
56
+ ## Specific to RubyMotion:
57
+ .dat*
58
+ .repl_history
59
+ build/
60
+ *.bridgesupport
61
+ build-iPhoneOS/
62
+ build-iPhoneSimulator/
63
+
64
+ ## Specific to RubyMotion (use of CocoaPods):
65
+ #
66
+ # We recommend against adding the Pods directory to your .gitignore. However
67
+ # you should judge for yourself, the pros and cons are mentioned at:
68
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
69
+ # vendor/Pods/
70
+
71
+ ## Documentation cache and generated files:
72
+ /.yardoc/
73
+ /_yardoc/
74
+ /doc/
75
+ /rdoc/
76
+
77
+ ## Environment normalization:
78
+ /.bundle/
79
+ /vendor/bundle
80
+ /lib/bundler/man/
81
+
82
+ # for a library or gem, you might want to ignore these files since the code is
83
+ # intended to run in multiple environments; otherwise, check them in:
84
+ # Gemfile.lock
85
+ # .ruby-version
86
+ # .ruby-gemset
87
+
88
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
89
+ .rvmrc
90
+
91
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
92
+ # .rubocop-https?--*
93
+
94
+ ### VisualStudioCode ###
95
+ .vscode/*
96
+ !.vscode/settings.json
97
+ !.vscode/tasks.json
98
+ !.vscode/launch.json
99
+ !.vscode/extensions.json
100
+ !.vscode/*.code-snippets
101
+
102
+ # Local History for Visual Studio Code
103
+ .history/
104
+
105
+ # Built Visual Studio Code Extensions
106
+ *.vsix
107
+
108
+ ### VisualStudioCode Patch ###
109
+ # Ignore all local history of files
110
+ .history
111
+ .ionide
112
+
113
+ # End of https://www.toptal.com/developers/gitignore/api/macos,visualstudiocode,ruby
data/.gitlab-ci.yml CHANGED
@@ -7,34 +7,44 @@ stages:
7
7
  workflow:
8
8
  rules:
9
9
  # For merge requests, create a pipeline.
10
- - if: '$CI_MERGE_REQUEST_IID'
10
+ - if: "$CI_MERGE_REQUEST_IID"
11
11
  # For default branch, create a pipeline.
12
- - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
12
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
13
13
  # For tags, never create pipeline.
14
- - if: '$CI_COMMIT_TAG'
14
+ - if: "$CI_COMMIT_TAG"
15
15
  when: never
16
16
 
17
17
  Update version:
18
18
  stage: version
19
- image: ruby:2.7.5
20
- before_script:
21
- - gem install gfsm
19
+ image: ruby:3.2.4
22
20
  script:
23
- - gfsm version bump --force > .version
24
- - gfsm changelog --force --output-file CHANGELOG.md
21
+ - bundle install
22
+ - chmod +x bin/gfsm
23
+ - bin/gfsm version bump > .version
24
+ - bin/gfsm changelog generate
25
25
  - echo "RELEASE_VERSION=$(<.version)" >> variables.env
26
+ - cat CHANGELOG.md
26
27
  artifacts:
27
28
  reports:
28
29
  dotenv: variables.env
29
30
  paths:
30
31
  - .version
31
32
  - CHANGELOG.md
32
-
33
+ variables:
34
+ FORCE_BUMP: true
35
+ OUTPUT_FILE: CHANGELOG.md
36
+ rules:
37
+ - if: "$CI_MERGE_REQUEST_IID"
38
+ variables:
39
+ PRERELEASE: true
40
+ PRERELEASE_NAME: $CI_COMMIT_REF_SLUG
41
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
42
+
33
43
  # Publish gem:
34
44
  # - GEM_HOST_API_KEY: A valid RubyGems API key.
35
45
  Publish gem:
36
46
  stage: deploy
37
- image: ruby:2.7.5
47
+ image: ruby:3.2.4
38
48
  variables:
39
49
  GEMSPEC_FILE: "gfsm.gemspec"
40
50
  GEM_FILE: "gfsm-${RELEASE_VERSION}.gem"
@@ -51,11 +61,9 @@ Publish gem:
51
61
  paths:
52
62
  - "*.gem"
53
63
  rules:
54
- - if: '$GEM_HOST_API_KEY == null'
64
+ - if: "$GEM_HOST_API_KEY == null"
55
65
  when: never
56
- - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
57
- when: never
58
- - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
66
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
59
67
 
60
68
  Upload docker image:
61
69
  stage: docker
@@ -64,12 +72,10 @@ Upload docker image:
64
72
  - docker:20.10.16-dind
65
73
  script:
66
74
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
67
- - docker build -t $CI_REGISTRY/zille_marco/gitlab-flavored-semantic-versioning:latest -t $CI_REGISTRY/zille_marco/gitlab-flavored-semantic-versioning:v$RELEASE_VERSION .
68
- - docker push --all-tags $CI_REGISTRY/zille_marco/gitlab-flavored-semantic-versioning
75
+ - docker build -t $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:v$RELEASE_VERSION .
76
+ - docker push --all-tags $CI_REGISTRY_IMAGE
69
77
  rules:
70
- - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
71
- when: never
72
- - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
78
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
73
79
 
74
80
  Create release:
75
81
  stage: release
@@ -85,8 +91,6 @@ Create release:
85
91
  - job: "Upload docker image"
86
92
  artifacts: false
87
93
  rules:
88
- - if: '$GEM_HOST_API_KEY == null'
89
- when: never
90
- - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
94
+ - if: "$GEM_HOST_API_KEY == null"
91
95
  when: never
92
- - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
96
+ - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.7.5
1
+ ruby 3.2.4
data/.version ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
data/.vscode/launch.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "Debug Local File",
9
- "type": "Ruby",
10
- "request": "launch",
11
- "program": "${workspaceRoot}/bin/gfsm",
12
- "args": ["version", "bump"]
13
- }
14
- ]
15
- }
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "ruby_lsp",
9
+ "request": "launch",
10
+ "name": "Debug program",
11
+ "program": "${workspaceRoot}/bin/gfsm version current"
12
+ }
13
+ ]
14
+ }
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.7.5-alpine3.15
1
+ FROM ruby:3.2.4-alpine3.20
2
2
 
3
3
  RUN gem install gfsm
4
4
 
data/Gemfile CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "yaml"
6
- gem "sem_version"
7
- gem "git"
5
+ gem "yaml", "~> 0.3.0"
6
+ gem "sem_version", "~> 2.0"
7
+ gem "git", "~> 2.1"
8
+
9
+ group :development do
10
+ gem "solargraph"
11
+ gem "debug"
12
+ end
data/Gemfile.lock CHANGED
@@ -1,20 +1,130 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- git (1.11.0)
4
+ activesupport (7.1.3.4)
5
+ base64
6
+ bigdecimal
7
+ concurrent-ruby (~> 1.0, >= 1.0.2)
8
+ connection_pool (>= 2.2.5)
9
+ drb
10
+ i18n (>= 1.6, < 2)
11
+ minitest (>= 5.1)
12
+ mutex_m
13
+ tzinfo (~> 2.0)
14
+ addressable (2.8.7)
15
+ public_suffix (>= 2.0.2, < 7.0)
16
+ ast (2.4.2)
17
+ backport (1.2.0)
18
+ base64 (0.2.0)
19
+ benchmark (0.3.0)
20
+ bigdecimal (3.1.8)
21
+ concurrent-ruby (1.3.3)
22
+ connection_pool (2.4.1)
23
+ debug (1.9.2)
24
+ irb (~> 1.10)
25
+ reline (>= 0.3.8)
26
+ diff-lcs (1.5.1)
27
+ drb (2.2.1)
28
+ e2mmap (0.1.0)
29
+ git (2.1.1)
30
+ activesupport (>= 5.0)
31
+ addressable (~> 2.8)
32
+ process_executer (~> 1.1)
5
33
  rchardet (~> 1.8)
34
+ i18n (1.14.5)
35
+ concurrent-ruby (~> 1.0)
36
+ io-console (0.7.2)
37
+ irb (1.13.2)
38
+ rdoc (>= 4.0.0)
39
+ reline (>= 0.4.2)
40
+ jaro_winkler (1.6.0)
41
+ json (2.7.2)
42
+ kramdown (2.4.0)
43
+ rexml
44
+ kramdown-parser-gfm (1.1.0)
45
+ kramdown (~> 2.0)
46
+ language_server-protocol (3.17.0.3)
47
+ minitest (5.24.0)
48
+ mutex_m (0.2.0)
49
+ nokogiri (1.16.6-arm64-darwin)
50
+ racc (~> 1.4)
51
+ nokogiri (1.16.6-x64-mingw-ucrt)
52
+ racc (~> 1.4)
53
+ nokogiri (1.16.6-x86_64-linux)
54
+ racc (~> 1.4)
55
+ parallel (1.25.1)
56
+ parser (3.3.3.0)
57
+ ast (~> 2.4.1)
58
+ racc
59
+ process_executer (1.1.0)
60
+ psych (5.1.2)
61
+ stringio
62
+ public_suffix (6.0.0)
63
+ racc (1.8.0)
64
+ rainbow (3.1.1)
65
+ rbs (2.8.4)
6
66
  rchardet (1.8.0)
67
+ rdoc (6.7.0)
68
+ psych (>= 4.0.0)
69
+ regexp_parser (2.9.2)
70
+ reline (0.5.9)
71
+ io-console (~> 0.5)
72
+ reverse_markdown (2.1.1)
73
+ nokogiri
74
+ rexml (3.3.0)
75
+ strscan
76
+ rubocop (1.64.1)
77
+ json (~> 2.3)
78
+ language_server-protocol (>= 3.17.0)
79
+ parallel (~> 1.10)
80
+ parser (>= 3.3.0.2)
81
+ rainbow (>= 2.2.2, < 4.0)
82
+ regexp_parser (>= 1.8, < 3.0)
83
+ rexml (>= 3.2.5, < 4.0)
84
+ rubocop-ast (>= 1.31.1, < 2.0)
85
+ ruby-progressbar (~> 1.7)
86
+ unicode-display_width (>= 2.4.0, < 3.0)
87
+ rubocop-ast (1.31.3)
88
+ parser (>= 3.3.1.0)
89
+ ruby-progressbar (1.13.0)
7
90
  sem_version (2.0.1)
8
- yaml (0.2.0)
91
+ solargraph (0.50.0)
92
+ backport (~> 1.2)
93
+ benchmark
94
+ bundler (~> 2.0)
95
+ diff-lcs (~> 1.4)
96
+ e2mmap
97
+ jaro_winkler (~> 1.5)
98
+ kramdown (~> 2.3)
99
+ kramdown-parser-gfm (~> 1.1)
100
+ parser (~> 3.0)
101
+ rbs (~> 2.0)
102
+ reverse_markdown (~> 2.0)
103
+ rubocop (~> 1.38)
104
+ thor (~> 1.0)
105
+ tilt (~> 2.0)
106
+ yard (~> 0.9, >= 0.9.24)
107
+ stringio (3.1.1)
108
+ strscan (3.1.0)
109
+ thor (1.3.1)
110
+ tilt (2.3.0)
111
+ tzinfo (2.0.6)
112
+ concurrent-ruby (~> 1.0)
113
+ unicode-display_width (2.5.0)
114
+ yaml (0.3.0)
115
+ yard (0.9.36)
9
116
 
10
117
  PLATFORMS
11
118
  arm64-darwin-21
119
+ x64-mingw-ucrt
12
120
  x86_64-linux
13
121
 
14
122
  DEPENDENCIES
15
- git
16
- sem_version
17
- yaml
123
+ debug
124
+ git (~> 2.1)
125
+ sem_version (~> 2.0)
126
+ solargraph
127
+ yaml (~> 0.3.0)
18
128
 
19
129
  BUNDLED WITH
20
130
  2.3.17
data/README.md CHANGED
@@ -78,7 +78,7 @@ stages:
78
78
 
79
79
  update-version:
80
80
  stage: version
81
- image: ruby:2.7.5
81
+ image: ruby:3.2.4
82
82
  before_script:
83
83
  - gem install gfsm
84
84
  script:
data/gfsm.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.description = %q{This gem adds support to bump the semantic version bump and generate changelog file based on the commits trailer.}
8
8
  spec.homepage = "https://gitlab.com/zillemarco/gitlab-flavored-semantic-versioning"
9
9
  spec.license = "MIT"
10
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
11
11
 
12
12
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
13
13
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = ["gfsm"]
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "yaml"
27
- spec.add_dependency "sem_version"
28
- spec.add_dependency "git"
26
+ spec.add_dependency "yaml", "~> 0.3.0"
27
+ spec.add_dependency "sem_version", "~> 2.0"
28
+ spec.add_dependency "git", "~> 2.1"
29
29
  end
@@ -7,44 +7,49 @@ module GFSM
7
7
  NEXT_ENTRY_MARKER = "<!--- next entry here -->"
8
8
 
9
9
  def self.help
10
+ cli_info = GFSM::Tools::VersionBumperSettings.cli_info
11
+
10
12
  <<~HELP
11
- Usage: gfsm changelog [help] [--output-file [<path>]] [--no-incremental] [--force] [--prerelease] [--prerelease-name <prerelease_name>] [--configuration <configuration_file_path>] [--path <repository_path]
12
-
13
- Arguments:
14
- help # Prints this help
15
- --output-file [<path>] # Path to the output changelog file. Defaults to 'CHANGELOG.md'.
16
- # If not specified, the generate changelog content will be written to stdout
17
- --no-incremental # When provided, the generated changelog won't look for an existing
18
- # changelog file. When outputting to stdout the changelog will never be incremental
19
- --force # When there are no commits with a changelog trailer
20
- # the version won't get bumped. Use this flag to force
21
- # the version bump (will increase the patch version)
22
- --prerelease # Use this switch to also include a prerelease in the version.
23
- # By default will add 'pre' and increment it like 'pre.1',
24
- # 'pre.2' and so on
25
- --prerelease-name <name> # Name of the prerelease that will get added when the
26
- # switch is enabled
27
- --configuration <path> # Path to the configuration YAML file
28
- --path <path> # Path to the repository. By default will use the current directory
13
+ Usage:
14
+ gfsm changelog [help|generate] [--output-file <path>] [--no-incremental] #{cli_info[:usage]}
15
+
16
+ Commands:
17
+ help # Prints this help
18
+ generate # Generate the changelog for the current version
19
+
20
+ Options:
21
+ --output-file <path> # Path to the output changelog file. Defaults to 'CHANGELOG.md'. If not specified, the generate changelog content will be written to stdout
22
+ --no-incremental # When provided, the generated changelog won't look for an existing changelog file. When outputting to stdout the changelog will never be incremental
23
+ --only-new-entries # When provided, the generated changelog won't look for an existing changelog file and will contain only the new entries for the current version, without the Changelog or version headings
24
+ #{cli_info[:options]}
25
+
26
+ Environment variables:
27
+ OUTPUT_FILE # Equivalent to --output-file
28
+ NO_INCREMENTAL # Equivalent to --no-incremental
29
+ ONLY_ENTRIES # Equivalent to --only-new-entries
30
+ #{cli_info[:environment_variables]}
29
31
  HELP
30
32
  end
31
33
 
32
34
  def run(args = [])
33
- if !args.empty? && args[0] == "help"
35
+ case args.shift
36
+ when 'help'
34
37
  GFSM::Output.puts(GFSM::Commands::Changelog.help)
35
- else
36
- no_incremental = args.include?("--no-incremental")
38
+ when 'generate'
39
+ no_incremental = ENV.has_key?("NO_INCREMENTAL") || args.include?("--no-incremental")
40
+ only_new_entries = ENV.has_key?("ONLY_NEW_ENTRIES") || args.include?("--only-new-entries")
37
41
  output_file_path = get_output_file_path(args)
38
- changelog_section = compute_this_version_section(args)
42
+ changelog_section = compute_this_version_section(args, only_new_entries)
39
43
 
40
- if !output_file_path
44
+ if only_new_entries
45
+ GFSM::Output.puts changelog_section
46
+ elsif !output_file_path
41
47
  GFSM::Output.puts <<~CHANGELOG
42
48
  # Changelog
43
-
44
49
  #{changelog_section}
45
50
  CHANGELOG
46
51
  else
47
- if File.exists?(output_file_path) && !no_incremental
52
+ if File.file?(output_file_path) && !no_incremental
48
53
  existing_content = File.read(output_file_path)
49
54
 
50
55
  file_content = existing_content.gsub(/#{Regexp.quote(NEXT_ENTRY_MARKER)}/i, changelog_section)
@@ -54,12 +59,13 @@ module GFSM
54
59
  File.open(output_file_path, 'w') do |file|
55
60
  file.write <<~CHANGELOG
56
61
  # Changelog
57
-
58
62
  #{changelog_section}
59
63
  CHANGELOG
60
64
  end
61
65
  end
62
66
  end
67
+ else
68
+ GFSM::Output.warn(GFSM::Commands::Version.help)
63
69
  end
64
70
 
65
71
  true
@@ -67,15 +73,10 @@ module GFSM
67
73
 
68
74
  private
69
75
 
70
- def compute_this_version_section(args)
71
- force = args.include?("--force")
72
- prerelease = args.include?("--prerelease")
73
- prerelease_name = get_prerelease_name(args)
74
- repository_path = get_repository_path(args)
75
- configuration_file_path = get_configuration_file_path(args)
76
-
77
- version_bumper = GFSM::Tools::VersionBumper.new()
78
- version = version_bumper.compute_version!(force, prerelease, prerelease_name, repository_path, configuration_file_path)
76
+ def compute_this_version_section(args, only_new_entries)
77
+ settings = GFSM::Tools::VersionBumperSettings.new(args)
78
+ version_bumper = GFSM::Tools::VersionBumper.new(settings)
79
+ version = version_bumper.execute
79
80
  subdivisions = version_bumper.subdivisions.to_a
80
81
  subdivisions.sort_by! { |subdivision_data| subdivision_data[0].priority }.reverse!
81
82
 
@@ -85,30 +86,29 @@ module GFSM
85
86
  change_type = subdivision_data[0]
86
87
  commits = subdivision_data[1]
87
88
 
88
- changelog_entries += "\n#{change_type.to_changelog_entry}\n\n"
89
+ changelog_entries += "#{change_type.to_changelog_entry}\n\n"
89
90
 
90
91
  commits.each do |commit|
91
92
  changelog_entries += "- #{commit.to_changelog_entry}\n"
92
93
  end
93
- end
94
94
 
95
- if !subdivisions || subdivisions.empty?
96
- changelog_section = "#{NEXT_ENTRY_MARKER}\n\n## #{version}\n\n"
97
- else
98
- changelog_section = "#{NEXT_ENTRY_MARKER}\n\n## #{version}\n#{changelog_entries}"
95
+ changelog_entries += "\n"
99
96
  end
100
- end
101
97
 
102
- def extract_switch_value(args, switch, default_value)
103
- switch_index = args.find_index(switch)
104
-
105
- return default_value unless switch_index &&
106
- (switch_index + 1) < args.length
98
+ changelog_entries = changelog_entries[0...-1] unless changelog_entries.empty?
107
99
 
108
- args[switch_index + 1]
100
+ return changelog_entries if only_new_entries
101
+
102
+ section = "#{NEXT_ENTRY_MARKER}\n## #{version}"
103
+
104
+ return section if !subdivisions || subdivisions.empty?
105
+
106
+ "#{section}\n\n#{changelog_entries}"
109
107
  end
110
108
 
111
- def extract_switch_value_if_present(args, switch, default_value)
109
+ def extract_switch_value_if_present(args, switch, default_value, env_name)
110
+ return ENV.fetch(env_name) if ENV.has_key?(env_name)
111
+
112
112
  switch_index = args.find_index(switch)
113
113
 
114
114
  return nil unless switch_index
@@ -118,19 +118,7 @@ module GFSM
118
118
  end
119
119
 
120
120
  def get_output_file_path(args)
121
- extract_switch_value_if_present(args, "--output-file", "./CHANGELOG.md")
122
- end
123
-
124
- def get_configuration_file_path(args)
125
- extract_switch_value(args, "--configuration", "./gfsmrc.yml")
126
- end
127
-
128
- def get_prerelease_name(args)
129
- extract_switch_value(args, "--prerelease-name", "pre")
130
- end
131
-
132
- def get_repository_path(args)
133
- extract_switch_value(args, "--path", ".")
121
+ extract_switch_value_if_present(args, "--output-file", "./CHANGELOG.md", "OUTPUT_FILE")
134
122
  end
135
123
  end
136
124
  end
data/lib/commands/help.rb CHANGED
@@ -7,22 +7,20 @@ module GFSM
7
7
  GFSM::Output.puts <<~HELP
8
8
  # GitLab Flavored Semantic Versioning
9
9
 
10
- Usage: gfsm <command> [<args>]
10
+ Usage:
11
+
12
+ gfsm <command> [<args>]
11
13
 
12
14
  Available commands:
15
+ gfsm help # Print this help text
16
+ gfsm version # Command used to print the current version or bump it based on the configuration
17
+ gfsm changelog # Command used to generate a changelog based on the commits since the latest release
13
18
 
14
- gfsm help # Print this help text
15
- gfsm version # Command used to print the current version or bump it based on the configuration
16
- gfsm changelog # Command used to generate a changelog based on the commits since the latest release
17
-
18
- # Version command
19
19
 
20
+ Version command
20
21
  #{GFSM::Commands::Version.help}
21
-
22
- # Changelog command
23
-
22
+ Changelog command
24
23
  #{GFSM::Commands::Changelog.help}
25
-
26
24
  HELP
27
25
 
28
26
  true
@@ -5,44 +5,38 @@ module GFSM
5
5
  class Version < BaseCommand
6
6
 
7
7
  def self.help
8
+ cli_info = GFSM::Tools::VersionBumperSettings.cli_info
9
+
8
10
  <<~HELP
9
- Usage: gfsm version [help] [bump [--force] [--prerelease] [--prerelease-name <prerelease_name>] [--configuration <configuration_file_path>] [--path <repository_path]]
11
+ Usage:
12
+ gfsm version [help|bump|current] #{cli_info[:usage]}
13
+
14
+ Commands:
15
+ help # Prints this help
16
+ bump # Bump the current version based on the commits changelog trailer and the configuration file
17
+ current # Print the current version, without bumping it
18
+
19
+ Options: \n#{cli_info[:options]}
10
20
 
11
- Arguments:
12
- help # Prints this help
13
- bump # Bump the current version based on the commits
14
- # changelog trailer and the configuration file
15
- --force # When there are no commits with a changelog trailer
16
- # the version won't get bumped. Use this flag to force
17
- # the version bump (will increase the patch version)
18
- --prerelease # Use this switch to also include a prerelease in the version.
19
- # By default will add 'pre' and increment it like 'pre.1',
20
- # 'pre.2' and so on
21
- --prerelease-name <name> # Name of the prerelease that will get added when the
22
- # switch is enabled
23
- --configuration <path> # Path to the configuration YAML file
24
- --path <path> # Path to the repository. By default will use the current directory
21
+ Environment variables: \n#{cli_info[:environment_variables]}
25
22
  HELP
26
23
  end
27
24
 
28
25
  def run(args = [])
29
- if args.empty? || (args.length == 2 && args[0] != "bump")
30
- repository_path = get_repository_path(args)
31
-
32
- GFSM::Output.puts GFSM::Tools::CurrentVersionLoader.load_current_version(repository_path)
33
- return true
34
- end
35
-
36
26
  case args.shift
37
27
  when 'bump'
38
- force = args.include?("--force")
39
- prerelease = args.include?("--prerelease")
40
- prerelease_name = get_prerelease_name(args)
41
- repository_path = get_repository_path(args)
42
- configuration_file_path = get_configuration_file_path(args)
28
+ settings = GFSM::Tools::VersionBumperSettings.new(args)
29
+ version_bumper = GFSM::Tools::VersionBumper.new(settings)
30
+ version = version_bumper.execute
31
+
32
+ GFSM::Output.puts(version)
33
+ when 'current'
34
+ settings = GFSM::Tools::VersionBumperSettings.new(args)
35
+ version = GFSM::Tools::CurrentVersionLoader.load_current_version(settings.repository)
43
36
 
44
- version_bumper = GFSM::Tools::VersionBumper.new()
45
- version = version_bumper.compute_version!(force, prerelease, prerelease_name, repository_path, configuration_file_path)
37
+ if settings.prerelease
38
+ version.add_prerelease_suffix!(settings.prerelease_name)
39
+ end
46
40
 
47
41
  GFSM::Output.puts(version)
48
42
  when 'help'
@@ -53,29 +47,6 @@ module GFSM
53
47
 
54
48
  true
55
49
  end
56
-
57
- private
58
-
59
- def extract_switch_value(args, switch, default_value)
60
- switch_index = args.find_index(switch)
61
-
62
- return default_value unless switch_index &&
63
- (switch_index + 1) < args.length
64
-
65
- args[switch_index + 1]
66
- end
67
-
68
- def get_configuration_file_path(args)
69
- extract_switch_value(args, "--configuration", "./gfsmrc.yml")
70
- end
71
-
72
- def get_prerelease_name(args)
73
- extract_switch_value(args, "--prerelease-name", "pre")
74
- end
75
-
76
- def get_repository_path(args)
77
- extract_switch_value(args, "--path", ".")
78
- end
79
50
  end
80
51
  end
81
52
  end
data/lib/data/version.rb CHANGED
@@ -7,7 +7,7 @@ module GFSM
7
7
  class Version < SemVersion
8
8
  PRERELEASE_BUILD_VERSION = /^(?<prerelease_name>[a-zA-Z\-]+)(\.?)(?<prerelease_version>[0-9]*)$/i
9
9
 
10
- def bump!(major = false, minor = false, patch = true, pre = false, prerelease_name = "pre")
10
+ def bump!(major = false, minor = false, patch = true, pre = false, prerelease_name)
11
11
  if major
12
12
  self.major = self.major + 1
13
13
  self.minor = 0
@@ -20,12 +20,16 @@ module GFSM
20
20
  end
21
21
 
22
22
  if pre
23
- preselease_match = self.pre.match(PRERELEASE_BUILD_VERSION) if self.pre
24
- if preselease_match
25
- self.pre = preselease_match[:prerelease_name] + "." + (preselease_match[:prerelease_version].to_i + 1).to_s
26
- else
27
- self.pre = prerelease_name
28
- end
23
+ self.add_prerelease_suffix!(prerelease_name)
24
+ end
25
+ end
26
+
27
+ def add_prerelease_suffix!(prerelease_name)
28
+ preselease_match = self.pre.match(PRERELEASE_BUILD_VERSION) if self.pre
29
+ if preselease_match
30
+ self.pre = preselease_match[:prerelease_name] + "." + (preselease_match[:prerelease_version].to_i + 1).to_s
31
+ else
32
+ self.pre = prerelease_name
29
33
  end
30
34
  end
31
35
  end
@@ -6,10 +6,8 @@ require_relative '../data/version'
6
6
  module GFSM
7
7
  module Tools
8
8
  class CurrentVersionLoader
9
- def self.load_current_version(repo_path = ".")
10
- last_tag_name = GFSM::Tools::GitUtilities.extract_last_tag_name(
11
- GFSM::Tools::GitUtilities.load_repo(repo_path)
12
- )
9
+ def self.load_current_version(repo)
10
+ last_tag_name = GFSM::Tools::GitUtilities.extract_last_tag_name(repo)
13
11
 
14
12
  return GFSM::Data::Version.new("0.0.0") unless last_tag_name
15
13
 
@@ -13,23 +13,16 @@ module GFSM
13
13
 
14
14
  def self.extract_last_tag_name(repo)
15
15
  begin
16
- current_sort_order = repo.config("tag.sort")
17
- repo.fetch(tags: true)
18
-
19
- repo.config("tag.sort", "-v:refname")
20
- tags = repo.tags
21
- repo.config("tag.sort", current_sort_order)
22
-
23
- tags[0].name if !tags.empty?
24
- rescue
16
+ repo.fetch(nil, {tags: true})
17
+ repo.describe(nil, {tags: true, abbrev: 0})
18
+ rescue => error
19
+ GFSM::Output.error(error.message)
25
20
  end
26
21
  end
27
22
 
28
- def self.extract_commits_with_changelog_trailer(repo)
29
- last_tag_name = self.extract_last_tag_name(repo)
30
-
23
+ def self.extract_commits_with_changelog_trailer(repo, from, to = "HEAD")
31
24
  begin
32
- commits = last_tag_name ? repo.log.between(last_tag_name, 'HEAD') : repo.log
25
+ commits = repo.log.between(from, to)
33
26
  commits.each_with_object([]) do |commit, memo|
34
27
  trailer = commit.message.match(CHANGELOG_TRAILER_REGEX)
35
28
  memo << GFSM::Data::Commit.new(commit, trailer[:name], trailer[:category]) if trailer
@@ -5,25 +5,111 @@ require_relative '../data/version'
5
5
 
6
6
  module GFSM
7
7
  module Tools
8
+
9
+ class VersionBumperSettings
10
+ attr_reader :repository, :configuration, :force, :force_version, :prerelease, :prerelease_name, :from, :to
11
+
12
+ def initialize(cli_args)
13
+ @repository = GFSM::Tools::GitUtilities.load_repo(get_repository_path(cli_args))
14
+ @configuration = GFSM::Data::Configuration.new(get_configuration_file_path(cli_args))
15
+ @force = ENV.has_key?("FORCE_BUMP") || cli_args.include?("--force")
16
+ @force_version = get_force_version(cli_args)
17
+ @prerelease = ENV.has_key?("PRERELEASE") || cli_args.include?("--prerelease")
18
+ @prerelease_name = get_prerelease_name(cli_args)
19
+ @from = get_from(cli_args)
20
+ @to = get_to(cli_args)
21
+ @from = GFSM::Tools::GitUtilities.extract_last_tag_name(@repository) if @from.nil?
22
+ end
23
+
24
+ def self.cli_info
25
+ options = <<~OPTIONS
26
+ --force # When there are no commits with a changelog trailer the version won't get bumped. Use this flag to force the version bump. Unless specified, it will increase the patch
27
+ --force-version <major|minor|match> # What section of the version to bump if the changelog trailer is not found.
28
+ --prerelease # Use this switch to also include a prerelease in the version. By default will add 'pre' and increment it like 'pre.1', 'pre.2' and so on
29
+ --prerelease-name <name> # Name of the prerelease that will get added when the switch is enabled
30
+ --configuration <path> # Path to the configuration YAML file
31
+ --from <hash or tag> # The commit hash or tag to start from when extracting the commits. By default will use the latest tag
32
+ --to <hash, tag or HEAD> # The commit hash or tag to stop at when extracting the commits. By default will use HEAD to get to the latest commit on the current branch
33
+ --configuration <path> # Path to the configuration YAML file
34
+ --path <path> # Path to the repository. By default will use the current directory
35
+ OPTIONS
36
+
37
+ environment_variables = <<~ENVVARS
38
+ FORCE_BUMP # Equivalent to --force
39
+ FORCE_BUMP_VERSION # Equivalent to --force-version
40
+ PRERELEASE # Equivalent to --prerelease
41
+ PRERELEASE_NAME # Equivalent to --prerelease-name
42
+ CONFIGURATION_FILE # Equivalent to --configuration
43
+ REPOSITORY_PATH # Equivalent to --path
44
+ FROM_COMMIT # Equivalent to --from
45
+ TO_COMMIT # Equivalent to --to
46
+ ENVVARS
47
+
48
+ return {
49
+ usage: "[--force] [--force-version <major|minor|patch>] [--configuration <configuration_file_path>] [--prerelease] [--prerelease-name <prerelease_name>] [--from <hash or tag>] [--to <hash, tag or HEAD>] [--path <repository_path]",
50
+ options: options,
51
+ environment_variables: environment_variables
52
+ }
53
+ end
54
+
55
+ private
56
+
57
+ def extract_switch_value(args, switch, default_value, env_name = nil)
58
+ return ENV.fetch(env_name) if ENV.has_key?(env_name)
59
+
60
+ switch_index = args.find_index(switch)
61
+
62
+ return default_value unless switch_index &&
63
+ (switch_index + 1) < args.length
64
+
65
+ args[switch_index + 1]
66
+ end
67
+
68
+ def get_configuration_file_path(args)
69
+ extract_switch_value(args, "--configuration", "./gfsmrc.yml", "CONFIGURATION_FILE")
70
+ end
71
+
72
+ def get_prerelease_name(args)
73
+ extract_switch_value(args, "--prerelease-name", "pre", "PRERELEASE_NAME")
74
+ end
75
+
76
+ def get_repository_path(args)
77
+ extract_switch_value(args, "--path", ".", "REPOSITORY_PATH")
78
+ end
79
+
80
+ def get_force_version(args)
81
+ extract_switch_value(args, "--force-version", "patch", "FORCE_BUMP_VERSION")
82
+ end
83
+
84
+ def get_from(args)
85
+ extract_switch_value(args, "--from", nil, "FROM_COMMIT")
86
+ end
87
+
88
+ def get_to(args)
89
+ extract_switch_value(args, "--to", "HEAD", "TO_COMMIT")
90
+ end
91
+ end
92
+
8
93
  class VersionBumper
9
94
  attr_reader :version, :subdivisions
10
95
 
11
- def compute_version!(force, prerelease, prerelease_name, repository_path, configuration_file_path)
12
- configuration = GFSM::Data::Configuration.new(configuration_file_path)
13
- changelog_commits = GFSM::Tools::GitUtilities.extract_commits_with_changelog_trailer(
14
- GFSM::Tools::GitUtilities.load_repo(repository_path)
15
- )
96
+ def initialize(settings)
97
+ @settings = settings
98
+ end
99
+
100
+ def execute
101
+ changelog_commits = GFSM::Tools::GitUtilities.extract_commits_with_changelog_trailer(@settings.repository, @settings.from, @settings.to)
16
102
 
17
- @version = GFSM::Tools::CurrentVersionLoader.load_current_version(repository_path)
18
- @subdivisions = GFSM::Tools::CommitsSubdivider.subdivide_commits(configuration, changelog_commits)
103
+ @version = GFSM::Tools::CurrentVersionLoader.load_current_version(@settings.repository)
104
+ @subdivisions = GFSM::Tools::CommitsSubdivider.subdivide_commits(@settings.configuration, changelog_commits)
19
105
 
20
- if !subdivisions || subdivisions.empty?
21
- if force
22
- @version.bump!(false, false, true, prerelease, prerelease_name)
106
+ if !@subdivisions || @subdivisions.empty?
107
+ if @settings.force
108
+ @version.bump!(@settings.force_version == "major", @settings.force_version == "minor", @settings.force_version == "patch", @settings.prerelease, @settings.prerelease_name)
23
109
  end
24
110
  else
25
- highest_bump = GFSM::Data::ChangeType.find_highest_bump(subdivisions.keys)
26
- @version.bump!(highest_bump == :major, highest_bump == :minor, highest_bump == :patch, prerelease, prerelease_name)
111
+ highest_bump = GFSM::Data::ChangeType.find_highest_bump(@subdivisions.keys)
112
+ @version.bump!(highest_bump == :major, highest_bump == :minor, highest_bump == :patch, @settings.prerelease, @settings.prerelease_name)
27
113
  end
28
114
 
29
115
  return @version
metadata CHANGED
@@ -1,69 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gfsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zille Marco
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-29 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sem_version
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: git
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.1'
55
55
  description: This gem adds support to bump the semantic version bump and generate
56
56
  changelog file based on the commits trailer.
57
- email:
57
+ email:
58
58
  executables:
59
59
  - gfsm
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".editorconfig"
64
+ - ".gitattributes"
64
65
  - ".gitignore"
65
66
  - ".gitlab-ci.yml"
66
67
  - ".tool-versions"
68
+ - ".version"
67
69
  - ".vscode/launch.json"
68
70
  - Dockerfile
69
71
  - Gemfile
@@ -94,7 +96,7 @@ metadata:
94
96
  homepage_uri: https://gitlab.com/zillemarco/gitlab-flavored-semantic-versioning
95
97
  source_code_uri: https://gitlab.com/zillemarco/gitlab-flavored-semantic-versioning
96
98
  changelog_uri: https://gitlab.com/zillemarco/gitlab-flavored-semantic-versioning/-/releases
97
- post_install_message:
99
+ post_install_message:
98
100
  rdoc_options: []
99
101
  require_paths:
100
102
  - lib
@@ -102,15 +104,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
104
  requirements:
103
105
  - - ">="
104
106
  - !ruby/object:Gem::Version
105
- version: 2.7.0
107
+ version: 3.0.0
106
108
  required_rubygems_version: !ruby/object:Gem::Requirement
107
109
  requirements:
108
110
  - - ">="
109
111
  - !ruby/object:Gem::Version
110
112
  version: '0'
111
113
  requirements: []
112
- rubygems_version: 3.1.6
113
- signing_key:
114
+ rubygems_version: 3.4.19
115
+ signing_key:
114
116
  specification_version: 4
115
117
  summary: This gem adds support to bump the semantic version bump and generate changelog
116
118
  file based on the commits trailer.