gfsm 0.5.0 → 0.6.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: bcc64afb8b73256994f18c36d2a639a046e0590ec702860b6cc60346cb764752
4
- data.tar.gz: '048ff158cca74ebd96952424b7c8246bcae31f99d75a94d679e713411bf7aa51'
3
+ metadata.gz: 1e82f5cdce1d37aced2b895cabbc7a9b24019ddfb0838a35b623ff097307c343
4
+ data.tar.gz: ef83dd15b50de4d9db1e28e92e354864379294f9f8485fd093682e59525afd7d
5
5
  SHA512:
6
- metadata.gz: 0b3283af8114728bc505d00af6e12fe6b7ebc0011e9f3fdddf0fb254752a78e98dc67283ae294c4acf3660ba2a5856c673f53786c6fb1899252df8db52058d42
7
- data.tar.gz: 0d739d31c958f5802b595521ec7ed0ad573220a7930d5c79272628fc0172cbf71fc0129ea29ed7fd8a74036ce1f869824eb6af16e251fc6116631ab6421cf9c2
6
+ metadata.gz: b2c98d7dce54ec8b5bed5a4a3f328b97778a95fb622d977af7051ad9c034e344fba153da0a495b5288ddf3498e2970b88a6e1b07c0760b67c9dd0da1974e758b
7
+ data.tar.gz: 67c36f148426d0f397fe076aae8bdcbe1cf94f17d8aef7098221bce59e2f864f63286ceabfa7bc34020c78718b5a96ab9f84ee4fc88e8e872fdc429fbfa2cc05
data/.gitlab-ci.yml CHANGED
@@ -64,6 +64,13 @@ Publish gem:
64
64
  - if: "$GEM_HOST_API_KEY == null"
65
65
  when: never
66
66
  - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
67
+ changes:
68
+ - bin/**/*
69
+ - lib/**/*
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - gfsm.gemspec
73
+ - .tools-versions
67
74
 
68
75
  Upload docker image:
69
76
  stage: docker
@@ -72,10 +79,18 @@ Upload docker image:
72
79
  - docker:20.10.16-dind
73
80
  script:
74
81
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
75
- - docker build -t $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:v$RELEASE_VERSION .
82
+ - docker build --build-arg="GFSM_VERSION=${RELEASE_VERSION}" -t $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:v$RELEASE_VERSION .
76
83
  - docker push --all-tags $CI_REGISTRY_IMAGE
77
84
  rules:
78
85
  - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
86
+ changes:
87
+ - bin/**/*
88
+ - lib/**/*
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - gfsm.gemspec
92
+ - .tools-versions
93
+ - Dockerfile
79
94
 
80
95
  Create release:
81
96
  stage: release
@@ -94,3 +109,11 @@ Create release:
94
109
  - if: "$GEM_HOST_API_KEY == null"
95
110
  when: never
96
111
  - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
112
+ changes:
113
+ - bin/**/*
114
+ - lib/**/*
115
+ - Gemfile
116
+ - Gemfile.lock
117
+ - gfsm.gemspec
118
+ - .tools-versions
119
+ - Dockerfile
data/Dockerfile CHANGED
@@ -1,8 +1,10 @@
1
1
  FROM ruby:3.2.4-alpine3.20
2
2
 
3
+ ARG GFSM_VERSION
4
+
3
5
  RUN apk add git
4
- RUN gem install gfsm
6
+ RUN gem install gfsm -v ${GFSM_VERSION}
5
7
 
6
8
  COPY ./gfsmrc.yml ./gfsmrc.yml
7
9
 
8
- ENTRYPOINT [""]
10
+ ENTRYPOINT [""]
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # GitLab Flavored Semantic Versionin
1
+ # GitLab Flavored Semantic Versioning
2
2
 
3
- ### Goal
3
+ ## Goal
4
4
 
5
5
  This project tries to achieve automatic semantic versioning not basing the version bump
6
6
  on the conventional commits standars, but rather on a `Changelog` value on the trailer
@@ -13,36 +13,40 @@ to get merged through a merge request.
13
13
  The beauty of this project is that you don't need to use the conventional commits specification,
14
14
  so you can have commits more similar to
15
15
 
16
- ```
16
+ ```plaintext
17
17
  Added new feature A to address this requirement
18
18
  ```
19
19
 
20
20
  instead of
21
21
 
22
- ```
22
+ ```plaintext
23
23
  feat(<type>): added new feature A to address this requirement
24
24
  ```
25
25
 
26
26
  This translates to:
27
+
27
28
  - _**no "wasted" characters for that message prefix**_
28
29
  - more readable commit messages
29
30
  - a nicer `Changelog`
30
- ```
31
+
32
+ ```plaintext
31
33
  New features:
32
34
  - Added new feature A to address this requirement
