Skip to content
Merged
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
227 changes: 227 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# Release Process

This document describes how to release a new version of cypress-playwright-on-rails.

## Prerequisites

1. Maintainer access to the repository
2. RubyGems account with publish permissions for `cypress-on-rails`
3. Clean working directory on `master` branch
4. Development dependencies installed: `bundle install`
- Includes `gem-release` for gem management (like react_on_rails)

## Release Tasks

The project uses rake tasks with `gem-release` to automate the release process (similar to react_on_rails and other ShakaCode gems):

### Quick Release

```bash
# Prepare and publish in one command
rake release:prepare[1.19.0]
# Review changes, commit
rake release:publish
```

### Step-by-Step Release

#### 1. Prepare the Release

```bash
rake release:prepare[1.19.0]
```

This task will:
- Validate the version format (X.Y.Z)
- Use `gem bump` to update `lib/cypress_on_rails/version.rb`
- Update `CHANGELOG.md` with the new version and date
- Provide next steps

After running this:
```bash
# Review the changes
git diff

# Commit the version bump
git add -A
git commit -m "Bump version to 1.19.0"

# Push to master
git push origin master
```

#### 2. Publish the Release

```bash
rake release:publish
```

This task will:
- Verify you're on master branch
- Verify working directory is clean
- Run the test suite
- Use `gem release` to:
- Build the gem
- Push the gem to RubyGems
- Create a git tag (e.g., `v1.19.0`)
- Push the tag to GitHub

#### 3. Post-Release Steps

After publishing, complete these manual steps:

1. **Create GitHub Release**
- Go to https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v1.19.0
- Copy release notes from CHANGELOG.md
- Publish the release

2. **Announce the Release**
- Post in Slack channel
- Tweet about the release
- Update forum posts if needed

3. **Close Related Issues**
- Review issues addressed in this release
- Close them with reference to the release

## Version Numbering

