Skip to content
Closed
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
102 changes: 27 additions & 75 deletions .cursor/skills/release/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,97 +1,49 @@
---
name: release
description: >-
Bumps RubyProxyHeaders::VERSION in lib/ruby_proxy_headers/version.rb, opens a PR from
branch release/VERSION toward main with auto-merge, and coordinates with CI that
publishes a GitHub Release when that branch merges. Use when the user invokes /release,
/release VERSION, asks for a release PR, version bump, or release automation.
Cuts a ruby-proxy-headers release from RELEASING.md. Prepare release opens a
pull request from release/X.Y.Z; merging it publishes the gem and tags vX.Y.Z.
Use when the user invokes /release, /release VERSION, or asks for a release PR.
---

# Release (`/release` and optional VERSION)
# Release

## When this applies
Follow `RELEASING.md` at the repository root. Do not publish, tag, or merge the release pull request. Do not enable auto-merge.

- User message starts with **`/release`** or **`/release VERSION`** (VERSION optional).
- User asks to cut a release, bump the gem version, or open a release PR with auto-merge.
## Version

## Preconditions
Read `RubyProxyHeaders::VERSION` from `lib/ruby_proxy_headers/version.rb`.

- Working tree clean (`git status`); stash or commit unrelated work first.
- `gh` CLI authenticated (`gh auth status`).
- Remote `origin` is GitHub.
- Repository allows **auto-merge** (Settings → General → Pull Requests → Allow auto-merge). If auto-merge is unavailable, open the PR anyway and tell the user to merge manually after checks pass.
| Input | Spec |
| --- | --- |
| `/release` | `patch` |
| `/release 1.4.0` | `1.4.0` |

## Version selection
The version must be `MAJOR.MINOR.PATCH`.

1. Read the current version from `lib/ruby_proxy_headers/version.rb` (`RubyProxyHeaders::VERSION`, semver `MAJOR.MINOR.PATCH`).
2. If **VERSION was provided**: set the new version to that string (must match `^\d+\.\d+\.\d+` unless the project already uses a different scheme—then follow the existing file format).
3. If **VERSION was omitted**: bump the **patch** segment only (e.g. `0.2.1` → `0.2.2`). If the current value is not `x.y.z`, stop and ask the user for an explicit VERSION.
## Preferred path

## Git identity (this repo)

Configure once if needed:
From latest `origin/main`:

```bash
git config user.email "cursor@proxymesh.com"
git config user.name "Cursor"
gh workflow run "Prepare release" --ref main -f version=SPEC
```

## Steps

1. **Sync main**

```bash
git fetch origin main
```

2. **Compute** `NEW_VERSION` (per rules above). **Branch name** is `release/${NEW_VERSION}` (no `v` prefix in the branch name).

3. **Create branch from latest main**

```bash
git checkout -B "release/${NEW_VERSION}" origin/main
```

4. **Edit** `lib/ruby_proxy_headers/version.rb`: set `VERSION = 'NEW_VERSION'` (single-quoted string).

5. **Refresh** `Gemfile.lock` so the path gem entry matches (CI uses frozen Bundler and fails if the gemspec version changed without a lock update):
The workflow runs the version, changelog, and gem build checks before it pushes, because a pull request it opens does not run pull_request workflows. Wait until the run opens the pull request titled `Release X.Y.Z`.

```bash
bundle lock
# If Ruby/Bundler is unavailable, update both `ruby-proxy-headers (OLD)` lines in Gemfile.lock to NEW_VERSION.
```
## Manual path

6. **Commit and push** (never push to `main`; push only the release branch)
Use this when the workflow cannot be started. Branch `release/X.Y.Z` from latest `origin/main` and make the same edits Prepare release makes:

```bash
git add lib/ruby_proxy_headers/version.rb Gemfile.lock
git commit -m "chore: bump version to ${NEW_VERSION}"
git push -u origin "release/${NEW_VERSION}"
```
- `lib/ruby_proxy_headers/version.rb`, `VERSION = 'X.Y.Z'`
- every `ruby-proxy-headers (X.Y.Z)` entry in `Gemfile.lock`
- move `## Unreleased` in `CHANGELOG.md` to `## X.Y.Z - YYYY-MM-DD`

7. **Open PR** into `main` with a short body (no Cursor boilerplate). Example:
Commit, push `release/X.Y.Z`, and open a pull request into `main` titled `Release X.Y.Z` whose body is that changelog section.

```bash
gh pr create --base main --head "release/${NEW_VERSION}" \
--title "Release ${NEW_VERSION}" \
--body "Bumps the gem version to ${NEW_VERSION} for release."
```
Git identity for commits in this repo:

8. **Enable auto-merge** after the PR exists. In non-interactive mode, `gh` requires an explicit merge strategy with `--auto` (use the repository default: usually **`--merge`** for a merge commit, or **`--squash`** / **`--rebase`** if that is what the repo uses).

```bash
gh pr merge <PR_NUMBER_OR_URL> --auto --merge
```

If `--auto` fails (permissions, auto-merge disabled, or pending checks), leave the PR open and report the error; the user can merge manually after CI passes. You can poll with `gh pr checks <PR_NUMBER_OR_URL> --watch` then retry `gh pr merge ... --auto --merge`, or merge manually.

## After merge

Merging the PR into `main` runs **Release on merge** (`.github/workflows/github_release_on_release_branch_merge.yml`), which creates a **GitHub Release** for tag `v{version}` from the merge commit. Because releases created with the default `GITHUB_TOKEN` do not trigger other workflows, **Push Gem** (`push_gem.yml`) is also started via **`workflow_run`** when that release workflow finishes. Manual or API-created releases still match the `release: published` trigger on `push_gem.yml`.

