diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml index ab4c1d5..5fd982c 100644 --- a/.github/workflows/bump.yml +++ b/.github/workflows/bump.yml @@ -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 diff --git a/Gemfile b/Gemfile index 62b25db..e7169b6 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index e9b6931..94ef6bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -13,12 +24,14 @@ 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 @@ -26,7 +39,14 @@ GEM 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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/Rakefile b/Rakefile index 754783f..6c31ef3 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/tasks/bump.rake b/tasks/bump.rake deleted file mode 100644 index c7fed74..0000000 --- a/tasks/bump.rake +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -desc 'bump pathc version' -task :bump do - 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 diff --git a/tasks/bump_minor.rake b/tasks/bump_minor.rake deleted file mode 100644 index a64765a..0000000 --- a/tasks/bump_minor.rake +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -desc 'bump minor vesrion' -task :bump_minor do - version = File.read('VERSION').gsub('v', '') - semver = version.split('.') - new_pathc = semver[1].to_i + 1 - semver[1] = new_pathc.to_s - semver[2] = '0' - new_version = "v#{semver.join('.')}" - File.write('VERSION', new_version) -end diff --git a/tasks/ci/bump_new_version.rake b/tasks/ci/bump_new_version.rake new file mode 100644 index 0000000..e4c9397 --- /dev/null +++ b/tasks/ci/bump_new_version.rake @@ -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