Skip to content

Commit

Permalink
Make a smart CI so that it would bump the version only if there is su…
Browse files Browse the repository at this point in the history
…ch a need (#57)
  • Loading branch information
leonovk authored Aug 24, 2024
1 parent e1063b2 commit ca08e18
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: bundle install

- name: bump
run: bundle exec rake bump
run: bundle exec rake ci:bump_pathc_version

- name: Commit changes
uses: EndBug/add-and-commit@v9
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gem 'pry-byebug', '~> 3.10', '>= 3.10.1'

group :development do
gem 'dotenv', '~> 3.1', '>= 3.1.2'
gem 'git', '~> 2.1', '>= 2.1.1'
gem 'rack-test', '~> 2.1'
gem 'rspec', '~> 3.13'
gem 'rubocop', '~> 1.65'
Expand Down
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
Expand All @@ -13,20 +24,29 @@ GEM
concurrent-ruby (1.3.3)
config (5.5.1)
deep_merge (~> 1.2, >= 1.2.1)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
deep_merge (1.2.2)
diff-lcs (1.5.1)
dotenv (3.1.2)
drb (2.2.1)
faraday (2.10.1)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-net_http (3.1.1)
net-http
ffi (1.17.0)
ffi (1.17.0-x86_64-linux-gnu)
git (2.1.1)
activesupport (>= 5.0)
addressable (~> 2.8)
process_executer (~> 1.1)
rchardet (~> 1.8)
hashdiff (1.1.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
ipaddr (1.2.6)
json (2.7.2)
json-schema (4.3.1)
Expand All @@ -37,6 +57,7 @@ GEM
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
method_source (1.1.0)
minitest (5.25.1)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
Expand All @@ -50,6 +71,7 @@ GEM
racc
patience_diff (1.2.0)
optimist (~> 3.0)
process_executer (1.1.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -73,6 +95,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rchardet (1.8.0)
regexp_parser (2.9.2)
rerun (0.14.0)
listen (~> 3.0)
Expand Down Expand Up @@ -115,6 +138,7 @@ GEM
ruby-progressbar (1.13.0)
ruby-units (4.0.3)
ruby2_keywords (0.0.5)
securerandom (0.3.1)
sentry-ruby (5.18.2)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand All @@ -138,6 +162,8 @@ GEM
diff-lcs
patience_diff
tilt (2.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
webmock (3.23.1)
Expand All @@ -155,6 +181,7 @@ DEPENDENCIES
config (~> 5.5)
dotenv (~> 3.1, >= 3.1.2)
faraday (~> 2.10, >= 2.10.1)
git (~> 2.1, >= 2.1.1)
ipaddr (~> 1.2, >= 1.2.6)
json-schema (~> 4.3)
pry-byebug (~> 3.10, >= 3.10.1)
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Config.load_and_set_settings("config/settings/#{env}.yaml")

require_relative 'config/application'

Dir.glob('tasks/*.rake').each do |file|
Dir.glob('tasks/**/*.rake').each do |file|
load file
end

Expand Down
11 changes: 0 additions & 11 deletions tasks/bump.rake

This file was deleted.

12 changes: 0 additions & 12 deletions tasks/bump_minor.rake

This file was deleted.

49 changes: 49 additions & 0 deletions tasks/ci/bump_new_version.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require 'git'

module CI
# Class for bump version in CI
class Bumper
def initialize
repo = Git.open('.')
@commit = repo.log.first
end

def bump?
commit.diff_parent.name_status.each_key do |file|
return false if file == 'VERSION'

path = file.split('/').first
case path
when 'lib', 'app', 'config', 'tasks', 'app.rb', 'config.ru', 'Dockerfile'
return true
end
end

false
end

def bump_pathc_version
version = File.read('VERSION').gsub('v', '')
semver = version.split('.')
new_pathc = semver.last.to_i + 1
semver[2] = new_pathc.to_s
new_version = "v#{semver.join('.')}"
File.write('VERSION', new_version)
end

private

attr_reader :commit
end
end

namespace :ci do
desc 'bump pathc version'
task :bump_pathc_version do
bumper = CI::Bumper.new

bumper.bump_pathc_version if bumper.bump?
end
end

0 comments on commit ca08e18

Please sign in to comment.