## Quick reference

| Input | Result |
|--------------------|---------------------------------------------|
| `/release` | Patch bump, branch `release/x.y.(z+1)` |
| `/release 1.4.0` | Version `1.4.0`, branch `release/1.4.0` |
```bash
git config user.email "cursor@proxymesh.com"
git config user.name "Cursor"
```
130 changes: 130 additions & 0 deletions .github/scripts/release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# frozen_string_literal: true

require 'English'

# Bumps the gem version and prints a changelog section.
module GemRelease
VERSION_FILE = 'lib/ruby_proxy_headers/version.rb'
VERSION_RE = /\A(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\z/

class Error < StandardError
end

def self.run(argv)
case argv.first
when 'bump' then bump(argv[1])
when 'check' then check(argv[1])
when 'notes' then print notes(argv[1])
else warn 'usage: release.rb bump SPEC|check [X.Y.Z]|notes X.Y.Z'
exit 1
end
rescue Error => e
warn e.message
exit 1
end

def self.bump(spec)
current = read_version
version = next_version(current, spec.to_s.strip)
write_version(version)
write_lock(current, version)
write_changelog(version, Time.now.utc.strftime('%Y-%m-%d'))
path = ENV.fetch('GITHUB_OUTPUT', '')
File.open(path, 'a') { |file| file.puts "version=#{version}" } unless path.empty?
end

def self.check(expected = nil)
version = read_version
assert_lock(version)
raise Error, "version is #{version}, expected #{expected}" unless expected.nil? || expected == version

head = ENV.fetch('HEAD_REF') { ENV.fetch('GITHUB_HEAD_REF', '') }
assert_branch(head, version)
notes(version) if head.start_with?('release/') || expected
end

def self.assert_branch(head, version)
return unless head.start_with?('release/')

raise Error, "branch #{head} does not match #{version}" unless head == "release/#{version}"
end

def self.assert_lock(version)
found = File.readlines('Gemfile.lock').filter_map { |line| line[/^\s*ruby-proxy-headers \(([^)]+)\)/, 1] }
raise Error, 'Gemfile.lock does not match version.rb' if found.empty? || found.uniq != [version]
end

def self.notes(version)
raise Error, 'version must be X.Y.Z' unless version.to_s.match?(VERSION_RE)

lines = File.readlines('CHANGELOG.md')
start = lines.index { |line| line.strip.match?(/\A## #{Regexp.escape(version)} - \d{4}-\d{2}-\d{2}\z/) }
raise Error, "CHANGELOG.md has no ## #{version} - YYYY-MM-DD section" unless start

section_body(lines, start)
end

def self.section_body(lines, start)
rest = lines[(start + 1)..] || []
stop = rest.index { |line| line.start_with?('## ') }
"#{([lines[start]] + (stop ? rest[0...stop] : rest)).join.strip}\n"
end

def self.read_version
version = File.read(VERSION_FILE)[/^\s*VERSION = ['"]([^'"]+)['"]/, 1]
raise Error, 'version.rb has no MAJOR.MINOR.PATCH' unless version&.match?(VERSION_RE)

version
end

def self.next_version(current, spec)
major, minor, patch = current.split('.').map(&:to_i)
case spec
when 'patch' then "#{major}.#{minor}.#{patch + 1}"
when 'minor' then "#{major}.#{minor + 1}.0"
when 'major' then "#{major + 1}.0.0"
else
raise Error, "#{spec} is not a newer X.Y.Z, patch, minor, or major" unless newer?(spec, current)

spec
end
end

def self.newer?(spec, current)
spec.match?(VERSION_RE) && (spec.split('.').map(&:to_i) <=> current.split('.').map(&:to_i)) == 1
end

def self.write_version(version)
updated = File.read(VERSION_FILE).sub(/^(\s*VERSION = )['"][^'"]*['"]/, "\\1'#{version}'")
raise Error, "could not update #{VERSION_FILE}" if updated == File.read(VERSION_FILE)

File.write(VERSION_FILE, updated)
end

def self.write_lock(old_version, new_version)
pattern = /^(\s*ruby-proxy-headers \()#{Regexp.escape(old_version)}(\).*)$/
original = File.read('Gemfile.lock')
updated = original.gsub(pattern) { "#{Regexp.last_match(1)}#{new_version}#{Regexp.last_match(2)}" }
raise Error, 'Gemfile.lock has no ruby-proxy-headers version' if updated == original

File.write('Gemfile.lock', updated)
end

def self.write_changelog(version, date)
lines, start, finish = unreleased_bounds
body = lines[(start + 1)...finish].join.strip
lines[start...finish] = ["## Unreleased\n\n## #{version} - #{date}\n\n#{body}\n\n"]
File.write('CHANGELOG.md', lines.join)
end

def self.unreleased_bounds
lines = File.read('CHANGELOG.md').lines
start = lines.index { |line| line.strip == '## Unreleased' }
raise Error, 'CHANGELOG.md has no ## Unreleased section' unless start

offset = lines[(start + 1)..].index { |line| line.start_with?('## ') }
[lines, start, offset ? start + 1 + offset : lines.size]
end
end

GemRelease.run(ARGV) if $PROGRAM_NAME == __FILE__
55 changes: 0 additions & 55 deletions .github/workflows/github_release_on_release_branch_merge.yml

This file was deleted.

Loading