Skip to content
Open
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
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: Optional release version overriding the checked-in version.
type: string
required: false
dry-run:
description: Only check the release prerequisites, without editing, pushing, or publishing.
type: boolean
default: false

permissions:
contents: read

jobs:
release:
uses: dblock/ruby-gem-release/.github/workflows/release.yml@fc9b2673899047f7cb021e4c7f6528d819d06f77 # v0.9.0
permissions:
contents: write
id-token: write
with:
ruby-version: '3.4'
gemfile: gemfiles/release.gemfile
version: ${{ inputs.version }}
dry-run: ${{ inputs.dry-run }}
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- gemfiles/rack_3_2.gemfile
- gemfiles/rails_8_0.gemfile
- gemfiles/rails_8_1.gemfile
specs: ['spec --exclude-pattern=spec/integration/{grape_entity,grape_swagger,hashie,dry_validation,multi_*}/*_spec.rb']
specs: ['spec --exclude-pattern=spec/integration/{grape_entity,grape_swagger,hashie,dry_validation,multi_*,ruby_gem_release}/*_spec.rb']
include:
- ruby: '4.0'
gemfile: gemfiles/grape_entity.gemfile
Expand All @@ -59,6 +59,9 @@ jobs:
- ruby: '4.0'
gemfile: gemfiles/multi_xml_0_8.gemfile
specs: 'spec/integration/multi_xml'
- ruby: '3.4'
gemfile: gemfiles/release.gemfile
specs: 'spec/integration/ruby_gem_release'
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [#3062](https://github.com/ruby-grape/grape/pull/3062): Use the reusable Danger workflow with a separate Gemfile - [@dblock](https://github.com/dblock).
* [#3063](https://github.com/ruby-grape/grape/pull/3063): Drop support for Rack 2.2 and 3.0 and require Rack 3.1 - [@ericproulx](https://github.com/ericproulx).
* [#3077](https://github.com/ruby-grape/grape/pull/3077): Add benchmarks that fail a pull request that makes Grape slower or allocate more, with [Duel](https://github.com/sferik/duel-ruby) - [@sferik](https://github.com/sferik).
* [#3078](https://github.com/ruby-grape/grape/pull/3078): Automate gem releases with ruby-gem-release - [@dblock](https://github.com/dblock).
* [#3085](https://github.com/ruby-grape/grape/pull/3085): Report `endpoint_call.grape` around an endpoint's whole stack, with the response the client gets - [@ericproulx](https://github.com/ericproulx).
* [#3088](https://github.com/ruby-grape/grape/pull/3088): Pin workflow actions to commits and grant their tokens only what they need - [@ericproulx](https://github.com/ericproulx).
* [#3090](https://github.com/ruby-grape/grape/pull/3090): Call Danger's workflows from danger/danger-pr-comment, where they moved - [@ericproulx](https://github.com/ericproulx).
Expand Down
115 changes: 38 additions & 77 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,73 @@
Releasing Grape
===============

There're no particular rules about when to release Grape. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
There are no particular rules about when to release Grape. Release bug fixes frequently, features not so frequently and breaking API changes rarely.

### Release

Run tests, check that all tests succeed locally.

```
bundle install
rake
```

Double-check that the [last build succeeded](https://github.com/ruby-grape/grape/actions) for all supported platforms.

Those with r/w permissions to the [master Grape repository](https://github.com/ruby-grape/grape) generally have large Grape-based projects. Point one to Grape HEAD and run all your API tests to catch any obvious regressions.

```
gem grape, github: 'ruby-grape/grape'
```

Modify the "Stable Release" section in [README.md](README.md). Change the text to reflect that this is going to be the documentation for a stable release. Remove references to the previous release of Grape. Keep the file open, you'll have to undo this change after the release.

```
## Stable Release
You're reading the documentation for the stable release of Grape, 0.6.0.
```

Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.

```
#### 0.6.0 (2013/9/16)
```
### One-Time Setup

Remove the line with "Your contribution here.", since there will be no more contributions to this release.
Releases use [ruby-gem-release 0.9.0](https://github.com/dblock/ruby-gem-release/tree/v0.9.0) and RubyGems Trusted Publishing without a stored RubyGems API key. The release tooling lives in its own bundle, [gemfiles/release.gemfile](gemfiles/release.gemfile), which evaluates the main `Gemfile` and adds `ruby-gem-release` and `commonmarker`, so neither is installed for contributors or other CI jobs. The gem is pinned there and the reusable workflow is pinned by commit SHA in [release.yml](.github/workflows/release.yml). Move both pins together when upgrading. The trusted publisher names the workflow repository but not a ref, so verify that a pinned SHA is the commit of the matching `vVERSION` tag.

Commit your changes.
Create a GitHub environment named `release` in **Settings > Environments**. Configure required release-maintainer reviewers, prevent self-review where appropriate, and restrict deployments to `master`. Creating an unprotected environment alone does not restrict publication: repository writers can dispatch the workflow, and required reviewers gate publication. The release job installs the release bundle, which includes the development and test bundle, without a lockfile and runs RuboCop and the full suite while holding `id-token: write` and `contents: write`, so any gem in that bundle could request a publishing token. Approval controls when the job runs, not what runs in it; review dependency changes on `master` before approving.

```
git add README.md CHANGELOG.md
git commit -m "Preparing for release, 0.6.0."
git push origin master
```
In the [grape trusted publishers settings](https://rubygems.org/gems/grape/trusted_publishers), configure these values:

Release.
| Field | Value |
| --- | --- |
| Repository owner | `ruby-grape` |
| Repository name | `grape` |
| Workflow filename | `release.yml` |
| Environment | `release` |
| Workflow repository owner | `dblock` |
| Workflow repository name | `ruby-gem-release` |

```
$ rake release
The workflow repository identifies the reusable workflow, not Grape's caller workflow. Ensure branch and tag rules permit `GITHUB_TOKEN` to push release commits to `master` and create `vVERSION` tags. If rules require PRs or checks that the release token cannot bypass, a repository administrator must establish an approved release policy before dispatching; the workflow does not change repository protections.

grape 0.6.0 built to pkg/grape-0.6.0.gem.
Tagged v0.6.0.
Pushed git commits and tags.
Pushed grape 0.6.0 to rubygems.org.
```

### Prepare for the Next Version
### Release

Modify the "Stable Release" section in [README.md](README.md). Change the text to reflect that this is going to be the next release.
Run tests and check that all tests succeed locally:

```sh
bundle install
bundle exec rake
bundle exec rake build
BUNDLE_GEMFILE=gemfiles/release.gemfile bundle install
BUNDLE_GEMFILE=gemfiles/release.gemfile bundle exec rspec spec/integration/ruby_gem_release
```
## Stable Release

You're reading the documentation for the next release of Grape, which should be 0.6.1.
The current stable release is [0.6.0](https://github.com/ruby-grape/grape/blob/v0.6.0/README.md).
```
The release specs run only in the release bundle, as their own CI job. They use `ruby-gem-release/rspec` to exercise the production workflow and README hooks in a disposable Git repository, replacing registry and hosted publication with the library's local adapters. They do not publish to RubyGems or GitHub.

Add the next release to [CHANGELOG.md](CHANGELOG.md).
Double-check that the [last build succeeded](https://github.com/ruby-grape/grape/actions) for all supported platforms. Point a Grape-based project at Grape HEAD and run its API tests to catch regressions:

```ruby
gem 'grape', github: 'ruby-grape/grape'
```
### 0.6.1 (Next)
#### Features

* Your contribution here.
Review the next section of [CHANGELOG.md](CHANGELOG.md) and the version in [lib/grape/version.rb](lib/grape/version.rb). Keep one `* Your contribution here.` placeholder in each of Features and Fixes; ruby-gem-release preserves this two-section format. Actual release notes are required.

#### Fixes
Dispatch **Release** from `master` in GitHub Actions, or run:

* Your contribution here.
```sh
gh workflow run release.yml --repo ruby-grape/grape --ref master
```

Bump the minor version in lib/grape/version.rb.
To select a different release version without a separate version-bump commit, pass `-f version=4.2.0`. Dispatching authorizes publication once the `release` environment's approval requirements are satisfied; do not dispatch from PR CI. To check the `release` environment, trusted publisher, and push permissions without editing, pushing, or publishing anything, pass `-f dry-run=true`; required reviewers still approve the dry run.

```ruby
module Grape
VERSION = '0.6.1'.freeze
end
```
The workflow validates release preconditions, dates the changelog and removes both contribution placeholders, updates the README to describe the stable release, and runs `bundle exec rake`. It builds and preserves the gem and recovery artifacts, publishes that exact gem to RubyGems, pushes the release commit and tag, and creates a GitHub Release. It then increments the minor version, as Grape does after every release, and pushes the next development iteration with both changelog sections and the README's stable-release link restored. No manual release edits are needed; `rake release` stops and points here instead of publishing.

Commit your changes.
### Recovery

```
git add CHANGELOG.md README.md lib/grape/version.rb
git commit -m "Preparing for next development iteration, 0.6.1."
git push origin master
```
Inspect the failed run and its `release-gem-*` artifact before retrying. It can contain the built gem, checksum manifest, and Git recovery bundle. RubyGems publication cannot be undone by resetting Git: if a version was uploaded, never publish different bytes under that version or move its tag. Follow the [ruby-gem-release recovery guide](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#verify-and-recover) to determine which steps completed and recover deliberately.

### Make an Announcement

Make an announcement on the [ruby-grape@googlegroups.com](mailto:ruby-grape@googlegroups.com) mailing list. The general format is as follows.
Make an announcement on the [ruby-grape@googlegroups.com](mailto:ruby-grape@googlegroups.com) mailing list:

```
Grape 0.6.0 has been released.
```text
Grape 4.2.0 has been released.
There were 8 contributors to this release, not counting documentation.
There were N contributors to this release, not counting documentation.
Please note the breaking API change in ...
[copy/paste CHANGELOG here]
```
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Bundler.setup(:default, :test, :development)

Bundler::GemHelper.install_tasks

# Releases run through the Release workflow, not Bundler's tasks; see RELEASING.md.
%w[release release:guard_clean release:source_control_push release:rubygem_push].each { |name| Rake::Task[name].clear }
desc('Release through the Release GitHub Actions workflow, see RELEASING.md')
task(:release) { abort('Release through the Release GitHub Actions workflow; see RELEASING.md.') }

require('rspec/core/rake_task')
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
Expand Down Expand Up @@ -33,3 +38,12 @@ begin
rescue LoadError
# (Any other bundle, which hasn't got Duel.)
end

# The release workflow's tasks, in its own bundle (gemfiles/release.gemfile).
begin
require_relative('tasks/release')
GrapeRelease.workflow.install_tasks
rescue LoadError => e
# (Any other bundle, which hasn't got ruby-gem-release.)
raise unless e.path.to_s.start_with?('ruby-gem-release')
end
8 changes: 8 additions & 0 deletions gemfiles/release.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# The release workflow's bundle: the main Gemfile, so the release job still runs
# the full suite, plus the release tooling only it needs.
eval_gemfile '../Gemfile'

gem 'commonmarker', '~> 2.10', require: false
gem 'ruby-gem-release', '0.9.0', require: false
36 changes: 36 additions & 0 deletions spec/integration/ruby_gem_release/release_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'ruby-gem-release/rspec'
require_relative '../../../tasks/release'

describe GrapeRelease do
include RubyGemRelease::RSpec

it 'updates the README and CHANGELOG in the release and next development commits' do
with_release_project do |project|
project.copy_files(path: File.expand_path('../../..', __dir__), files: %w[tasks/release.rb grape.gemspec lib/grape/version.rb README.md CHANGELOG.md])
project.configure_workflow(require: 'tasks/release', builder: 'GrapeRelease.workflow')
project.commit!

project.release!(version: '4.2.9')

readme = File.read(File.expand_path('../../../README.md', __dir__))
section = /^## Stable Release\n.*?(?=^## |\z)/m
stable = "You're reading the documentation for the stable release of Grape, 4.2.9."
development = "You're reading the documentation for the next release of Grape, which should be 4.3.0.\n" \
'The current stable release is [4.2.9](https://github.com/ruby-grape/grape/blob/v4.2.9/README.md).'
expect(project.remote_file('v4.2.9', 'README.md')).to eq(readme.sub(section, "## Stable Release\n\n#{stable}\n\n").strip)
expect(project.remote_file('master', 'README.md')).to eq(readme.sub(section, "## Stable Release\n\n#{development}\n\n").strip)

changelog = File.read(File.expand_path('../../../CHANGELOG.md', __dir__))
released = changelog.sub('### 4.2.0 (Next)', "### 4.2.9 (#{project.environment.fetch('RELEASE_DATE')})").gsub("* Your contribution here.\n", '')
development = "### 4.3.0 (Next)\n\n#### Features\n\n* Your contribution here.\n\n#### Fixes\n\n* Your contribution here.\n\n#{released}"
expect(project.environment.fetch('RELEASE_DATE')).to match(/\A\d{4}-\d{2}-\d{2}\z/)
expect(project.remote_file('v4.2.9', 'CHANGELOG.md')).to eq(released.strip)
expect(project.remote_file('master', 'CHANGELOG.md')).to eq(development.strip)
expect(project.remote_file('v4.2.9', 'lib/grape/version.rb')).to include("VERSION = '4.2.9'")
expect(project.remote_file('master', 'lib/grape/version.rb')).to include("VERSION = '4.3.0'")
expect(project.git('status', '--porcelain')).to eq('')
end
end
end
30 changes: 30 additions & 0 deletions tasks/release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'ruby-gem-release/workflow/ruby_gem'
require 'ruby-gem-release/changelog'
require 'ruby-gem-release/markdown/section'

module GrapeRelease
# Grape starts the next minor version after every release, patch releases included,
# and drops an empty Features or Fixes section from a release.
def self.workflow(**)
workflow = RubyGemRelease::Workflow::RubyGem.new(
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/grape/version.rb', constant: 'VERSION'),
changelog: RubyGemRelease::Changelog::Intridea.new(placeholder: '* Your contribution here.', date_format: '%Y-%m-%d', sections: %w[Features Fixes]),
next_version: :minor,
**
)

readme = RubyGemRelease::Markdown::Section.new(path: 'README.md', heading: '## Stable Release')
workflow.after(:prepare_release) do |ctx|
readme.replace!("You're reading the documentation for the stable release of Grape, #{ctx.release.version}.")
end
workflow.after(:prepare_next) do |ctx|
readme.replace!(
"You're reading the documentation for the next release of Grape, which should be #{ctx.release.next_version}.\n" \
"The current stable release is [#{ctx.release.version}](https://github.com/ruby-grape/grape/blob/v#{ctx.release.version}/README.md)."
)
end
workflow
end
end
Loading