Skip to content

Commit 8615fc7

Browse files
justin808claude
andcommitted
Refactor release task to match react_on_rails pattern
Simplified the release workflow to match react_on_rails approach: Changes: 1. Created rakelib/task_helpers.rb with TaskHelpers module 2. Rewrote release.rake to use single `rake release[version]` task 3. Removed namespace approach (release:prepare/publish) 4. Added RaisingMessageHandler for consistency with react_on_rails 5. Used TaskHelpers module with sh_in_dir and gem_root helpers 6. Fixed gem bump flag: --version to -v The workflow is now simpler and matches react_on_rails: - rake release[1.19.0] - Bumps, commits, tags, and publishes - rake release[1.19.0,true] - Dry run mode Removed npm/release-it parts from the react_on_rails version since cypress-on-rails is gem-only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 95f95cf commit 8615fc7

File tree

2 files changed

+66
-102
lines changed

2 files changed

+66
-102
lines changed

rakelib/release.rake

Lines changed: 51 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,59 @@
11
# frozen_string_literal: true
22

3-
namespace :release do
4-
desc "Prepare release: bump version and update changelog"
5-
task :prepare, [:version] do |_t, args|
6-
require_relative '../lib/cypress_on_rails/version'
7-
8-
version = args[:version]
9-
unless version
10-
puts "Usage: rake release:prepare[VERSION]"
11-
puts "Example: rake release:prepare[1.19.0]"
12-
exit 1
13-
end
14-
15-
unless version.match?(/^\d+\.\d+\.\d+$/)
16-
puts "Error: Version must be in format X.Y.Z (e.g., 1.19.0)"
17-
exit 1
18-
end
19-
20-
current_version = CypressOnRails::VERSION
21-
puts "Current version: #{current_version}"
22-
puts "New version: #{version}"
23-
24-
# Confirm the version bump
25-
print "Continue? (y/n): "
26-
response = $stdin.gets.chomp.downcase
27-
unless response == 'y'
28-
puts "Aborted."
29-
exit 0
30-
end
31-
32-
# Use gem bump to update version
33-
puts "\n→ Bumping version with gem-release..."
34-
unless system("gem bump -v #{version} --no-commit")
35-
puts "Error: Failed to bump version"
36-
exit 1
37-
end
38-
puts "✓ Updated version to #{version}"
39-
40-
# Update CHANGELOG
41-
update_changelog(version, current_version)
42-
43-
puts "\n✓ Version prepared!"
44-
puts "\nNext steps:"
45-
puts " 1. Review changes: git diff"
46-
puts " 2. Commit: git add -A && git commit -m 'Bump version to #{version}'"
47-
puts " 3. Push: git push origin master"
48-
puts " 4. Release: rake release:publish"
49-
end
3+
require "bundler"
4+
require_relative "task_helpers"
505

51-
desc "Publish release: tag, build, and push gem"
52-
task :publish do
53-
require_relative '../lib/cypress_on_rails/version'
54-
version = CypressOnRails::VERSION
55-
56-
# Pre-flight checks
57-
current_branch = `git rev-parse --abbrev-ref HEAD`.chomp
58-
unless current_branch == 'master'
59-
puts "Error: Must be on master branch to release (currently on #{current_branch})"
60-
exit 1
61-
end
62-
63-
if `git status --porcelain`.chomp != ''
64-
puts "Error: Working directory is not clean. Commit or stash changes first."
65-
exit 1
66-
end
67-
68-
puts "Preparing to release version #{version}..."
69-
70-
# Run tests
71-
puts "\n→ Running tests..."
72-
unless system('bundle exec rake spec')
73-
puts "Error: Tests failed. Fix them before releasing."
74-
exit 1
75-
end
76-
puts "✓ Tests passed"
77-
78-
# Use gem release command
79-
puts "\n→ Releasing gem with gem-release..."
80-
unless system("gem release --tag --push")
81-
puts "Error: Failed to release gem"
82-
exit 1
83-
end
84-
85-
puts "\n🎉 Successfully released version #{version}!"
86-
puts "\nNext steps:"
87-
puts " 1. Create GitHub release: https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v#{version}"
88-
puts " 2. Announce on Slack/Twitter"
89-
puts " 3. Close related issues"
6+
class RaisingMessageHandler
7+
def add_error(error)
8+
raise error
909
end
9110
end
9211

93-
def update_changelog(version, current_version)
94-
changelog_file = 'CHANGELOG.md'
95-
changelog = File.read(changelog_file)
96-
97-
today = Time.now.strftime('%Y-%m-%d')
98-
99-
# Replace [Unreleased] with versioned entry
100-
if changelog.match?(/## \[Unreleased\]/)
101-
changelog.sub!(
102-
/## \[Unreleased\]/,
103-
"## [Unreleased]\n\n---\n\n## [#{version}] — #{today}\n[Compare]: https://github.com/shakacode/cypress-playwright-on-rails/compare/v#{current_version}...v#{version}"
104-
)
105-
File.write(changelog_file, changelog)
106-
puts "✓ Updated #{changelog_file}"
107-
else
108-
puts "Warning: Could not find [Unreleased] section in CHANGELOG.md"
12+
# rubocop:disable Metrics/BlockLength
13+
14+
desc("Releases the gem using the given version.
15+
16+
IMPORTANT: the gem version must be in valid rubygem format (no dashes).
17+
18+
This task depends on the gem-release ruby gem which is installed via `bundle install`
19+
20+
1st argument: The new version in rubygem format (no dashes). Pass no argument to
21+
automatically perform a patch version bump.
22+
2nd argument: Perform a dry run by passing 'true' as a second argument.
23+
24+
Note, accept defaults for rubygems options. Script will pause to get 2FA tokens.
25+
26+
Example: `rake release[1.19.0,false]`")
27+
task :release, %i[gem_version dry_run] do |_t, args|
28+
include CypressOnRails::TaskHelpers
29+
30+
# Check if there are uncommitted changes
31+
unless `git status --porcelain`.strip.empty?
32+
raise "You have uncommitted changes. Please commit or stash them before releasing."
10933
end
34+
35+
args_hash = args.to_hash
36+
37+
is_dry_run = args_hash[:dry_run] == 'true'
38+
39+
gem_version = args_hash.fetch(:gem_version, "")
40+
41+
# See https://github.com/svenfuchs/gem-release
42+
sh_in_dir(gem_root, "git pull --rebase")
43+
sh_in_dir(gem_root, "gem bump --no-commit #{gem_version.strip.empty? ? '' : %(-v #{gem_version})}")
44+
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
48+
49+
msg = <<~MSG
50+
Once you have successfully published, run these commands to update CHANGELOG.md:
51+
52+
bundle exec rake update_changelog
53+
git commit -a -m 'Update CHANGELOG.md'
54+
git push
55+
MSG
56+
puts msg
11057
end
58+
59+
# rubocop:enable Metrics/BlockLength

rakelib/task_helpers.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module CypressOnRails
4+
module TaskHelpers
5+
# Returns the root folder of the cypress-on-rails gem
6+
def gem_root
7+
File.expand_path("..", __dir__)
8+
end
9+
10+
# Executes a string or an array of strings in a shell in the given directory
11+
def sh_in_dir(dir, *shell_commands)
12+
shell_commands.flatten.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)