diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e559649 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: Optional release version overriding the checked-in version. + type: string + required: false + dry-run: + description: Check release prerequisites without releasing. + type: boolean + default: false + +permissions: + contents: write + id-token: write + +jobs: + release: + uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.9.0 + with: + ruby-version: '4.0' + gemfile: gemfiles/release.gemfile + version: ${{ inputs.version }} + dry-run: ${{ inputs.dry-run }} diff --git a/.gitignore b/.gitignore index 2ae702c..fd23e79 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ test/version_tmp tmp examples/william.rb Gemfile.lock +gemfiles/*.lock +vendor/bundle diff --git a/CHANGELOG.md b/CHANGELOG.md index d9e4427..9b6a8e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * [#338](https://github.com/codegram/hyperclient/pull/338): Documented link properties, including HAL `profile` via `Link#_profile` - [@dblock](https://github.com/dblock). * [#339](https://github.com/codegram/hyperclient/pull/339): Sped up CI by running JRuby with `--dev`, separating JSON 2 and JSON 3 bundler caches, skipping duplicate branch builds, and updating `actions/checkout` to v7 - [@dblock](https://github.com/dblock). * [#340](https://github.com/codegram/hyperclient/pull/340): Added `Link#_allow`, `Link#_allow?`, `Resource#_allow` and `Resource#_allow?` to read the `Allow` header, and an opt-in `enforce_allowed_methods` setting that raises `Hyperclient::MethodNotAllowedError` instead of sending a method the link's most recent response disallowed - [@dblock](https://github.com/dblock). +* [#341](https://github.com/codegram/hyperclient/pull/341): Added a Release workflow using [ruby-gem-release](https://github.com/dblock/ruby-gem-release) and RubyGems Trusted Publishing, and disabled the local `rake release` task - [@dblock](https://github.com/dblock). * Your contribution here. ### 2.1.0 (2026/10/14) diff --git a/RELEASING.md b/RELEASING.md index 10786f5..268c485 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -2,74 +2,57 @@ Release bug fixes frequently, features less frequently, and breaking API changes rarely. -## Prepare the Release +Releases run through the [Release workflow](.github/workflows/release.yml), which uses [ruby-gem-release](https://github.com/dblock/ruby-gem-release/tree/v0.9.0) and RubyGems Trusted Publishing. Merging does not publish anything, and the local Bundler `rake release` task is disabled. -Start with a clean, up-to-date `master` branch. Check that CI has succeeded for all supported platforms. +## One-Time Setup -Set the release version in [lib/hyperclient/version.rb](lib/hyperclient/version.rb). Use a patch version for backward-compatible fixes, a minor version for backward-compatible features, and a major version for breaking changes. +Create a GitHub environment named `release` in this repository, for example with `gh api --method PUT repos/codegram/hyperclient/environments/release`. To require a maintainer's approval before publication, add required reviewers and restrict deployment to `master`. -Replace the next-version heading in [CHANGELOG.md](CHANGELOG.md) with the release version and date, for example `### 2.1.0 (2026/10/14)`. Remove the "Your contribution here." placeholder from that release. +On RubyGems, open the [hyperclient trusted publishers](https://rubygems.org/gems/hyperclient/trusted_publishers) page and add a GitHub Actions publisher with repository owner `codegram`, repository name `hyperclient`, workflow filename `release.yml`, and environment `release`. Set the separate workflow repository owner to `dblock` and name to `ruby-gem-release`, because publication runs in that reusable workflow. No RubyGems API key is stored. -Run the full suite, then commit and push the release preparation: +The workflow needs to push the release commit, the `vVERSION` tag, and the next development commit to `master`. Branch and tag rules must allow that; every release checks them before publishing. -```sh -bundle install -bundle exec rake -git add CHANGELOG.md lib/hyperclient/version.rb -git commit -m "Preparing for release, 2.1.0." -git push origin master -``` +## Prepare the Release + +Releases publish the version in [lib/hyperclient/version.rb](lib/hyperclient/version.rb) with the notes in its `### VERSION (Next)` section of [CHANGELOG.md](CHANGELOG.md). Use a patch version for backward-compatible fixes, a minor version for backward-compatible features, and a major version for breaking changes. To change it, update both files in a pull request, or pass a different version when starting the release. -Wait for CI on the release preparation commit to succeed before publishing. +Check that CI has succeeded on `master`, and don't merge anything while a release is running. -## Publish to RubyGems and GitHub +## Release -Publish the gem using Bundler's release task. This builds the gem, creates and pushes the version tag, and publishes to RubyGems. Complete RubyGems MFA when prompted. +Check the setup without releasing anything: ```sh -bundle exec rake release +gh workflow run release.yml --repo codegram/hyperclient --ref master -f dry-run=true ``` -Creating a Git tag does **not** create a GitHub release. After confirming that the gem was published successfully, create a GitHub release for the same tag. Put the matching changelog section's entries in a temporary file and use them as the release notes: +Then release the checked-in version: ```sh -version=2.1.0 -notes="$(mktemp)" -awk -v version="$version" ' - /^### / { - if (found) exit - if ($2 == version) found = 1 - next - } - found { print } -' CHANGELOG.md > "$notes" -gh release create "v$version" --repo codegram/hyperclient --verify-tag --title "$version" --notes-file "$notes" --latest -rm "$notes" +gh workflow run release.yml --repo codegram/hyperclient --ref master ``` -Verify both publications before considering the release complete: +To release a different version, pass `-f version=2.3.0`. + +The workflow runs `bundle exec rake` on Ruby 4.0 with [gemfiles/release.gemfile](gemfiles/release.gemfile), dates the changelog section and removes its "Your contribution here." placeholder, publishes the gem to RubyGems, pushes the release commit and tag, and creates a GitHub Release with the changelog notes. It then increments the patch version and pushes a new `### VERSION (Next)` section to `master`. + +## Verify and Recover + +Check the RubyGems version, the matching tag and GitHub Release, and the next development version on `master`: ```sh +version=2.2.0 curl --fail --silent --show-error "https://rubygems.org/api/v2/rubygems/hyperclient/versions/$version.json" gh release view "v$version" --repo codegram/hyperclient ``` -If publishing is interrupted, inspect the existing tag, RubyGems version, and GitHub release first. Resume only the missing step; do not move or recreate a published tag. - -## Prepare the Next Version +Don't rerun a failed release blindly: RubyGems may have accepted the gem. Inspect the existing tag, RubyGems version, and GitHub Release first, and never republish a version or move its tag. Follow the [ruby-gem-release recovery instructions](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#recovery-artifacts) to complete only the missing steps. -Increment the development patch version in [lib/hyperclient/version.rb](lib/hyperclient/version.rb), for example from `2.1.0` to `2.1.1`. Add the matching unreleased section at the top of [CHANGELOG.md](CHANGELOG.md): - -```markdown -### 2.1.1 (Next) - -* Your contribution here. -``` +## Run the Release Tasks Locally -Commit and push: +The release tasks need Ruby 3.3+ and the release bundle: ```sh -git add CHANGELOG.md lib/hyperclient/version.rb -git commit -m "Preparing for next release, 2.1.1." -git push origin master +BUNDLE_GEMFILE=gemfiles/release.gemfile bundle install +BUNDLE_GEMFILE=gemfiles/release.gemfile bundle exec rake -T release ``` diff --git a/Rakefile b/Rakefile index fd517a6..3689702 100755 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,24 @@ Bundler.setup :default, :test, :development Bundler::GemHelper.install_tasks +# Releases run through the Release workflow, see RELEASING.md. +%w[release release:rubygem_push release:source_control_push].each do |name| + Rake::Task[name].clear + desc 'Disabled, releases run through the Release workflow (see RELEASING.md)' + task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" } +end + +# The release tasks are only installed with BUNDLE_GEMFILE=gemfiles/release.gemfile. +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/hyperclient/version.rb', constant: 'VERSION'), + changelog: RubyGemRelease::Changelog::Intridea.new(placeholder: '* Your contribution here.') + ).install_tasks +end + require 'rake/testtask' Rake::TestTask.new(:test) do |t| diff --git a/gemfiles/release.gemfile b/gemfiles/release.gemfile new file mode 100644 index 0000000..eb30825 --- /dev/null +++ b/gemfiles/release.gemfile @@ -0,0 +1,6 @@ +# Bundle used by the Release workflow, see RELEASING.md. +# ruby-gem-release requires Ruby 3.3+, so it is kept out of the main Gemfile. +eval_gemfile '../Gemfile' + +gem 'commonmarker', '~> 2.10', require: false +gem 'ruby-gem-release', '0.9.0', require: false