33
35
  - Added feature B
34
36
  ```
37
+
35
38
  vs
36
- ```
39
+
40
+ ```plaintext
37
41
  New features:
38
42
  - feat(<type>): added new feature A to address this requirement
39
43
  - feat: added feature B
40
44
  ```
41
45
 
42
- ### Setup
46
+ ## Setup
43
47
 
44
48
  The only tool you need to setup this project on your local environment is Ruby, which can be
45
- downloaded using `asdf`. The Ruby version required is `2.7.5`.
49
+ downloaded using `asdf`. The Ruby version required is `3.2.4`.
46
50
 
47
51
  Once Ruby is present on your system you can install the dependencies by running
48
52
 
@@ -50,11 +54,13 @@ Once Ruby is present on your system you can install the dependencies by running
50
54
  bundle install
51
55
  ```
52
56
 
53
- ### Testing
57
+ ## Testing
54
58
 
55
59
  At the moment there's no built-in testing platform, but I'm planning to use `rspec` to add unit tests.
56
60
 
57
- ### Using
61
+ ## Usage
62
+
63
+ ### Installation
58
64
 
59
65
  This project is available as a Ruby gem, so to be able to use it is enough to run
60
66
 
@@ -68,33 +74,138 @@ Once that command completes, the gem will be available and you can invoke it fro
68
74
  gfsm help
69
75
  ```
70
76
 
71
- The main way this project can be used though, is inside a CI pipeline where you can invoke it to bump the version and/or update the changelog.
77
+ **Important**: `git` must be avaiable on the system for the gem to work.
72
78
 
73
- In order to use is inside a CI job, the job itself could look something like this:
79
+ The main way this project can be used though, is inside a CI pipeline where you can invoke it to bump
80
+ the version and/or update the changelog.
74
81
 
