gfsm 0.5.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +23 -0
- data/README.md +146 -35
- data/lib/commands/version.rb +1 -1
- data/lib/tools/current_version_loader.rb +2 -2
- data/lib/tools/version_bumper.rb +32 -5
- metadata +2 -3
- data/.version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: accb61758c5e95e2715a20c9e2ca48a021539314dea1e9a122efc7b605486554
|
4
|
+
data.tar.gz: 7414ee6f86661bd4854683d74fb8155a1485cf593ecf2eec5e17835ea236d2c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7628471e0f7b4b0514ab000575632b735bd8e47a6ef694a48f3c2dfcd7a25761b77f86044ac01d37279de6765f05cec7a99e91c44713216097900ed881b47c56
|
7
|
+
data.tar.gz: dd44e1c57962580accbfed793e34519ee05fb680a9c4a4f9c58f144c85c2abee12371f3b12f7c15d8eb70bc05f1705fa25a106695eaed21fb82bd2fd5a20147f
|
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
|
@@ -76,6 +83,14 @@ Upload docker image:
|
|
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/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# GitLab Flavored Semantic
|
1
|
+
# GitLab Flavored Semantic Versioning
|
2
2
|
|
3
|
-
|
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
|
-
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
77
|
+
**Important**: `git` must be avaiable on the system for the gem to work.
|
72
78
|
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
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
|
-
|
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
|
+
```
|
data/lib/commands/version.rb
CHANGED
@@ -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(
|
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)
|
data/lib/tools/version_bumper.rb
CHANGED
@@ -7,17 +7,18 @@ 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))
|
14
14
|
@configuration = GFSM::Data::Configuration.new(get_configuration_file_path(cli_args))
|
15
|
-
@force =
|
15
|
+
@force = get_force(cli_args)
|
16
16
|
@force_version = get_force_version(cli_args)
|
17
|
-
@prerelease =
|
17
|
+
@prerelease = get_prerelease(cli_args)
|
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
|
}
|
@@ -65,9 +68,29 @@ module GFSM
|
|
65
68
|
args[switch_index + 1]
|
66
69
|
end
|
67
70
|
|
71
|
+
def extract_boolean_value(args, switch, default_value, env_name = nil)
|
72
|
+
if ENV.has_key?(env_name)
|
73
|
+
return ENV.fetch(env_name) == "true"
|
74
|
+
end
|
75
|
+
|
76
|
+
switch_index = args.find_index(switch)
|
77
|
+
|
78
|
+
return default_value unless switch_index
|
79
|
+
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_force(args)
|
84
|
+
extract_boolean_value(args, "--force", false, "FORCE_BUMP")
|
85
|
+
end
|
86
|
+
|
68
87
|
def get_configuration_file_path(args)
|
69
88
|
extract_switch_value(args, "--configuration", "./gfsmrc.yml", "CONFIGURATION_FILE")
|
70
89
|
end
|
90
|
+
|
91
|
+
def get_prerelease(args)
|
92
|
+
extract_boolean_value(args, "--prerelease", false, "PRERELEASE")
|
93
|
+
end
|
71
94
|
|
72
95
|
def get_prerelease_name(args)
|
73
96
|
extract_switch_value(args, "--prerelease-name", "pre", "PRERELEASE_NAME")
|
@@ -88,6 +111,10 @@ module GFSM
|
|
88
111
|
def get_to(args)
|
89
112
|
extract_switch_value(args, "--to", "HEAD", "TO_COMMIT")
|
90
113
|
end
|
114
|
+
|
115
|
+
def get_initial_version(args)
|
116
|
+
extract_switch_value(args, "--initial-version", "0.0.0", "INITIAL_VERSION")
|
117
|
+
end
|
91
118
|
end
|
92
119
|
|
93
120
|
class VersionBumper
|
@@ -100,7 +127,7 @@ module GFSM
|
|
100
127
|
def execute
|
101
128
|
changelog_commits = GFSM::Tools::GitUtilities.extract_commits_with_changelog_trailer(@settings.repository, @settings.from, @settings.to)
|
102
129
|
|
103
|
-
@version = GFSM::Tools::CurrentVersionLoader.load_current_version(@settings.repository)
|
130
|
+
@version = GFSM::Tools::CurrentVersionLoader.load_current_version(@settings.repository, @settings.initial_version)
|
104
131
|
@subdivisions = GFSM::Tools::CommitsSubdivider.subdivide_commits(@settings.configuration, changelog_commits)
|
105
132
|
|
106
133
|
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2024-09-04 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.1
|