diff --git a/.cursor/skills/release/SKILL.md b/.cursor/skills/release/SKILL.md index fa2f678..394ecbf 100644 --- a/.cursor/skills/release/SKILL.md +++ b/.cursor/skills/release/SKILL.md @@ -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 --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 --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" +``` diff --git a/.github/scripts/release.rb b/.github/scripts/release.rb new file mode 100644 index 0000000..4a1d20e --- /dev/null +++ b/.github/scripts/release.rb @@ -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__ diff --git a/.github/workflows/github_release_on_release_branch_merge.yml b/.github/workflows/github_release_on_release_branch_merge.yml deleted file mode 100644 index 343eeff..0000000 --- a/.github/workflows/github_release_on_release_branch_merge.yml +++ /dev/null @@ -1,55 +0,0 @@ -# When a release/* PR merges into main, create a GitHub release (tag vX.Y.Z). -# Events from GITHUB_TOKEN do not start other workflows; push_gem.yml is triggered via -# workflow_run when this workflow completes (see push_gem.yml). - -name: Release on merge - -on: - pull_request: - types: [closed] - branches: - - main - -concurrency: - group: release-on-merge-${{ github.event.pull_request.number }} - cancel-in-progress: false - -permissions: - contents: write - -jobs: - github-release: - if: >- - github.event.pull_request.merged == true && - startsWith(github.head_ref, 'release/') && - github.event.pull_request.head.repo.full_name == github.repository - runs-on: ubuntu-24.04 - steps: - - name: Checkout merge commit - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ github.event.pull_request.merge_commit_sha }} - - - name: Read version from lib/ruby_proxy_headers/version.rb - id: meta - run: | - VERSION=$(ruby -r ./lib/ruby_proxy_headers/version.rb -e 'puts RubyProxyHeaders::VERSION') - echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" - - - name: Create GitHub Release - env: - GH_TOKEN: ${{ github.token }} - run: | - set -euo pipefail - VERSION="${{ steps.meta.outputs.version }}" - TAG="v${VERSION}" - MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}" - if gh release view "${TAG}" --repo "${{ github.repository }}" >/dev/null 2>&1; then - echo "Release ${TAG} already exists; skipping." - exit 0 - fi - gh release create "${TAG}" \ - --repo "${{ github.repository }}" \ - --target "${MERGE_SHA}" \ - --title "${TAG}" \ - --generate-notes diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 0000000..b5b65c0 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,94 @@ +# Opens a release/X.Y.Z pull request. Does not merge it. +# A pull request opened with GITHUB_TOKEN does not run pull_request workflows, +# so this job runs the release checks before it pushes. + +name: Prepare release + +on: + workflow_dispatch: + inputs: + version: + description: X.Y.Z, patch, minor, or major + required: true + type: string + +permissions: {} + +concurrency: + group: prepare-release + cancel-in-progress: false + +jobs: + prepare: + runs-on: ubuntu-24.04 + timeout-minutes: 15 + permissions: + contents: write + pull-requests: write + steps: + - name: Require main + run: | + set -euo pipefail + if [[ "${GITHUB_REF}" != "refs/heads/main" ]]; then + echo "Run Prepare release from main." >&2 + exit 1 + fi + + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + persist-credentials: true + + - name: Set up Ruby + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 + with: + bundler: none + ruby-version: ruby + + - name: Bump version and changelog + id: bump + env: + RELEASE_SPEC: ${{ inputs.version }} + run: ruby .github/scripts/release.rb bump "${RELEASE_SPEC}" + + - name: Check version and changelog + env: + VERSION: ${{ steps.bump.outputs.version }} + run: ruby .github/scripts/release.rb check "${VERSION}" + + - name: Build gem + env: + VERSION: ${{ steps.bump.outputs.version }} + run: | + set -euo pipefail + gem build ruby-proxy-headers.gemspec + test -f "ruby-proxy-headers-${VERSION}.gem" + + - name: Push release branch + env: + VERSION: ${{ steps.bump.outputs.version }} + GIT_AUTHOR_NAME: github-actions[bot] + GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com + GIT_COMMITTER_NAME: github-actions[bot] + GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com + run: | + set -euo pipefail + branch="release/${VERSION}" + git checkout -b "${branch}" + git add lib/ruby_proxy_headers/version.rb Gemfile.lock CHANGELOG.md + git commit -m "Release ${VERSION}" + git push origin "HEAD:${branch}" + + - name: Open pull request + env: + VERSION: ${{ steps.bump.outputs.version }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + ruby .github/scripts/release.rb notes "${VERSION}" > "${RUNNER_TEMP}/notes.md" + gh pr create \ + --base main \ + --head "release/${VERSION}" \ + --title "Release ${VERSION}" \ + --body-file "${RUNNER_TEMP}/notes.md" diff --git a/.github/workflows/proxy_integration_tests.yml b/.github/workflows/proxy_integration_tests.yml index a94d23d..6ebd03d 100644 --- a/.github/workflows/proxy_integration_tests.yml +++ b/.github/workflows/proxy_integration_tests.yml @@ -14,6 +14,7 @@ permissions: jobs: integration: runs-on: ubuntu-24.04 + timeout-minutes: 15 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -21,7 +22,7 @@ jobs: persist-credentials: false - name: Set up Ruby - uses: ruby/setup-ruby@v1 # kept unpinned per maintainer guidance — pinning freezes available Ruby versions + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 with: bundler-cache: true ruby-version: ruby diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index dea7523..0b216ae 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -1,95 +1,156 @@ -# Trusted publishing to RubyGems.org (OIDC). Configure a pending publisher at: -# https://rubygems.org/profile/oidc/pending_trusted_publishers -# Workflow file name and repository must match RubyGems trusted publisher settings. -# See https://guides.rubygems.org/trusted-publishing/pushing-a-new-gem/ -# and https://guides.rubygems.org/trusted-publishing/releasing-gems/ +# The RubyGems trusted publisher is registered to this filename (push_gem.yml). name: Push Gem on: - release: - types: [published] - - workflow_dispatch: + pull_request: + branches: [main] + push: + branches: [main] - # GitHub does not start new workflow runs for events caused by the default - # GITHUB_TOKEN (e.g. gh release create in another workflow). After - # "Release on merge" creates a release, trigger this workflow instead. - workflow_run: - workflows: [Release on merge] - types: [completed] +permissions: {} -permissions: - contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: false jobs: - gate: + release-check: + name: Release check + if: github.event_name == 'pull_request' runs-on: ubuntu-24.04 + timeout-minutes: 15 + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Set up Ruby + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 + with: + bundler: none + ruby-version: ruby + + - name: Check version and changelog + env: + HEAD_REF: ${{ github.head_ref }} + run: ruby .github/scripts/release.rb check + + - name: Build gem + run: gem build ruby-proxy-headers.gemspec + + lookup: + if: github.event_name == 'push' + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: + contents: read + pull-requests: read outputs: - publish: ${{ steps.decide.outputs.publish }} + version: ${{ steps.release.outputs.version }} steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - if: github.event_name == 'workflow_run' + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: main + persist-credentials: false - - id: decide + - name: Find the release pull request + id: release env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail - if [[ "${{ github.event_name }}" != "workflow_run" ]]; then - echo "publish=true" >> "${GITHUB_OUTPUT}" + pulls="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls")" + mapfile -t refs < <( + jq -r --arg repo "$GITHUB_REPOSITORY" ' + .[] + | select( + .base.ref == "main" + and .merged_at != null + and (.head.ref | test("^release/[0-9]+\\.[0-9]+\\.[0-9]+$")) + and .head.repo.full_name == $repo + ) + | .head.ref + ' <<<"$pulls" + ) + if [ "${#refs[@]}" -eq 0 ]; then + echo "Not a release merge." exit 0 fi - if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then - echo "publish=false" >> "${GITHUB_OUTPUT}" - exit 0 - fi - VERSION="$(ruby -r ./lib/ruby_proxy_headers/version.rb -e 'puts RubyProxyHeaders::VERSION')" - TAG="v${VERSION}" - if gh release view "${TAG}" --repo "${{ github.repository }}" >/dev/null 2>&1; then - echo "publish=true" >> "${GITHUB_OUTPUT}" - else - echo "No GitHub release ${TAG} yet (or release job was skipped); skipping gem push." - echo "publish=false" >> "${GITHUB_OUTPUT}" + if [ "${#refs[@]}" -ne 1 ]; then + echo "This commit matches more than one release pull request." >&2 + exit 1 fi + version="${refs[0]#release/}" + echo "version=${version}" >> "$GITHUB_OUTPUT" - push: - needs: gate - if: >- - github.repository == 'proxymesh/ruby-proxy-headers' && - needs.gate.outputs.publish == 'true' + publish: + needs: lookup + if: needs.lookup.outputs.version != '' runs-on: ubuntu-24.04 - + timeout-minutes: 20 permissions: - contents: write + contents: read id-token: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ github.event_name == 'workflow_run' && 'main' || github.ref }} persist-credentials: false - - name: Verify release tag matches gem version - if: github.event_name == 'release' + - name: Set up Ruby + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 + with: + bundler: none + ruby-version: ruby + + - name: Check version and changelog env: - REF_NAME: ${{ github.ref_name }} - run: | - VERSION=$(ruby -r ./lib/ruby_proxy_headers/version.rb -e 'puts RubyProxyHeaders::VERSION') - if [ "v${VERSION}" != "${REF_NAME}" ]; then - echo "Release tag must be v${VERSION} (RubyProxyHeaders::VERSION); got ${REF_NAME}" >&2 - exit 1 - fi + HEAD_REF: release/${{ needs.lookup.outputs.version }} + run: ruby .github/scripts/release.rb check + + - name: Build gem + run: gem build ruby-proxy-headers.gemspec + + - name: Configure RubyGems credentials + uses: rubygems/configure-rubygems-credentials@dc5a8d8553e6ee01fc26761a49e99e733d17954a # v2.1.0 + + - name: Push gem + env: + VERSION: ${{ needs.lookup.outputs.version }} + run: gem push "ruby-proxy-headers-${VERSION}.gem" + + github-release: + needs: [lookup, publish] + if: needs.lookup.outputs.version != '' && needs.publish.result == 'success' + runs-on: ubuntu-24.04 + timeout-minutes: 10 + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Set up Ruby - uses: ruby/setup-ruby@v1 # kept unpinned per maintainer guidance — pinning freezes available Ruby versions + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 with: - # workflow_run gets a read-only Actions cache token for the default branch - # (https://github.blog/changelog/2026-06-26-read-only-actions-cache-for-untrusted-triggers/), - # so saving the bundler cache would only warn. Keep caching for trusted triggers. - bundler-cache: ${{ github.event_name != 'workflow_run' }} + bundler: none ruby-version: ruby - - uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1 + - name: Create GitHub Release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.lookup.outputs.version }} + run: | + set -euo pipefail + ruby .github/scripts/release.rb notes "${VERSION}" > "${RUNNER_TEMP}/notes.md" + gh release view "v${VERSION}" \ + || gh release create "v${VERSION}" \ + --target "$GITHUB_SHA" \ + --title "v${VERSION}" \ + --notes-file "${RUNNER_TEMP}/notes.md" diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 6bf1db3..4a4dedf 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -9,6 +9,7 @@ permissions: jobs: rspec: runs-on: ubuntu-24.04 + timeout-minutes: 15 strategy: matrix: @@ -20,7 +21,7 @@ jobs: persist-credentials: false - name: Set up Ruby ${{ matrix.ruby-version }} - uses: ruby/setup-ruby@v1 # kept unpinned per maintainer guidance — pinning freezes available Ruby versions + uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199 # v1.338.0 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b14f78..0e315d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## Unreleased ### Changed - Require Ruby >= 3.2. Dependabot resolves Bundler updates against the gemspec floor, and Ruby 3.1 cannot select nokogiri 1.19 (the release line that installs on the integration job's current Ruby). -## [0.1.0] - 2024-02-28 +## 0.1.0 - 2024-02-28 ### Added @@ -26,6 +26,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `RestClient` module for RestClient integration - Comprehensive documentation - Test suite with RSpec - -[Unreleased]: https://github.com/proxymeshai/ruby-proxy-headers/compare/v0.1.0...HEAD -[0.1.0]: https://github.com/proxymeshai/ruby-proxy-headers/releases/tag/v0.1.0 diff --git a/README.md b/README.md index 97cb3c6..a541478 100644 --- a/README.md +++ b/README.md @@ -132,3 +132,4 @@ bundle exec ruby test/test_proxy_headers.rb -v - [python-proxy-headers](https://github.com/proxymesh/python-proxy-headers) - [javascript-proxy-headers](https://github.com/proxymesh/javascript-proxy-headers) - [proxy-examples (Ruby)](https://github.com/proxymesh/proxy-examples/tree/main/ruby) +- [Releasing](RELEASING.md) diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..49581ca --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,49 @@ +# Releasing + +## Cut a release + +1. On GitHub, open **Actions** → **Prepare release** → **Run workflow** on `main`. +2. Set **version** to `X.Y.Z`, `patch`, `minor`, or `major`. +3. The workflow bumps the version, moves the changelog section, runs the release checks, and opens a pull request titled `Release X.Y.Z`. It does not auto-merge. +4. Merge that pull request when you are ready. + +Opening the pull request by hand still works. From an up-to-date `main`, bump every version manifest, move `## Unreleased` in `CHANGELOG.md` to `## X.Y.Z - YYYY-MM-DD`, and open a pull request titled `Release X.Y.Z` whose body is that changelog section. Do not auto-merge. + +Version manifests: + +- `lib/ruby_proxy_headers/version.rb` (`RubyProxyHeaders::VERSION`) +- `Gemfile.lock` (every `ruby-proxy-headers` version entry) + +`ruby-proxy-headers.gemspec` reads `RubyProxyHeaders::VERSION`. + +## What runs + +### Prepare release + +`.github/workflows/prepare-release.yml` runs on `workflow_dispatch` from `main`. It bumps the manifests, moves the changelog section, checks that the version matches and the changelog has a dated section, builds the gem, and opens the pull request. + +A pull request opened with `GITHUB_TOKEN` does not run `pull_request` workflows, so those checks run in this job before the branch is pushed. + +### Release check + +`.github/workflows/push_gem.yml` runs **Release check** on pull requests into `main`. It checks that `version.rb` and `Gemfile.lock` agree and runs `gem build`. On a `release/X.Y.Z` pull request it also checks that the branch name matches the version and that `CHANGELOG.md` has a `## X.Y.Z - YYYY-MM-DD` section. + +Don't make **Release check** a required check: release pull requests are opened with `GITHUB_TOKEN`, so it doesn't run on them unless you close and reopen the PR. + +### Publish + +A push to `main` runs **lookup** in `.github/workflows/push_gem.yml`. It reads the pull request for that commit. When that pull request was merged from the same repository, targets `main`, and its branch is `release/X.Y.Z`, **publish** and **github-release** run. Otherwise they are skipped. + +**publish** builds the gem and pushes it with `gem push` after `rubygems/configure-rubygems-credentials`. A version already on RubyGems fails the push. **github-release** then runs `gh release view` or `gh release create` with the changelog section as the notes. + +The workflow filename stays `push_gem.yml`. + +## One-time owner setup + +**Prepare release** opens the pull request as `github-actions[bot]`. Actions +workflow permissions need read and write access, and **Allow GitHub Actions to +create and approve pull requests** should stay enabled. + +## Tags + +Tags are `vX.Y.Z`. Existing tags already use that form. Older tags are left as they are. diff --git a/spec/release_script_spec.rb b/spec/release_script_spec.rb new file mode 100644 index 0000000..94d962b --- /dev/null +++ b/spec/release_script_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'fileutils' +require 'open3' +require 'tmpdir' + +RSpec.describe 'release script' do + it 'bumps a patch and prints the dated changelog section' do + Dir.mktmpdir do |dir| + FileUtils.mkdir_p("#{dir}/lib/ruby_proxy_headers") + File.write("#{dir}/lib/ruby_proxy_headers/version.rb", "module RubyProxyHeaders\n VERSION = '0.2.3'\nend\n") + File.write("#{dir}/Gemfile.lock", " ruby-proxy-headers (0.2.3)\n") + File.write("#{dir}/CHANGELOG.md", "## Unreleased\n\n- Note\n\n## 0.1.0 - 2024-02-28\n") + script = File.expand_path('../.github/scripts/release.rb', __dir__) + env = { 'GITHUB_REPOSITORY' => 'proxymesh/ruby-proxy-headers' } + _output, status = Open3.capture2e(env, 'ruby', script, 'bump', 'patch', chdir: dir) + expect(status).to be_success + expect(File.read("#{dir}/lib/ruby_proxy_headers/version.rb")).to include("VERSION = '0.2.4'") + notes, notes_status = Open3.capture2e(env, 'ruby', script, 'notes', '0.2.4', chdir: dir) + expect(notes_status).to be_success + expect(notes).to include('## 0.2.4 - ') + _checked, check_status = Open3.capture2e(env, 'ruby', script, 'check', '0.2.4', chdir: dir) + expect(check_status).to be_success + expect(notes).to include('- Note') + expect(File.read("#{dir}/CHANGELOG.md")).not_to include('[0.2.4]:') + end + end +end