-
-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathrelease.rake
93 lines (71 loc) · 3.51 KB
/
release.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true
require "bundler"
require_relative "task_helpers"
require_relative File.join(gem_root, "lib", "react_on_rails", "version_syntax_converter")
require_relative File.join(gem_root, "lib", "react_on_rails", "git_utils")
require_relative File.join(gem_root, "lib", "react_on_rails", "utils")
class RaisingMessageHandler
def add_error(error)
raise error
end
end
# rubocop:disable Metrics/BlockLength
desc("Releases both the gem and node package using the given version.
IMPORTANT: the gem version must be in valid rubygem format (no dashes).
It will be automatically converted to a valid yarn semver by the rake task
for the node package version. This only makes a difference for pre-release
versions such as `3.0.0.beta.1` (yarn version would be `3.0.0-beta.1`).
This task depends on the gem-release (ruby gem) and release-it (node package)
which are installed via `bundle install` and `yarn global add release-it`
1st argument: The new version in rubygem format (no dashes). Pass no argument to
automatically perform a patch version bump.
2nd argument: Perform a dry run by passing 'true' as a second argument.
Note, accept defaults for npmjs options. Script will pause to get 2FA tokens.
Example: `rake release[2.1.0,false]`")
task :release, %i[gem_version dry_run tools_install] do |_t, args|
include ReactOnRails::TaskHelpers
# Check if there are uncommitted changes
ReactOnRails::GitUtils.uncommitted_changes?(RaisingMessageHandler.new)
args_hash = args.to_hash
is_dry_run = ReactOnRails::Utils.object_to_boolean(args_hash[:dry_run])
gem_version = args_hash.fetch(:gem_version, "")
npm_version = if gem_version.strip.empty?
""
else
ReactOnRails::VersionSyntaxConverter.new.rubygem_to_npm(gem_version)
end
# Having the examples prevents publishing
Rake::Task["shakapacker_examples:clobber"].invoke
Rake::Task["webpacker_examples:clobber"].invoke
# Delete any react_on_rails.gemspec except the root one
sh_in_dir(gem_root, "find . -mindepth 2 -name 'react_on_rails.gemspec' -delete")
# See https://github.com/svenfuchs/gem-release
sh_in_dir(gem_root, "git pull --rebase")
sh_in_dir(gem_root, "gem bump --no-commit #{gem_version.strip.empty? ? '' : %(--version #{gem_version})}")
# Update dummy app's Gemfile.lock
bundle_install_in(dummy_app_dir)
puts "Carefully add your OTP for NPM. If you get an error, 'git reset --hard' and start over."
# Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
release_it_command = +"release-it"
release_it_command << " #{npm_version}" unless npm_version.strip.empty?
release_it_command << " --npm.publish --no-git.requireCleanWorkingDir"
release_it_command << " --dry-run --verbose" if is_dry_run
sh_in_dir(gem_root, release_it_command)
# Release the new gem version
puts "Carefully add your OTP for Rubygems. If you get an error, run 'gem release' again."
sh_in_dir(gem_root, "gem release") unless is_dry_run
msg = <<~MSG
Once you have successfully published, run these commands to update the spec apps:
cd #{dummy_app_dir}; bundle update react_on_rails
cd #{gem_root}#{' '}
git commit -a -m 'Update Gemfile.lock for spec app'
git push
MSG
puts msg
end
# rubocop:enable Metrics/BlockLength
task :test do
unbundled_sh_in_dir(gem_root, "cd #{dummy_app_dir}; bundle update react_on_rails")
sh_in_dir(gem_root, "git commit -a -m 'Update Gemfile.lock for spec app'")
sh_in_dir(gem_root, "git push")
end