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
51 changes: 16 additions & 35 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,25 @@
name: Release

on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: Optional release version overriding the checked-in version.
type: string
required: false
dry-run:
description: Check the release prerequisites without publishing.
type: boolean
default: false

permissions:
contents: write
id-token: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Extract changelog
id: changelog
shell: bash
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
version="${tag#v}"
notes="$(awk -v version="$version" '
$0 ~ "^### " version " " {found=1; next}
found && $0 ~ "^### " {exit}
found {print}
' CHANGELOG.md)"
if [[ -z "${notes// }" ]]; then
echo "No changelog entry found for ${version}" >&2
exit 1
fi
{
echo "notes<<EOF"
echo "$notes"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.notes }}
uses: dblock/ruby-gem-release/.github/workflows/release.yml@fc9b2673899047f7cb021e4c7f6528d819d06f77 # v0.9.0
with:
ruby-version: '3.4'
version: ${{ inputs.version }}
dry-run: ${{ inputs.dry-run }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Features

* [#1017](https://github.com/ruby-grape/grape-swagger/pull/1017): Release through the manual Release workflow with `ruby-gem-release` and RubyGems Trusted Publishing, replacing the tag-triggered GitHub Release workflow and local `rake release` - [@numbata](https://github.com/numbata).
* Your contribution here.

#### Fixes
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ group :test do
gem 'simplecov', require: false
gem 'super_diff', require: false
end

# ruby-gem-release requires Ruby 3.3+; older CI Rubies and contributors on Ruby 3.1 or 3.2 skip it.
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0')
gem 'commonmarker', '~> 2.10', require: false
gem 'ruby-gem-release', '0.9.0', require: false
end
61 changes: 20 additions & 41 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,46 @@ There are no particular rules about when to release grape-swagger. Any co-mainta

### Release

Run tests, check that all tests succeed locally.
Run tests locally and make sure they pass.

```
bundle install
rake
```

Check that the last build succeeded in [Travis CI](https://travis-ci.org/ruby-grape/grape-swagger) for all supported platforms.
Make sure the "Next" section in [CHANGELOG.md](CHANGELOG.md) lists the changes for the release. A release with only placeholder notes is refused. Keep at least one `* Your contribution here.` line in the section (until ruby-gem-release includes #90 and #91), because the workflow removes the placeholder lines and refuses a section that has none.

Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
Dispatch the Release workflow from the `master` branch, either from the Actions tab or from the command line. Leave `version` empty to release the version in [lib/grape-swagger/version.rb](lib/grape-swagger/version.rb).

```
### 2.2.0 (2025-11-21)
gh workflow run release.yml
```

Remove the lines with "Your contribution here.", since there will be no more contributions to this release.
The workflow:

Commit your changes.
- Validates the release and builds the gem.
- Publishes the gem to RubyGems through Trusted Publishing, so no API key is needed.
- Changes "Next" in [CHANGELOG.md](CHANGELOG.md) to the release version and the current date, and removes the "Your contribution here." lines.
- Tags the release, creates the GitHub Release, and pushes the commit to `master`.
- Bumps the version and opens the next "Next" section in [CHANGELOG.md](CHANGELOG.md).

```
git add CHANGELOG.md lib/grape-swagger/version.rb
git commit -m "Preparing for release, 2.2.0."
git push origin master
```

Release.

```
$ rake release

grape-swagger 2.2.0 built to pkg/grape-swagger-2.2.0.gem.
Tagged v2.2.0.
Pushed git commits and tags.
Pushed grape-swagger 2.2.0 to rubygems.org.
```
The local Bundler release tasks (`rake release`, `release:rubygem_push`, and `release:source_control_push`) are disabled. They stop with a message that points to the workflow.

### Prepare for the Next Version
The `release` environment in GitHub requires an approval before the workflow publishes. Maintainers listed as reviewers approve the run.

Increment the minor version, the third number, modify [lib/grape-swagger/version.rb](lib/grape-swagger/version.rb). For example, change `0.7.1` to `0.7.2`. Major versions are incremented in pull requests that require it.
### If a Release Fails

Add the next release to [CHANGELOG.md](CHANGELOG.md).
Do not merge anything into `master` while a release runs. If `master` moves before the gem is published, the release stops safely and a new dispatch starts clean. If it moves after publication, the gem is on RubyGems but the push fails with `Default branch advanced; start a new release`, leaving no tag, release commit, GitHub Release, or next version, and a new dispatch does not repair that. Recover from the artifacts the run preserved, following [Default Branch Advanced During Publication](https://github.com/dblock/ruby-gem-release/blob/master/docs/actions/release.md#default-branch-advanced-during-publication) in the ruby-gem-release documentation.

```
### 2.2.1 (Next)

#### Features
### One-time Setup

* Your contribution here.
Maintainers set these up once before the first release:

#### Fixes

* Your contribution here.
```
- A RubyGems trusted publisher for `grape-swagger` that points to `ruby-grape/grape-swagger`, the `release.yml` workflow, and the `release` environment. The workflow is a reusable one, so also set the separate workflow repository owner and name fields to `dblock` and `ruby-gem-release`.
- A `release` environment in the repository settings, with required reviewers and a deployment branch rule that only allows `master`.
- Permission for the Actions token to push the release commit and tag to `master`.

Commit your changes.

```
git add CHANGELOG.md lib/grape-swagger/version.rb
git commit -m "Preparing for next developer iteration, 2.2.1."
git push origin master
```
Then dispatch the Release workflow once with `dry-run` enabled (`gh workflow run release.yml -f dry-run=true`). It checks Trusted Publishing and the token's push permissions without publishing anything, and waits for the same `release` environment approval as a real run. It does not validate the changelog, so a green dry run does not guarantee the real run passes.

### Make an Announcement

Expand Down
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ require 'rake'

Bundler::GemHelper.install_tasks

# Disable Bundler's local release tasks so the Release workflow is the only release path.
# `clear` also drops their prerequisites, so nothing is built or tagged before the abort.
%w[release release:rubygem_push release:source_control_push].each do |name|
Rake::Task[name].clear if Rake::Task.task_defined?(name)
task(name) { abort "#{name} is disabled; dispatch the Release workflow instead: gh workflow run release.yml" }
end

if Gem.loaded_specs.key?('ruby-gem-release')
require 'ruby-gem-release/workflow/ruby_gem'
require 'ruby-gem-release/changelog'

RubyGemRelease::Workflow::RubyGem.new(
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/grape-swagger/version.rb', constant: 'VERSION'),
changelog: RubyGemRelease::Changelog::Intridea.new(
path: 'CHANGELOG.md', placeholder: '* Your contribution here.', date_format: '%Y-%m-%d',
sections: %w[Features Fixes]
)
).install_tasks
end

require 'rspec/core'
require 'rspec/core/rake_task'

Expand Down
Loading