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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ccdfca4c117dd359cdd7ad0b93c9ea99b47551cb8edc4028c680b75acc0dddc
4
- data.tar.gz: e0959ca04f31bcaafb6643bdd248721814ac831e15225033280d6e97ad1f4ba3
3
+ metadata.gz: f1328d98b44c0777e42445b9ef8f67b9b88e37d8a7bdc517a3e6393b2543d2a3
4
+ data.tar.gz: 5ee4cf826f1c4b608bad7f58193db6c744e4c33868f31c5b477994a475bc69d6
5
5
  SHA512:
6
- metadata.gz: 6f0ac6843c7a75407273d2d3826f3a2bf4aa24576bb35e3969591a2397b29935ce2e0541d91c05dd77adc5f6fce67e3a2b6f9c31294ce5a464e7e845b7eb9b68
7
- data.tar.gz: 6f5dc0b736a34b8be9a25420a9d8b405cc87693ce954451ed6d287241798dc5473ede1b885b9c868c2529486d4ee4cfe6159a02bc2a3f273c13fef90d93461dd
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
@@ -0,0 +1,7 @@
1
+ FROM ruby:2.7.5-alpine3.15
2
+
3
+ RUN gem install gfsm
4
+
5
+ COPY ./gfsmrc.yml ./gfsmrc.yml
6
+
7
+ ENTRYPOINT [""]
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
- There are two ways to run this tool locally at the moment:
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
- ./bin/gfsm [args]
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.
@@ -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 |change_type, commits|
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|
@@ -18,7 +18,7 @@ module GFSM
18
18
  end
19
19
  end
20
20
 
21
- @change_types.sort_by! { |change_type| change_type.priority }.reverse!
21
+ @change_types
22
22
  end
23
23
 
24
24
  def get_change_type_from_category(category)
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/version_bumper'
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
- repo = Git.open(repo_path)
11
-
12
- begin
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 CommitsExtractor
7
+ class GitUtilities
8
8
  CHANGELOG_TRAILER_REGEX = /^(?<name>Changelog):\s*(?<category>.+)$/i
9
9
 
10
- def self.extract_commits_with_changelog_trailer(repo_path = ".")
11
- repo = Git.open(repo_path)
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
- last_tag_name = repo.describe(nil, { abbrev: 0 })
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
@@ -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::CommitsExtractor.extract_commits_with_changelog_trailer(repository_path)
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
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-07-04 00:00:00.000000000 Z
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