Skip to content

Commit af98130

Browse files
authored
Add automated release rake tasks (#182)
Implements rake tasks for automating the release process, similar to Shakapacker. New rake tasks: - rake release:prepare[VERSION] - Bumps version and updates CHANGELOG - rake release:publish - Tags, builds, and publishes gem to RubyGems - rake release:full[VERSION] - Complete release in one command Features: - Validates semantic versioning format - Confirms before making changes - Updates version.rb automatically - Updates CHANGELOG.md with date and compare link - Runs test suite before publishing - Creates and pushes git tags - Builds and publishes to RubyGems - Provides clear next steps after each phase Documentation: - RELEASING.md with complete release process guide - Troubleshooting section for common issues - Examples and pre-release checklist This eliminates the need for a manual PR to bump versions. Instead, maintainers can run: rake release:prepare[1.19.0]
1 parent b453c49 commit af98130

File tree

3 files changed

+337
-1
lines changed

3 files changed

+337
-1
lines changed

RELEASING.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# Release Process
2+
3+
This document describes how to release a new version of cypress-playwright-on-rails.
4+
5+
## Prerequisites
6+
7+
1. Maintainer access to the repository
8+
2. RubyGems account with publish permissions for `cypress-on-rails`
9+
3. Clean working directory on `master` branch
10+
4. Development dependencies installed: `bundle install`
11+
- Includes `gem-release` for gem management (like react_on_rails)
12+
13+
## Release Tasks
14+
15+
The project uses rake tasks with `gem-release` to automate the release process (similar to react_on_rails and other ShakaCode gems):
16+
17+
### Quick Release
18+
19+
```bash
20+
# Prepare and publish in one command
21+
rake release:prepare[1.19.0]
22+
# Review changes, commit
23+
rake release:publish
24+
```
25+
26+
### Step-by-Step Release
27+
28+
#### 1. Prepare the Release
29+
30+
```bash
31+
rake release:prepare[1.19.0]
32+
```
33+
34+
This task will:
35+
- Validate the version format (X.Y.Z)
36+
- Use `gem bump` to update `lib/cypress_on_rails/version.rb`
37+
- Update `CHANGELOG.md` with the new version and date
38+
- Provide next steps
39+
40+
After running this:
41+
```bash
42+
# Review the changes
43+
git diff
44+
45+
# Commit the version bump
46+
git add -A
47+
git commit -m "Bump version to 1.19.0"
48+
49+
# Push to master
50+
git push origin master
51+
```
52+
53+
#### 2. Publish the Release
54+
55+
```bash
56+
rake release:publish
57+
```
58+
59+
This task will:
60+
- Verify you're on master branch
61+
- Verify working directory is clean
62+
- Run the test suite
63+
- Use `gem release` to:
64+
- Build the gem
65+
- Push the gem to RubyGems
66+
- Create a git tag (e.g., `v1.19.0`)
67+
- Push the tag to GitHub
68+
69+
#### 3. Post-Release Steps
70+
71+
After publishing, complete these manual steps:
72+
73+
1. **Create GitHub Release**
74+
- Go to https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v1.19.0
75+
- Copy release notes from CHANGELOG.md
76+
- Publish the release
77+
78+
2. **Announce the Release**
79+
- Post in Slack channel
80+
- Tweet about the release
81+
- Update forum posts if needed
82+
83+
3. **Close Related Issues**
84+
- Review issues addressed in this release
85+
- Close them with reference to the release
86+
87+
## Version Numbering
88+
89+
Follow [Semantic Versioning](https://semver.org/):
90+
91+
- **MAJOR** (X.0.0): Breaking changes
92+
- **MINOR** (1.X.0): New features, backwards compatible
93+
- **PATCH** (1.19.X): Bug fixes, backwards compatible
94+
95+
### Examples
96+
97+
```bash
98+
# Patch release (bug fixes)
99+
rake release:prepare[1.18.1]
100+
101+
# Minor release (new features)
102+
rake release:prepare[1.19.0]
103+
104+
# Major release (breaking changes)
105+
rake release:prepare[2.0.0]
106+
```
107+
108+
## Pre-Release Checklist
109+
110+
Before running `rake release:prepare`:
111+
112+
- [ ] All PRs for the release are merged
113+
- [ ] CI is passing on master
114+
- [ ] CHANGELOG.md has [Unreleased] section with all changes
115+
- [ ] Major changes have been tested manually
116+
- [ ] Documentation is up to date
117+
- [ ] Issue #183 discussion is resolved (if applicable)
118+
119+
## Troubleshooting
120+
121+
### "Must be on master branch" error
122+
123+
```bash
124+
git checkout master
125+
git pull --rebase
126+
```
127+
128+
### "Working directory is not clean" error
129+
130+
```bash
131+
# Commit or stash your changes
132+
git status
133+
git add -A && git commit -m "Your message"
134+
# or
135+
git stash
136+
```
137+
138+
### "Tests failed" error
139+
140+
```bash
141+
# Fix the failing tests before releasing
142+
bundle exec rake spec
143+
144+
# If tests are truly failing, don't release
145+
```
146+
147+
### "Failed to push gem to RubyGems" error
148+
149+
Ensure you're authenticated with RubyGems:
150+
```bash
151+
gem signin
152+
# Enter your RubyGems credentials
153+
```
154+
155+
### Tag already exists
156+
157+
If you need to re-release:
158+
```bash
159+
# Delete local tag
160+
git tag -d v1.19.0
161+
162+
# Delete remote tag
163+
git push origin :v1.19.0
164+
165+
# Try again
166+
rake release:publish
167+
```
168+
169+
## Rollback
170+
171+
If you need to rollback a release:
172+
173+
### Yank the gem from RubyGems
174+
```bash
175+
gem yank cypress-on-rails -v 1.19.0
176+
```
177+
178+
### Delete the git tag
179+
```bash
180+
git tag -d v1.19.0
181+
git push origin :v1.19.0
182+
```
183+
184+
### Revert the version commit
185+
```bash
186+
git revert HEAD
187+
git push origin master
188+
```
189+
190+
## Example Release Flow
191+
192+
```bash
193+
# 1. Ensure you're on master and up to date
194+
git checkout master
195+
git pull --rebase
196+
197+
# 2. Prepare the release
198+
rake release:prepare[1.19.0]
199+
# Review output, confirm with 'y'
200+
201+
# 3. Review and commit changes
202+
git diff
203+
git add -A
204+
git commit -m "Bump version to 1.19.0"
205+
206+
# 4. Run tests (optional, publish will run them too)
207+
bundle exec rake spec
208+
209+
# 5. Push to master
210+
git push origin master
211+
212+
# 6. Publish the release
213+
rake release:publish
214+
215+
# 7. Create GitHub release
216+
open "https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v1.19.0"
217+
218+
# 8. Celebrate! 🎉
219+
```
220+
221+
## Notes
222+
223+
- The release tasks will **not** push commits to master for you
224+
- Always review changes before committing
225+
- The `publish` task will run tests before releasing
226+
- Tags are created locally first, then pushed
227+
- Failed releases can be retried after fixing issues

Rakefile

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,117 @@
11
require 'bundler/gem_tasks'
22

3-
43
require 'rspec/core/rake_task'
54
RSpec::Core::RakeTask.new(:spec) do |t|
65
t.pattern = 'spec/cypress_on_rails/*_spec.rb'
76
end
87

98
task default: %w[spec build]
9+
10+
namespace :release do
11+
desc "Prepare release: bump version and update changelog"
12+
task :prepare, [:version] do |_t, args|
13+
require_relative 'lib/cypress_on_rails/version'
14+
15+
version = args[:version]
16+
unless version
17+
puts "Usage: rake release:prepare[VERSION]"
18+
puts "Example: rake release:prepare[1.19.0]"
19+
exit 1
20+
end
21+
22+
unless version.match?(/^\d+\.\d+\.\d+$/)
23+
puts "Error: Version must be in format X.Y.Z (e.g., 1.19.0)"
24+
exit 1
25+
end
26+
27+
current_version = CypressOnRails::VERSION
28+
puts "Current version: #{current_version}"
29+
puts "New version: #{version}"
30+
31+
# Confirm the version bump
32+
print "Continue? (y/n): "
33+
response = $stdin.gets.chomp.downcase
34+
unless response == 'y'
35+
puts "Aborted."
36+
exit 0
37+
end
38+
39+
# Use gem bump to update version
40+
puts "\n→ Bumping version with gem-release..."
41+
unless system("gem bump --version #{version} --no-commit")
42+
puts "Error: Failed to bump version"
43+
exit 1
44+
end
45+
puts "✓ Updated version to #{version}"
46+
47+
# Update CHANGELOG
48+
update_changelog(version, current_version)
49+
50+
puts "\n✓ Version prepared!"
51+
puts "\nNext steps:"
52+
puts " 1. Review changes: git diff"
53+
puts " 2. Commit: git add -A && git commit -m 'Bump version to #{version}'"
54+
puts " 3. Push: git push origin master"
55+
puts " 4. Release: rake release:publish"
56+
end
57+
58+
desc "Publish release: tag, build, and push gem"
59+
task :publish do
60+
require_relative 'lib/cypress_on_rails/version'
61+
version = CypressOnRails::VERSION
62+
63+
# Pre-flight checks
64+
current_branch = `git rev-parse --abbrev-ref HEAD`.chomp
65+
unless current_branch == 'master'
66+
puts "Error: Must be on master branch to release (currently on #{current_branch})"
67+
exit 1
68+
end
69+
70+
if `git status --porcelain`.chomp != ''
71+
puts "Error: Working directory is not clean. Commit or stash changes first."
72+
exit 1
73+
end
74+
75+
puts "Preparing to release version #{version}..."
76+
77+
# Run tests
78+
puts "\n→ Running tests..."
79+
unless system('bundle exec rake spec')
80+
puts "Error: Tests failed. Fix them before releasing."
81+
exit 1
82+
end
83+
puts "✓ Tests passed"
84+
85+
# Use gem release command
86+
puts "\n→ Releasing gem with gem-release..."
87+
unless system("gem release --tag --push")
88+
puts "Error: Failed to release gem"
89+
exit 1
90+
end
91+
92+
puts "\n🎉 Successfully released version #{version}!"
93+
puts "\nNext steps:"
94+
puts " 1. Create GitHub release: https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v#{version}"
95+
puts " 2. Announce on Slack/Twitter"
96+
puts " 3. Close related issues"
97+
end
98+
end
99+
100+
def update_changelog(version, current_version)
101+
changelog_file = 'CHANGELOG.md'
102+
changelog = File.read(changelog_file)
103+
104+
today = Time.now.strftime('%Y-%m-%d')
105+
106+
# Replace [Unreleased] with versioned entry
107+
if changelog.match?(/## \[Unreleased\]/)
108+
changelog.sub!(
109+
/## \[Unreleased\]/,
110+
"## [Unreleased]\n\n---\n\n## [#{version}] — #{today}\n[Compare]: https://github.com/shakacode/cypress-playwright-on-rails/compare/v#{current_version}...v#{version}"
111+
)
112+
File.write(changelog_file, changelog)
113+
puts "✓ Updated #{changelog_file}"
114+
else
115+
puts "Warning: Could not find [Unreleased] section in CHANGELOG.md"
116+
end
117+
end

cypress-on-rails.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
2121
s.add_development_dependency 'railties', '>= 3.2'
2222
s.add_development_dependency 'factory_bot', '!= 6.4.5'
2323
s.add_development_dependency 'vcr'
24+
s.add_development_dependency 'gem-release'
2425
s.metadata = {
2526
"bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
2627
"changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md",

0 commit comments

Comments
 (0)