Skip to content
Merged
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
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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, such as RubyGems Trusted Publishing, without releasing.
type: boolean
default: false

permissions:
contents: write
id-token: write

jobs:
release:
if: github.repository == 'mongoid/mongoid_orderable' && github.ref == 'refs/heads/master'
uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.9.0
with:
ruby-version: '3.3'
version: ${{ inputs.version }}
dry-run: ${{ inputs.dry-run }}
test: |
docker run --detach --name mongodb --publish 27018:27018 mongo:8.0 --replSet rs0 --port 27018 --bind_ip_all
until docker exec mongodb mongosh --port 27018 --quiet --eval 'try { rs.status().ok } catch (e) { rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27018" }] }).ok }' | grep -q 1; do sleep 1; done
until docker exec mongodb mongosh --port 27018 --quiet --eval 'db.hello().isWritablePrimary' | grep -q true; do sleep 1; done
MONGODB_HOST=localhost:27018 bundle exec rake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
Gemfile.lock
coverage/
pkg/*
/vendor/bundle
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Metrics/BlockLength:
merge:
- Exclude
Exclude:
- spec/release/release_spec.rb
- Gemfile

Markdown/HeadingCapitalization:
Expand Down
3 changes: 3 additions & 0 deletions .spellcheck.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ActiveSupport
Arkadiy
Bundler
CHANGELOG
changelog
CLI
Expand All @@ -14,6 +15,7 @@ gte
initializer
joeyAghion
johnnyshields
JRuby
linter
lt
lte
Expand All @@ -35,6 +37,7 @@ Rakefile
rb
README
README's
RSpec
RuboCop
rubocop
RubyGems
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Your contribution here.
* [#94](https://github.com/mongoid/mongoid_orderable/pull/94): Lint Markdown, YAML, and spelling with rubocop-md, rubocop-prose, rubocop-spellcheck, and rubocop-yaml in a separate Lint workflow, and clean up documentation - [@dblock](https://github.com/dblock).
* [#95](https://github.com/mongoid/mongoid_orderable/pull/95): Run CI pushes only on the default branch, cancel superseded pull request runs, skip duplicate lint in the test matrix, and bound job times - [@dblock](https://github.com/dblock).
* [#96](https://github.com/mongoid/mongoid_orderable/pull/96): Release with ruby-gem-release from a manually dispatched GitHub Actions workflow using RubyGems Trusted Publishing, with dry runs - [@dblock](https://github.com/dblock).

### 6.0.7 (2026/10/18)

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ end

group :development, :test do
if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3')
gem 'commonmarker', '~> 2.10', require: false
gem 'rubocop', '~> 1.92'
gem 'rubocop-md', '~> 3.0', require: false
gem 'rubocop-prose', '~> 0.2', require: false
gem 'rubocop-rake', '~> 0.7', require: false
gem 'rubocop-spellcheck', '~> 0.2', require: false
gem 'rubocop-yaml', '~> 0.1.0', require: false
gem 'ruby-gem-release', '0.9.0', require: false
end
end
39 changes: 22 additions & 17 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
# Releasing
# Releasing Mongoid Orderable

Release from a clean local checkout of the upstream repository, not a fork. You need repository push access, RubyGems ownership with MFA, and an authenticated GitHub CLI.
Releases use [ruby-gem-release](https://github.com/dblock/ruby-gem-release) 0.9.0 through a manually dispatched [Release workflow](.github/workflows/release.yml). Keep the `ruby-gem-release` gem in [Gemfile](Gemfile) and the reusable workflow in `release.yml` pinned to the same version. The workflow publishes through RubyGems Trusted Publishing, so no RubyGems API key or one-time password is needed. It only runs from `master` in `mongoid/mongoid_orderable`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.

## Prepare
## One-Time Setup

1. Run `git switch master` and `git pull --ff-only`. Confirm that `origin` points to `mongoid/mongoid_orderable`.
2. Choose the next semantic version and update `lib/mongoid/orderable/version.rb`. Date the corresponding changelog section and remove its contribution placeholder.
3. Run `bundle install`, then `bundle exec rake` against a MongoDB replica set so transaction examples run correctly. Set `MONGODB_HOST` if the replica set is not on `localhost:27017`; use `MONGOID_VERSION` to select a supported Mongoid version.
4. Commit the preparation, push `master`, and wait for the complete GitHub Actions test matrix and RuboCop workflow to pass for that commit.
Before the first automated release, a maintainer must:

## Publish
1. Create the GitHub environment `release` in `mongoid/mongoid_orderable`, for example with `gh api --method PUT repos/mongoid/mongoid_orderable/environments/release`, and restrict its deployment branches to `master`. Add required reviewers to require maintainer approval before publication.
2. At [mongoid_orderable's trusted publishers](https://rubygems.org/gems/mongoid_orderable/trusted_publishers), add a GitHub Actions publisher with repository owner `mongoid`, repository `mongoid_orderable`, workflow filename `release.yml`, environment `release`, and the separate workflow repository owner `dblock` and repository `ruby-gem-release`.
3. Allow GitHub Actions to push release commits and `v*` tags to `master`. See the upstream [setup and permissions guidance](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#one-time-setup).

Run `bundle exec rake release`. This builds the package under `pkg/`, creates and pushes the version tag, and publishes to RubyGems. Enter a fresh RubyGems MFA code when prompted.
Verify the setup without publishing with a [dry run](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#dry-run), which never edits files, builds, pushes, or publishes:

If RubyGems rejects the push for missing MFA after the tag was pushed, do not rerun the entire release task. Check the tag and RubyGems first, then publish the built package with `gem push pkg/mongoid_orderable-VERSION.gem --otp CODE`. Never move a published tag or republish an existing version.
```sh
gh workflow run release.yml --repo mongoid/mongoid_orderable --ref master -f dry-run=true
```

Create a GitHub release from the same tag, using the matching changelog section as its release notes:
## Prepare

Start with a clean, up-to-date `master` and verify that the latest [CI checks](https://github.com/mongoid/mongoid_orderable/actions) pass. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/mongoid/orderable/version.rb](lib/mongoid/orderable/version.rb) and the matching `(Next)` heading in [CHANGELOG.md](CHANGELOG.md), and change both in a pull request if needed, or pass a `version` override when dispatching. The workflow dates the `(Next)` heading using `YYYY/MM/DD` and removes the `* Your contribution here.` placeholder; a section without notes cannot be released.

Release automation requires MRI Ruby 3.3 or newer; the release dependency and tasks are skipped on older Ruby versions and JRuby. Release specs in [spec/release](spec/release) run the actual release tasks against a local fixture with the [ruby-gem-release RSpec helpers](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/testing.md), without contacting RubyGems or GitHub.

## Publish

```sh
version=6.0.6 # Replace with the version being released.
gh release create "v$version" --repo mongoid/mongoid_orderable \
--verify-tag --title "$version" --notes-file /path/to/release-notes.md --latest
gh workflow run release.yml --repo mongoid/mongoid_orderable --ref master
```

Verify the exact version at `https://rubygems.org/gems/mongoid_orderable/versions/VERSION` and inspect `gh release view "v$version" --repo mongoid/mongoid_orderable` to confirm a published, non-draft release. If interrupted, resume only the missing publication step.
Pass `-f version=x.y.z` to release a different version. Dispatching starts a real release; do not merge into `master` while it runs. The workflow prepares the release commit, starts a single-node MongoDB 8.0 replica set for the transaction specs, runs lint and specs on Ruby 3.3, builds the gem, preserves recovery artifacts, publishes to RubyGems, pushes the release commit and `v` tag, and creates a GitHub Release with the changelog notes and the gem attached. It then increments the patch version, adds a new `(Next)` section, and pushes the next development commit. Verify the published version on [RubyGems](https://rubygems.org/gems/mongoid_orderable), the tag, the [GitHub Release](https://github.com/mongoid/mongoid_orderable/releases), and the next development commit.

## Next Development Version
## Recover a Partial Release

Increment the patch version in `lib/mongoid/orderable/version.rb`, add a new dated-as-`Next` changelog section with a contribution placeholder, and commit and push the changes to `master`.
Inspect the failed run, RubyGems, remote commits and tags, and the GitHub Release before retrying. Publication may have succeeded even if a later step failed. Never move a published tag or republish a version with different contents. Use the run's retained recovery artifacts and the upstream [recovery instructions](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#recovery-artifacts).
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ end

Bundler::GemHelper.install_tasks

if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
Gem.loaded_specs.key?('ruby-gem-release')
require_relative 'script/release'
MongoidOrderableRelease.workflow.install_tasks

%w[release release:rubygem_push release:source_control_push].each do |name|
Rake::Task[name].clear
desc 'Disabled; releases run through GitHub Actions, see RELEASING.md'
task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" }
end
end

require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
Expand Down
3 changes: 1 addition & 2 deletions mongoid_orderable.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'mongoid/orderable/version'
require_relative 'lib/mongoid/orderable/version'

Gem::Specification.new do |gem|
gem.name = 'mongoid_orderable'
Expand Down
15 changes: 15 additions & 0 deletions script/release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

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

# Builds the ruby-gem-release workflow used by the Rakefile, the Release GitHub Actions workflow, and spec/release.
module MongoidOrderableRelease
def self.workflow(**options)
RubyGemRelease::Workflow::RubyGem.new(
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/mongoid/orderable/version.rb', constant: 'VERSION'),
changelog: RubyGemRelease::Changelog::Intridea.new(placeholder: '* Your contribution here.'),
**options
)
end
end
78 changes: 78 additions & 0 deletions spec/release/release_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
Gem.loaded_specs.key?('ruby-gem-release')
require_relative '../../script/release'
require 'ruby-gem-release/rspec'

RSpec.describe MongoidOrderableRelease do
include RubyGemRelease::RSpec

let(:root) { File.expand_path('../..', __dir__) }
let(:version_path) { 'lib/mongoid/orderable/version.rb' }
let(:fixture_files) do
%w[
mongoid_orderable.gemspec script/release.rb lib/**/*.rb CHANGELOG.md
CONTRIBUTING.md README.md RELEASING.md UPGRADING.md
LICENSE.txt
]
end
let(:placeholder) { '* Your contribution here.' }
let(:note) { '* [#1](https://github.com/mongoid/mongoid_orderable/pull/1): Added a feature.' }

