Created
June 22, 2023 17:05
-
-
Save aseroff/f38a93ca71b6778bd3a89150a2055ce3 to your computer and use it in GitHub Desktop.
rake tasks for versioning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
if Rails.env.development? | |
require 'rails-erd' | |
require 'yard' | |
namespace :docs do | |
desc 'updates documentation' | |
task all: :environment do | |
Rake::Task['docs:yard'].invoke | |
end | |
namespace :release do | |
desc 'updates version and docs for patch release' | |
task patch: :environment do | |
Rake::Task['docs:version:patch'].invoke | |
Rake::Task['docs:all'].invoke | |
end | |
desc 'updates version and docs for minor release' | |
task minor: :environment do | |
Rake::Task['docs:version:minor'].invoke | |
Rake::Task['docs:all'].invoke | |
end | |
desc 'updates version and docs for major release' | |
task major: :environment do | |
Rake::Task['docs:version:major'].invoke | |
Rake::Task['docs:all'].invoke | |
end | |
end | |
namespace :version do | |
desc 'bumps version to next patch number' | |
task patch: :environment do | |
version = `git describe --tags --always`.split('-')[0].split('.') | |
version = (version[..-2] + [(version[-1].to_i + 1)]).join('.') | |
puts "Version bumped to #{version}" if version != Rails.application.config.version && Rails.root.join('config', 'version').open('w') { |file| file.write version }.positive? | |
end | |
desc 'bumps version to next minor number' | |
task minor: :environment do | |
version = `git describe --tags --always`.split('-')[0].split('.') | |
version = [version[0], (version[1].to_i + 1), 0].join('.') | |
puts "Version bumped to #{version}" if version != Rails.application.config.version && Rails.root.join('config', 'version').open('w') { |file| file.write version }.positive? | |
end | |
desc 'bumps version to next major number' | |
task major: :environment do | |
version = `git describe --tags --always`.split('-')[0].split('.') | |
version = "v#{([(version[0][1..].to_i + 1)] + [0, 0]).join('.')}" | |
puts "Version bumped to #{version}" if version != Rails.application.config.version && Rails.root.join('config', 'version').open('w') { |file| file.write version }.positive? | |
end | |
end | |
YARD::Rake::YardocTask.new do |t| | |
t.options = ['-odocs', '-rREADME.md'] | |
t.stats_options = ['--list-undoc'] | |
end | |
end | |
Rake::Task['docs:yard'].enhance do | |
return unless Rails.env.development? | |
RailsERD.load_tasks | |
end | |
desc 'runs all documentation tasks' | |
task docs: :environment do | |
Rake::Task['docs:all'].invoke | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment