gfsm 0.1.4 → 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/.gitlab-ci.yml +17 -0
- data/Dockerfile +7 -0
- data/README.md +40 -3
- data/lib/commands/changelog.rb +6 -2
- data/lib/data/configuration.rb +1 -1
- data/lib/gfsm.rb +2 -2
- data/lib/tools/current_version_loader.rb +3 -7
- data/lib/tools/{commits_extractor.rb → git_utilities.rb} +16 -5
- data/lib/tools/version_bumper.rb +3 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1328d98b44c0777e42445b9ef8f67b9b88e37d8a7bdc517a3e6393b2543d2a3
|
4
|
+
data.tar.gz: 5ee4cf826f1c4b608bad7f58193db6c744e4c33868f31c5b477994a475bc69d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50c2d64b74ed354024fffb5825c28e309e9ddfcdd99889613b2c12cbef85f4ee32cae3c3089e8e5a466bfc0c7abd150d1398c9a3f13bc57df81472ff57640c59
|
7
|
+
data.tar.gz: 178a21e2f2212bc7427bb0ac4b894ae83b4b3846ed1e9bd2b29287ba30500012397a69bdc77f8d408020ca055891f495bad7774a40a18c5d66ff63928ae8faf6
|
data/.gitlab-ci.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
stages:
|
2
2
|
- version
|
3
3
|
- deploy
|
4
|
+
- docker
|
4
5
|
- release
|
5
6
|
|
6
7
|
workflow:
|
@@ -56,6 +57,20 @@ Publish gem:
|
|
56
57
|
when: never
|
57
58
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
58
59
|
|
60
|
+
Upload docker image:
|
61
|
+
stage: docker
|
62
|
+
image: docker:20.10.16
|
63
|
+
services:
|
64
|
+
- docker:20.10.16-dind
|
65
|
+
script:
|
66
|
+
- 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
|
69
|
+
rules:
|
70
|
+
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
|
71
|
+
when: never
|
72
|
+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
73
|
+
|
59
74
|
Create release:
|
60
75
|
stage: release
|
61
76
|
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
@@ -67,6 +82,8 @@ Create release:
|
|
67
82
|
artifacts: true
|
68
83
|
- job: "Publish gem"
|
69
84
|
artifacts: false
|
85
|
+
- job: "Upload docker image"
|
86
|
+
artifacts: false
|
70
87
|
rules:
|
71
88
|
- if: '$GEM_HOST_API_KEY == null'
|
72
89
|
when: never
|
data/Dockerfile
ADDED
data/README.md
CHANGED
@@ -56,8 +56,45 @@ At the moment there's no built-in testing platform, but I'm planning to use `rsp
|
|
56
56
|
|
57
57
|
### Using
|
58
58
|
|
59
|
-
|
59
|
+
This project is available as a Ruby gem, so to be able to use it is enough to run
|
60
60
|
|
61
61
|
```shell
|
62
|
-
|
63
|
-
```
|
62
|
+
gem install gfsm
|
63
|
+
```
|
64
|
+
|
65
|
+
Once that command completes, the gem will be available and you can invoke it from the command line with
|
66
|
+
|
67
|
+
```shell
|
68
|
+
gfsm help
|
69
|
+
```
|
70
|
+
|
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.
|
72
|
+
|
73
|
+
In order to use is inside a CI job, the job itself could look something like this:
|
74
|
+
|
75
|
+
```yaml
|
76
|
+
stages:
|
77
|
+
- version
|
78
|
+
|
79
|
+
update-version:
|
80
|
+
stage: version
|
81
|
+
image: ruby:2.7.5
|
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
|
94
|
+
```
|
95
|
+
|
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
|
99
|
+
|
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.
|
data/lib/commands/changelog.rb
CHANGED
@@ -76,11 +76,15 @@ module GFSM
|
|
76
76
|
|
77
77
|
version_bumper = GFSM::Tools::VersionBumper.new()
|
78
78
|
version = version_bumper.compute_version!(force, prerelease, prerelease_name, repository_path, configuration_file_path)
|
79
|
-
subdivisions = version_bumper.subdivisions
|
79
|
+
subdivisions = version_bumper.subdivisions.to_a
|
80
|
+
subdivisions.sort_by! { |subdivision_data| subdivision_data[0].priority }.reverse!
|
80
81
|
|
81
82
|
changelog_entries = ""
|
82
83
|
|
83
|
-
subdivisions.each do |
|
84
|
+
subdivisions.each do |subdivision_data|
|
85
|
+
change_type = subdivision_data[0]
|
86
|
+
commits = subdivision_data[1]
|
87
|
+
|
84
88
|
changelog_entries += "\n#{change_type.to_changelog_entry}\n\n"
|
85
89
|
|
86
90
|
commits.each do |commit|
|
data/lib/data/configuration.rb
CHANGED
data/lib/gfsm.rb
CHANGED
@@ -7,11 +7,11 @@ require 'data/configuration'
|
|
7
7
|
require 'data/version'
|
8
8
|
|
9
9
|
# Load the tools
|
10
|
-
require 'tools/commits_extractor'
|
11
10
|
require 'tools/commits_subdivider'
|
12
11
|
require 'tools/current_version_loader'
|
13
|
-
require 'tools/
|
12
|
+
require 'tools/git_utilities'
|
14
13
|
require 'tools/output'
|
14
|
+
require 'tools/version_bumper'
|
15
15
|
|
16
16
|
# Load the commands
|
17
17
|
require 'commands/base_command'
|
@@ -7,13 +7,9 @@ module GFSM
|
|
7
7
|
module Tools
|
8
8
|
class CurrentVersionLoader
|
9
9
|
def self.load_current_version(repo_path = ".")
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
last_tag_name = repo.describe(nil, { abbrev: 0 })
|
14
|
-
rescue
|
15
|
-
last_tag_name = nil
|
16
|
-
end
|
10
|
+
last_tag_name = GFSM::Tools::GitUtilities.extract_last_tag_name(
|
11
|
+
GFSM::Tools::GitUtilities.load_repo(repo_path)
|
12
|
+
)
|
17
13
|
|
18
14
|
return GFSM::Data::Version.new("0.0.0") unless last_tag_name
|
19
15
|
|
@@ -4,17 +4,28 @@ require 'git'
|
|
4
4
|
|
5
5
|
module GFSM
|
6
6
|
module Tools
|
7
|
-
class
|
7
|
+
class GitUtilities
|
8
8
|
CHANGELOG_TRAILER_REGEX = /^(?<name>Changelog):\s*(?<category>.+)$/i
|
9
9
|
|
10
|
-
def self.
|
11
|
-
|
10
|
+
def self.load_repo(repo_path)
|
11
|
+
Git.open(repo_path)
|
12
|
+
end
|
12
13
|
|
14
|
+
def self.extract_last_tag_name(repo)
|
13
15
|
begin
|
14
|
-
|
16
|
+
current_sort_order = repo.config("tag.sort")
|
17
|
+
|
18
|
+
repo.config("tag.sort", "-v:refname")
|
19
|
+
tags = repo.tags
|
20
|
+
repo.config("tag.sort", current_sort_order)
|
21
|
+
|
22
|
+
tags[0].name if !tags.empty?
|
15
23
|
rescue
|
16
|
-
last_tag_name = nil
|
17
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.extract_commits_with_changelog_trailer(repo)
|
28
|
+
last_tag_name = self.extract_last_tag_name(repo)
|
18
29
|
|
19
30
|
begin
|
20
31
|
commits = last_tag_name ? repo.log.between(last_tag_name, 'HEAD') : repo.log
|
data/lib/tools/version_bumper.rb
CHANGED
@@ -10,7 +10,9 @@ module GFSM
|
|
10
10
|
|
11
11
|
def compute_version!(force, prerelease, prerelease_name, repository_path, configuration_file_path)
|
12
12
|
configuration = GFSM::Data::Configuration.new(configuration_file_path)
|
13
|
-
changelog_commits = GFSM::Tools::
|
13
|
+
changelog_commits = GFSM::Tools::GitUtilities.extract_commits_with_changelog_trailer(
|
14
|
+
GFSM::Tools::GitUtilities.load_repo(repository_path)
|
15
|
+
)
|
14
16
|
|
15
17
|
@version = GFSM::Tools::CurrentVersionLoader.load_current_version(repository_path)
|
16
18
|
@subdivisions = GFSM::Tools::CommitsSubdivider.subdivide_commits(configuration, changelog_commits)
|
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.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zille Marco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- ".gitlab-ci.yml"
|
66
66
|
- ".tool-versions"
|
67
67
|
- ".vscode/launch.json"
|
68
|
+
- Dockerfile
|
68
69
|
- Gemfile
|
69
70
|
- Gemfile.lock
|
70
71
|
- README.md
|
@@ -80,9 +81,9 @@ files:
|
|
80
81
|
- lib/data/configuration.rb
|
81
82
|
- lib/data/version.rb
|
82
83
|
- lib/gfsm.rb
|
83
|
-
- lib/tools/commits_extractor.rb
|
84
84
|
- lib/tools/commits_subdivider.rb
|
85
85
|
- lib/tools/current_version_loader.rb
|
86
|
+
- lib/tools/git_utilities.rb
|
86
87
|
- lib/tools/output.rb
|
87
88
|
- lib/tools/version_bumper.rb
|
88
89
|
homepage: https://gitlab.com/zillemarco/gitlab-flavored-semantic-versioning
|