Skip to content

Commit cd17a0d

Browse files
committed
Fix release task to commit version bump before gem release
The gem bump command modifies the version file but the --no-commit flag means it doesn't commit it. This causes gem release to fail because it expects a clean working directory. This commit adds git commands to stage and commit the version file after bumping but before releasing the gem.
1 parent 5e4041d commit cd17a0d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

rakelib/release.rake

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,32 @@ task :release, %i[gem_version dry_run] do |_t, args|
4040

4141
# See https://github.com/svenfuchs/gem-release
4242
sh_in_dir(gem_root, "git pull --rebase")
43-
sh_in_dir(gem_root, "gem bump --no-commit --file lib/cypress_on_rails/version.rb #{gem_version.strip.empty? ? '' : %(-v #{gem_version})}")
43+
sh_in_dir(gem_root, "gem bump --no-commit --file lib/cypress_on_rails/version.rb #{gem_version.strip.empty? ? '' : %(--version #{gem_version})}")
4444

45-
# Release the new gem version
46-
puts "Carefully add your OTP for Rubygems. If you get an error, run 'gem release' again."
47-
sh_in_dir(gem_root, "gem release") unless is_dry_run
45+
# Read the actual version from the file after bump
46+
require_relative "../lib/cypress_on_rails/version"
47+
actual_version = CypressOnRails::VERSION
48+
49+
# Update Gemfile.lock files
50+
sh_in_dir(gem_root, "bundle install")
51+
52+
unless is_dry_run
53+
# Commit the version bump and Gemfile.lock update
54+
sh_in_dir(gem_root, "git add -A")
55+
sh_in_dir(gem_root, "git commit -m \"Release v#{actual_version}\"")
56+
57+
# Tag the release
58+
sh_in_dir(gem_root, "git tag v#{actual_version}")
59+
60+
# Push the commit and tag
61+
sh_in_dir(gem_root, "git push && git push --tags")
62+
63+
# Release the new gem version
64+
puts "Carefully add your OTP for Rubygems. If you get an error, run 'gem release' again."
65+
sh_in_dir(gem_root, "gem release")
66+
else
67+
puts "DRY RUN: Would have committed, tagged v#{actual_version}, pushed, and released gem"
68+
end
4869

4970
msg = <<~MSG
5071
Once you have successfully published, run these commands to update CHANGELOG.md:

0 commit comments

Comments
 (0)