Follow [Semantic Versioning](https://semver.org/):

- **MAJOR** (X.0.0): Breaking changes
- **MINOR** (1.X.0): New features, backwards compatible
- **PATCH** (1.19.X): Bug fixes, backwards compatible

### Examples

```bash
# Patch release (bug fixes)
rake release:prepare[1.18.1]

# Minor release (new features)
rake release:prepare[1.19.0]

# Major release (breaking changes)
rake release:prepare[2.0.0]
```

## Pre-Release Checklist

Before running `rake release:prepare`:

- [ ] All PRs for the release are merged
- [ ] CI is passing on master
- [ ] CHANGELOG.md has [Unreleased] section with all changes
- [ ] Major changes have been tested manually
- [ ] Documentation is up to date
- [ ] Issue #183 discussion is resolved (if applicable)

## Troubleshooting

### "Must be on master branch" error

```bash
git checkout master
git pull --rebase
```

### "Working directory is not clean" error

```bash
# Commit or stash your changes
git status
git add -A && git commit -m "Your message"
# or
git stash
```

### "Tests failed" error

```bash
# Fix the failing tests before releasing
bundle exec rake spec

# If tests are truly failing, don't release
```

### "Failed to push gem to RubyGems" error

Ensure you're authenticated with RubyGems:
```bash
gem signin
# Enter your RubyGems credentials
```

### Tag already exists

If you need to re-release:
```bash
# Delete local tag
git tag -d v1.19.0

# Delete remote tag
git push origin :v1.19.0

# Try again
rake release:publish
```

## Rollback

If you need to rollback a release:

### Yank the gem from RubyGems
```bash
gem yank cypress-on-rails -v 1.19.0
```

### Delete the git tag
```bash
git tag -d v1.19.0
git push origin :v1.19.0
```

### Revert the version commit
```bash
git revert HEAD
git push origin master
```

## Example Release Flow

```bash
# 1. Ensure you're on master and up to date
git checkout master
git pull --rebase

# 2. Prepare the release
rake release:prepare[1.19.0]
# Review output, confirm with 'y'

# 3. Review and commit changes
git diff
git add -A
git commit -m "Bump version to 1.19.0"

# 4. Run tests (optional, publish will run them too)
bundle exec rake spec

# 5. Push to master
git push origin master

# 6. Publish the release
rake release:publish

# 7. Create GitHub release
open "https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v1.19.0"

# 8. Celebrate! 🎉
```

## Notes

- The release tasks will **not** push commits to master for you
- Always review changes before committing
- The `publish` task will run tests before releasing
- Tags are created locally first, then pushed
- Failed releases can be retried after fixing issues
110 changes: 109 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,117 @@
require 'bundler/gem_tasks'


require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/cypress_on_rails/*_spec.rb'
end

task default: %w[spec build]

namespace :release do
desc "Prepare release: bump version and update changelog"
task :prepare, [:version] do |_t, args|
require_relative 'lib/cypress_on_rails/version'

version = args[:version]
unless version
puts "Usage: rake release:prepare[VERSION]"
puts "Example: rake release:prepare[1.19.0]"
exit 1
end

unless version.match?(/^\d+\.\d+\.\d+$/)
puts "Error: Version must be in format X.Y.Z (e.g., 1.19.0)"
exit 1
end

current_version = CypressOnRails::VERSION
puts "Current version: #{current_version}"
puts "New version: #{version}"

# Confirm the version bump
print "Continue? (y/n): "
response = $stdin.gets.chomp.downcase
unless response == 'y'
puts "Aborted."
exit 0
end

# Use gem bump to update version
puts "\n→ Bumping version with gem-release..."
unless system("gem bump --version #{version} --no-commit")
puts "Error: Failed to bump version"
exit 1
end
puts "✓ Updated version to #{version}"
Comment on lines +39 to +45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Use array form of system() to prevent shell injection.

Although the version is validated with a regex, using string interpolation in system() is a security risk. The array form of system() is safer as it avoids shell interpretation.

Apply this diff:

-    unless system("gem bump --version #{version} --no-commit")
+    unless system("gem", "bump", "--version", version, "--no-commit")
       puts "Error: Failed to bump version"
       exit 1
     end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Use gem bump to update version
puts "\n→ Bumping version with gem-release..."
unless system("gem bump --version #{version} --no-commit")
puts "Error: Failed to bump version"
exit 1
end
puts "✓ Updated version to #{version}"
# Use gem bump to update version
puts "\n→ Bumping version with gem-release..."
unless system("gem", "bump", "--version", version, "--no-commit")
puts "Error: Failed to bump version"
exit 1
end
puts "✓ Updated version to #{version}"
🤖 Prompt for AI Agents
In Rakefile around lines 39 to 45, the call system("gem bump --version
#{version} --no-commit") uses a single string which invokes a shell and risks
injection; replace it with the array form system("gem", "bump", "--version",
version, "--no-commit") so arguments are passed directly (no shell
interpolation), keep the existing conditional and error handling unchanged.


# Update CHANGELOG
update_changelog(version, current_version)

puts "\n✓ Version prepared!"
puts "\nNext steps:"
puts " 1. Review changes: git diff"
puts " 2. Commit: git add -A && git commit -m 'Bump version to #{version}'"
puts " 3. Push: git push origin master"
puts " 4. Release: rake release:publish"
end

desc "Publish release: tag, build, and push gem"
task :publish do
require_relative 'lib/cypress_on_rails/version'
version = CypressOnRails::VERSION

# Pre-flight checks
current_branch = `git rev-parse --abbrev-ref HEAD`.chomp
unless current_branch == 'master'
puts "Error: Must be on master branch to release (currently on #{current_branch})"
exit 1
end

if `git status --porcelain`.chomp != ''
puts "Error: Working directory is not clean. Commit or stash changes first."
exit 1
end

puts "Preparing to release version #{version}..."

# Run tests
puts "\n→ Running tests..."
unless system('bundle exec rake spec')
puts "Error: Tests failed. Fix them before releasing."
exit 1
end
puts "✓ Tests passed"

# Use gem release command
puts "\n→ Releasing gem with gem-release..."
unless system("gem release --tag --push")
puts "Error: Failed to release gem"
exit 1
end

puts "\n🎉 Successfully released version #{version}!"
puts "\nNext steps:"
puts " 1. Create GitHub release: https://github.com/shakacode/cypress-playwright-on-rails/releases/new?tag=v#{version}"
puts " 2. Announce on Slack/Twitter"
puts " 3. Close related issues"
end
end

def update_changelog(version, current_version)
changelog_file = 'CHANGELOG.md'
changelog = File.read(changelog_file)

today = Time.now.strftime('%Y-%m-%d')

# Replace [Unreleased] with versioned entry
if changelog.match?(/## \[Unreleased\]/)
changelog.sub!(
/## \[Unreleased\]/,
"## [Unreleased]\n\n---\n\n## [#{version}] — #{today}\n[Compare]: https://github.com/shakacode/cypress-playwright-on-rails/compare/v#{current_version}...v#{version}"
)
File.write(changelog_file, changelog)
puts "✓ Updated #{changelog_file}"
else
puts "Warning: Could not find [Unreleased] section in CHANGELOG.md"
end
end
1 change: 1 addition & 0 deletions cypress-on-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'railties', '>= 3.2'
s.add_development_dependency 'factory_bot', '!= 6.4.5'
s.add_development_dependency 'vcr'
s.add_development_dependency 'gem-release'
s.metadata = {
"bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
"changelog_uri" => "https://github.com/shakacode/cypress-on-rails/blob/master/CHANGELOG.md",
Expand Down
Loading