Skip to content

Commit ca08e18

Browse files
authored
Make a smart CI so that it would bump the version only if there is such a need (#57)
1 parent e1063b2 commit ca08e18

File tree

7 files changed

+79
-25
lines changed

7 files changed

+79
-25
lines changed

.github/workflows/bump.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: bundle install
2121

2222
- name: bump
23-
run: bundle exec rake bump
23+
run: bundle exec rake ci:bump_pathc_version
2424

2525
- name: Commit changes
2626
uses: EndBug/add-and-commit@v9

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ gem 'pry-byebug', '~> 3.10', '>= 3.10.1'
2121

2222
group :development do
2323
gem 'dotenv', '~> 3.1', '>= 3.1.2'
24+
gem 'git', '~> 2.1', '>= 2.1.1'
2425
gem 'rack-test', '~> 2.1'
2526
gem 'rspec', '~> 3.13'
2627
gem 'rubocop', '~> 1.65'

Gemfile.lock

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
activesupport (7.2.1)
5+
base64
6+
bigdecimal
7+
concurrent-ruby (~> 1.0, >= 1.3.1)
8+
connection_pool (>= 2.2.5)
9+
drb
10+
i18n (>= 1.6, < 2)
11+
logger (>= 1.4.2)
12+
minitest (>= 5.1)
13+
securerandom (>= 0.3)
14+
tzinfo (~> 2.0, >= 2.0.5)
415
addressable (2.8.7)
516
public_suffix (>= 2.0.2, < 7.0)
617
ast (2.4.2)
@@ -13,20 +24,29 @@ GEM
1324
concurrent-ruby (1.3.3)
1425
config (5.5.1)
1526
deep_merge (~> 1.2, >= 1.2.1)
27+
connection_pool (2.4.1)
1628
crack (1.0.0)
1729
bigdecimal
1830
rexml
1931
deep_merge (1.2.2)
2032
diff-lcs (1.5.1)
2133
dotenv (3.1.2)
34+
drb (2.2.1)
2235
faraday (2.10.1)
2336
faraday-net_http (>= 2.0, < 3.2)
2437
logger
2538
faraday-net_http (3.1.1)
2639
net-http
2740
ffi (1.17.0)
2841
ffi (1.17.0-x86_64-linux-gnu)
42+
git (2.1.1)
43+
activesupport (>= 5.0)
44+
addressable (~> 2.8)
45+
process_executer (~> 1.1)
46+
rchardet (~> 1.8)
2947
hashdiff (1.1.1)
48+
i18n (1.14.5)
49+
concurrent-ruby (~> 1.0)
3050
ipaddr (1.2.6)
3151
json (2.7.2)
3252
json-schema (4.3.1)
@@ -37,6 +57,7 @@ GEM
3757
rb-inotify (~> 0.9, >= 0.9.10)
3858
logger (1.6.0)
3959
method_source (1.1.0)
60+
minitest (5.25.1)
4061
multi_json (1.15.0)
4162
mustermann (3.0.0)
4263
ruby2_keywords (~> 0.0.1)
@@ -50,6 +71,7 @@ GEM
5071
racc
5172
patience_diff (1.2.0)
5273
optimist (~> 3.0)
74+
process_executer (1.1.0)
5375
pry (0.14.2)
5476
coderay (~> 1.1)
5577
method_source (~> 1.0)
@@ -73,6 +95,7 @@ GEM
7395
rb-fsevent (0.11.2)
7496
rb-inotify (0.11.1)
7597
ffi (~> 1.0)
98+
rchardet (1.8.0)
7699
regexp_parser (2.9.2)
77100
rerun (0.14.0)
78101
listen (~> 3.0)
@@ -115,6 +138,7 @@ GEM
115138
ruby-progressbar (1.13.0)
116139
ruby-units (4.0.3)
117140
ruby2_keywords (0.0.5)
141+
securerandom (0.3.1)
118142
sentry-ruby (5.18.2)
119143
bigdecimal
120144
concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -138,6 +162,8 @@ GEM
138162
diff-lcs
139163
patience_diff
140164
tilt (2.3.0)
165+
tzinfo (2.0.6)
166+
concurrent-ruby (~> 1.0)
141167
unicode-display_width (2.5.0)
142168
uri (0.13.0)
143169
webmock (3.23.1)
@@ -155,6 +181,7 @@ DEPENDENCIES
155181
config (~> 5.5)
156182
dotenv (~> 3.1, >= 3.1.2)
157183
faraday (~> 2.10, >= 2.10.1)
184+
git (~> 2.1, >= 2.1.1)
158185
ipaddr (~> 1.2, >= 1.2.6)
159186
json-schema (~> 4.3)
160187
pry-byebug (~> 3.10, >= 3.10.1)

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Config.load_and_set_settings("config/settings/#{env}.yaml")
1919

2020
require_relative 'config/application'
2121

22-
Dir.glob('tasks/*.rake').each do |file|
22+
Dir.glob('tasks/**/*.rake').each do |file|
2323
load file
2424
end
2525

tasks/bump.rake

-11
This file was deleted.

tasks/bump_minor.rake

-12
This file was deleted.

tasks/ci/bump_new_version.rake

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
require 'git'
4+
5+
module CI
6+
# Class for bump version in CI
7+
class Bumper
8+
def initialize
9+
repo = Git.open('.')
10+
@commit = repo.log.first
11+
end
12+
13+
def bump?
14+
commit.diff_parent.name_status.each_key do |file|
15+
return false if file == 'VERSION'
16+
17+
path = file.split('/').first
18+
case path
19+
when 'lib', 'app', 'config', 'tasks', 'app.rb', 'config.ru', 'Dockerfile'
20+
return true
21+
end
22+
end
23+
24+
false
25+
end
26+
27+
def bump_pathc_version
28+
version = File.read('VERSION').gsub('v', '')
29+
semver = version.split('.')
30+
new_pathc = semver.last.to_i + 1
31+
semver[2] = new_pathc.to_s
32+
new_version = "v#{semver.join('.')}"
33+
File.write('VERSION', new_version)
34+
end
35+
36+
private
37+
38+
attr_reader :commit
39+
end
40+
end
41+
42+
namespace :ci do
43+
desc 'bump pathc version'
44+
task :bump_pathc_version do
45+
bumper = CI::Bumper.new
46+
47+
bumper.bump_pathc_version if bumper.bump?
48+
end
49+
end

0 commit comments

Comments
 (0)