def changelog(notes)
[
'### 1.2.0 (Next)', '', notes, placeholder, '',
'### 1.1.0 (2026/01/01)', '', '* Previous release.', ''
].join("\n")
end

def write_version(project, version)
source = File.read(File.join(root, version_path))
project.write(version_path, source.sub(/VERSION = (['"])[^'"]+\1/, "VERSION = '#{version}'"))
end

def with_project(notes)
with_release_project do |project|
project.environment.merge!(ENV.to_h.slice(*["MONGOID_VERSION"]))
project.copy_files(path: root, files: fixture_files)
project.configure_workflow(require: 'script/release', builder: 'MongoidOrderableRelease.workflow')
project.write('CHANGELOG.md', changelog(notes))
write_version(project, '1.2.0')
project.commit!
yield project
end
end

it 'builds the standard ruby-gem-release workflow' do
expect(described_class.workflow).to be_a(RubyGemRelease::Workflow::RubyGem)
end

it 'dates the release and prepares the next patch version' do
with_project(note) do |project|
project.release!

released = project.remote_file('v1.2.0', 'CHANGELOG.md')
expect(released).to match(%r{\A### 1\.2\.0 \(\d{4}/\d{2}/\d{2}\)\n\n})
expect(released).to include(note)
expect(released).not_to include('(Next)', placeholder)
expect(project.remote_file('v1.2.0', version_path)).to include("VERSION = '1.2.0'")
pending = project.remote_file('master', 'CHANGELOG.md')
expect(pending).to start_with("### 1.2.1 (Next)\n\n#{placeholder}\n\n### 1.2.0 (")
expect(project.remote_file('master', version_path)).to include("VERSION = '1.2.1'")
expect(project.git('status', '--porcelain')).to be_empty
end
end

it 'rejects placeholder-only notes without changing files or remote refs' do
with_project('') do |project|
original = project.git('rev-parse', 'origin/master')
project.run_task('release:workflow:capture')

expect { project.run_task('release:validate') }.to raise_error(RuntimeError, /no pending changelog notes/)
expect(project.git('status', '--porcelain')).to be_empty
expect(project.git('rev-parse', 'origin/master')).to eq(original)
end
end
end
end