75
- ```yaml
76
- stages:
77
- - version
78
-
79
- update-version:
80
- stage: version
81
- image: ruby:3.2.4
82
- before_script:
83
- - gem install gfsm
84
- script:
85
- - gfsm version bump --force > .version
86
- - gfsm changelog --force --output-file CHANGELOG.md
87
- - echo "RELEASE_VERSION=$(<.version)" >> variables.env
88
- artifacts:
89
- reports:
90
- dotenv: variables.env
91
- paths:
92
- - .version
93
- - CHANGELOG.md
82
+ To facilitate this, a docker image is published with every release of this tool.
83
+ [Here](https://gitlab.com/zille_marco/gitlab-flavored-semantic-versioning/container_registry/3294324)
84
+ is a list of all the available images.
85
+
86
+ ### Available commands
87
+
88
+ The main commands available are:
89
+
90
+ - `gfsm version`: this command takes care of the project's verioning.
91
+ - `gfsm changelog`: this command takes care of the project's changelog.
92
+ - `gfsm help`: this command will display the available commands and their usage.
93
+
94
+ To use these commands, you can invoke the `gfsm` executable from the command line. For example:
95
+
96
+ ```shell
97
+ gfsm version <subcommand>
98
+ gfsm changelog <subcommand>
99
+ ```
100
+
101
+ #### gfsm version
102
+
103
+ The `version` command has its own subcommands:
104
+
105
+ - `bump`: used to bump the version to the next one
106
+ - `current`: used to extract the current version
107
+ - `help`: used to print the usage of the `vesion` command itself
108
+
109
+ All subcommands are configurable through either CLI flags or environment variables, that have precedence
110
+ over the CLI flags.
111
+
112
+ | CLI flag | Environment variable | Accepted values | Default | Description |
113
+ | ------------------- | -------------------- | ------------------------------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
114
+ | `--force` | `FORCE_BUMP` | | | If there are no commits with a changelog trailer, the version will still be bumped. |
115
+ | `--force-version` | `FORCE_BUMP_VERSION` | `major`, `minor`, `patch` | `patch` | If the version needs to be force-bumped, this flag instructs the tool which section of the version to bump. |
116
+ | `--prerelease` | `PRERELEASE` | | | Turns on prerelease generation, which by default appends `-pre` to the generated version. |
117
+ | `--prerelease-name` | `PRERELEASE_NAME` | Any string without whitespaces | `pre` | When prerelease generation is enabled, this overrides the default `pre` value appended as suffix to the generated version. |
118
+ | `--configuration` | `CONFIGURATION_FILE` | A file path | `./gfsmrc.yml` | The path to the YAML configuration file. |
119
+ | `--path` | `REPOSITORY_PATH` | A folder path | `.` | The path to the folder containing the Git repository. |
120
+ | `--from` | `FROM_COMMIT` | A commit SHA or a tag name | The latest **reachable** tag | The commit SHA or the tag name from where to start scraping for commit messages. |
121
+ | `--to` | `TO_COMMIT` | A commit SHA or a tag name | `HEAD` | The commit SHA or the tag name where to stop scraping for commit messages. |
122
+ | `--initial-version` | `INITIAL_VERSION` | A semantic version value | `0.0.0` | The version used when the project doesn't have one yet, useful for the first initialization of the project. |
123
+
124
+ #### gfsm changelog
125
+
126
+ The `changelog` command has its own subcommands:
127
+
128
+ - `generate`: used to generate a changelog for the latest version
129
+ - `extract`: used to extract a section from the changelog associated with a specific version
130
+ - `help`: used to print the usage of the `changelog` command itself
131
+
132
+ All subcommands are configurable through either CLI flags or environment variables, that have precedence
133
+ over the CLI flags.
134
+
135
+ The `changelog` command supports all the flags and environment variables of the `version` command, with
136
+ the following additions.
137
+
138
+ | CLI flag | Environment variable | Accepted values | Default | Description |
139
+ | -------------------- | -------------------- | --------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
140
+ | `--output-file` | `OUTPUT_FILE` | A file path | | The path to the CHANGELOG.md file, which will be created if not existing. If not specified the changelog will be written to stdout. **Only usable with `generate`**. |
141
+ | `--input-file` | `INPUT_FILE` | A file path | `./CHANGELOG.md` | The path to the CHANGELOG.md file. **Only usable with `extract`**. |
142
+ | `--no-incremental` | `NO_INCREMENTAL` | | | When provided, the output file will always be overridden and will contain only the changelog entries for the latest version. |
143
+ | `--only-new-entries` | `ONLY_NEW_ENTRIES` | | | When provided, the output will always be written to stdout and will only contain the changelog for the latest changes without the version header. |
144
+ | `--extract-version` | `EXTRACT_VERSION` | A version name | | When provided, this specifies the version that `extract` will extract the release notes from. If not provided, or set to `latest`, it will extract the release notes from the latest version. |
145
+
146
+ ### Configuration
147
+
148
+ GFSM can be cofigured by providing a YAML configuration file which will contain informations about the
149
+ supported changelog trailers, the section they belong to and their priority.
150
+
151
+ The schema is the following:
152
+
153
+ ```plaintext
154
+ change_types:
155
+ <identifier>:
156
+ title: string
157
+ matcher: string
158
+ bump: major|minor|patch
159
+ priority: number
94
160
  ```
95
161
 
96
- With this, subsequent jobs that depend on the `update-version` job will:
97
- - be able to get the new version form the `RELEASE_VERSION` environment variable
98
- - read the `CHANGELOG.md` file to get an updated changelog file
162
+ Where:
99
163
 
100
- To have a working example of the things described above you can have a look at the `.gitlab-ci.yml` of this project, which implements this exact concept.
164
+ - `<identifier>` is used only to separate the different sections
165
+ - `title` is the title used when generating the changelog
166
+ - `matcher` is the string that the commit changelog trailer has to contain in order to match the section
167
+ - `bump` tells the tool which section of the version to bump when a commit changelog trailer matches
168
+ the section
169
+ - `priority` is used to order the sections when generating the changelog, the higher the priority the
170
+ higher up the section will be in the changelog
171
+
172
+ Here is an example:
173
+
174
+ ```yaml
175
+ change_types:
176
+ new_features:
177
+ title: "New features"
178
+ matcher: added
179
+ bump: minor
180
+ priority: 6
181
+ feature_removals:
182
+ title: "Feature removals"
183
+ matcher: removed
184
+ bump: major
185
+ priority: 5
186
+ deprecations:
187
+ title: "Deprecations"
188
+ matcher: deprecated
189
+ bump: minor
190
+ priority: 4
191
+ feature_changes:
192
+ title: "Feature changes"
193
+ matcher: changed
194
+ bump: minor
195
+ priority: 3
196
+ fixes:
197
+ title: "Fixes"
198
+ matcher: fixed
199
+ bump: patch
200
+ priority: 2
201
+ security_fixes:
202
+ title: "Security fixes"
203
+ matcher: security
204
+ bump: patch
205
+ priority: 1
206
+ other:
207
+ title: "Other"
208
+ matcher: other
209
+ bump: patch
210
+ priority: 0
211
+ ```
@@ -85,7 +85,7 @@ module GFSM
85
85
  end
86
86
  end
87
87
  else
88
- GFSM::Output.warn GFSM::Commands::Version.help
88
+ GFSM::Output.warn GFSM::Commands::Changelog.help
89
89
  end
90
90
 
91
91
  true
data/lib/commands/help.rb CHANGED
@@ -8,7 +8,7 @@ module GFSM
8
8
  # GitLab Flavored Semantic Versioning
9
9
 
10
10
  Usage:
11
-
11
+
12
12
  gfsm <command> [<args>]
13
13
 
14
14
  Available commands:
@@ -32,7 +32,7 @@ module GFSM
32
32
  GFSM::Output.puts(version)
33
33
  when 'current'
34
34
  settings = GFSM::Tools::VersionBumperSettings.new(args)
35
- version = GFSM::Tools::CurrentVersionLoader.load_current_version(settings.repository)
35
+ version = GFSM::Tools::CurrentVersionLoader.load_current_version(settings.repository, settings.initial_version)
36
36
 
37
37
  if settings.prerelease
38
38
  version.add_prerelease_suffix!(settings.prerelease_name)
@@ -6,10 +6,10 @@ require_relative '../data/version'
6
6
  module GFSM
7
7
  module Tools
8
8
  class CurrentVersionLoader
9
- def self.load_current_version(repo)
9
+ def self.load_current_version(repo, initial_version)
10
10
  last_tag_name = GFSM::Tools::GitUtilities.extract_last_tag_name(repo)
11
11
 
12
- return GFSM::Data::Version.new("0.0.0") unless last_tag_name
12
+ return GFSM::Data::Version.new(initial_version) unless last_tag_name
13
13
 
14
14
  if last_tag_name.downcase.start_with?("v")
15
15
  last_tag_name.slice!(0)
@@ -7,7 +7,7 @@ module GFSM
7
7
  module Tools
8
8
 
9
9
  class VersionBumperSettings
10
- attr_reader :repository, :configuration, :force, :force_version, :prerelease, :prerelease_name, :from, :to
10
+ attr_reader :repository, :configuration, :force, :force_version, :prerelease, :prerelease_name, :from, :to, :initial_version
11
11
 
12
12
  def initialize(cli_args)
13
13
  @repository = GFSM::Tools::GitUtilities.load_repo(get_repository_path(cli_args))
@@ -18,6 +18,7 @@ module GFSM
18
18
  @prerelease_name = get_prerelease_name(cli_args)
19
19
  @from = get_from(cli_args)
20
20
  @to = get_to(cli_args)
21
+ @initial_version = get_initial_version(cli_args)
21
22
  @from = GFSM::Tools::GitUtilities.extract_last_tag_name(@repository) if @from.nil?
22
23
  end
23
24
 
@@ -32,6 +33,7 @@ module GFSM
32
33
  --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
34
  --configuration <path> # Path to the configuration YAML file
34
35
  --path <path> # Path to the repository. By default will use the current directory
36
+ --initial-version <x.y.z> # Version to use when no existing version is found, useful when initializing the first one
35
37
  OPTIONS
36
38
 
37
39
  environment_variables = <<~ENVVARS
@@ -43,10 +45,11 @@ module GFSM
43
45
  REPOSITORY_PATH # Equivalent to --path
44
46
  FROM_COMMIT # Equivalent to --from
45
47
  TO_COMMIT # Equivalent to --to
48
+ INITIAL_VERSION # Equivalent to --initial-version
46
49
  ENVVARS
47
50
 
48
51
  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]",
52
+ 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] [--initial-version <x.y.z>]",
50
53
  options: options,
51
54
  environment_variables: environment_variables
52
55
  }
@@ -88,6 +91,10 @@ module GFSM
88
91
  def get_to(args)
89
92
  extract_switch_value(args, "--to", "HEAD", "TO_COMMIT")
90
93
  end
94
+
95
+ def get_initial_version(args)
96
+ extract_switch_value(args, "--initial-version", "0.0.0", "INITIAL_VERSION")
97
+ end
91
98
  end
92
99
 
93
100
  class VersionBumper
@@ -100,7 +107,7 @@ module GFSM
100
107
  def execute
101
108
  changelog_commits = GFSM::Tools::GitUtilities.extract_commits_with_changelog_trailer(@settings.repository, @settings.from, @settings.to)
102
109
 
103
- @version = GFSM::Tools::CurrentVersionLoader.load_current_version(@settings.repository)
110
+ @version = GFSM::Tools::CurrentVersionLoader.load_current_version(@settings.repository, @settings.initial_version)
104
111
  @subdivisions = GFSM::Tools::CommitsSubdivider.subdivide_commits(@settings.configuration, changelog_commits)
105
112
 
106
113
  if !@subdivisions || @subdivisions.empty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gfsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zille Marco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-25 00:00:00.000000000 Z
11
+ date: 2024-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml
@@ -65,7 +65,6 @@ files:
65
65
  - ".gitignore"
66
66
  - ".gitlab-ci.yml"
67
67
  - ".tool-versions"
68
- - ".version"
69
68
  - ".vscode/launch.json"
70
69
  - Dockerfile
71
70
  - Gemfile
data/.version DELETED
@@ -1 +0,0 @@
1
- 0.5.0