Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ also run `bin/console` for an interactive prompt that will allow you to experime

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
version number in `version.rb`, ensure the CHANGELOG.md is updated and that everything is committed.
Then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push
the `.gem` file to [rubygems.org](https://rubygems.org).
Then run `bundle exec rake release`, which will create a git tag for the version, then push git commits and tags to GitHub.

## Contributing

Expand Down
56 changes: 49 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
# frozen_string_literal: true

# We add preflight to the release task pre-requisites before loading in the
# bundler/gem_tasks to ensure that it runs first. This is becuase 'release' is
# bundler/gem_tasks to ensure that it runs first. This is because 'release' is
# actually composed entirely of pre-requisites and so would otherwise end up
# running the pre-flight tasks AFTER everything else
task release: :preflight

require 'bundler/gem_tasks'
require 'rainbow/refinement'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

using Rainbow

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new

task default: %i[rubocop spec]

desc 'Runs the preflight checklist before building a release'
task :preflight do
puts '🛫 Preflight checklist'
puts '──────────────────────'.bright
puts '🛫 Preflight checklist'.bright
puts '──────────────────────'.bright

current_version = RecordLoader::VERSION
latest_changelog_entry = File.read('CHANGELOG.md').scan(/^## \[(.*?)\]/).flatten.first
latest_master = latest_master?

puts 'This is still a manual process, but before we roll a release, lets confirm a few things:'
puts 'Before we roll a release, lets confirm a few things:'
puts
puts "▢ Has the gem version been updated? Currently #{st(current_version)} in #{p('lib/record_loader/version.rb')} "
puts "▢ Has the changelog been updated? Latest entry is #{st(latest_changelog_entry)} in #{p('CHANGELOG.md')}"
puts "▢ Are all changes committed to git? #{yn(uncommitted_changes?)}"
puts "▢ Are you on master and up to date? #{yn(on_master? & latest_master)}"
puts
puts "☐ lib/record_loader/version.rb updated? Currently contains #{current_version}"
puts '☐ CHANGELOG.md updated'
puts '☐ Commited, on master and up to date'
puts 'Proceeding will package the gem, create a git tag for the version, push commits and tags to GitHub, and push the .gem file to rubygems.org.'.italic
puts 'We do not currently have an accessible team account on rubygems.org, so this final step can be skipped.'.italic
puts
print 'Proceed Y/N > '
print 'Proceed [y/N] > '

proceed = $stdin.gets.chomp

Expand All @@ -38,3 +49,34 @@ task :preflight do
exit 1
end
end

private

# Highlight the provided path in cyan for better visibility in the terminal
def p(path)
Rainbow(path).bright.cyan
end

# Highlight the provided status in white for better visibility in the terminal
def st(status)
Rainbow(status).bright.white
end

# Given a boolean value, return Yes or No, or 'N/A' if the value is nil
def yn(value)
return 'N/A' if value.nil?

value ? 'Yes'.bright.green : 'No'.bright.red
end

def uncommitted_changes?
`git status --porcelain`.empty?
end

def on_master?
`git rev-parse --abrev-ref HEAD`.chomp == 'master'
end

def latest_master?
!`git remote show origin | grep "pushes to master" | grep "(up to date)"`.empty?
end