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/mongo_session_store' && github.ref == 'refs/heads/main'
uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.9.0
with:
ruby-version: '3.3'
gemfile: gemfiles/rails-current-mongoid.gemfile
version: ${{ inputs.version }}
dry-run: ${{ inputs.dry-run }}
test: |
docker run --detach --name mongodb --publish 27017:27017 mongo:8.0
timeout 60 bash -c 'until docker exec mongodb mongosh --quiet --eval "db.adminCommand({ping: 1})"; do sleep 1; done'
bundle exec rake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ spec/support/apps/rails_*/db/*.sqlite3-*
spec/support/apps/rails_*/log/
*.gem
/tmp/
/vendor/bundle
/.bundle
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Metrics/BlockLength:
merge:
- Exclude
Exclude:
- 'spec/release/release_spec.rb'
- Gemfile

Layout/LineLength:
Expand Down
11 changes: 5 additions & 6 deletions .spellcheck.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
ActionDispatch
ActionPack
actionpack
brianhempel
Brickley
Bruijn
BSON
Bundler
capybara
CHANGELOG
changelog
CLI
DataMapper
dblock
de
ENV
env
Gemfile
gemfile
Gemfiles
gemspec
Hempel
hsbt
html
initializer
ismaster
JRuby
linter
lt
marshalled
md
memuller
middleware
Mongo
mongo
mongod
Mongoid
MongoMapper
MongoSessionStore
MongoSessionStoreRelease
MongoStore
Mérouze
nmerouze
ODM
Pitale
Racco
Rakefile
rb
README
rspec
RuboCop
rubocop
RubyGems
shingara
streetlogics
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.
* [#59](https://github.com/mongoid/mongo_session_store/pull/59): 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).
* [#60](https://github.com/mongoid/mongo_session_store/pull/60): 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).
* [#61](https://github.com/mongoid/mongo_session_store/pull/61): Release with ruby-gem-release from a manually dispatched GitHub Actions workflow using RubyGems Trusted Publishing, with dry runs - [@dblock](https://github.com/dblock).

### 3.3.0 (2026/10/18)

Expand Down
42 changes: 20 additions & 22 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
# Releasing
# Releasing MongoSessionStore

Release from a clean local checkout of the upstream repository, not a fork. You need 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 `main` in `mongoid/mongo_session_store`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.

## Prepare
## One-Time Setup

1. Run `git switch main`, `git pull --ff-only`, and confirm that `origin` points to `mongoid/mongo_session_store`.
2. Choose the next semantic version, update `lib/mongo_session_store/version.rb`, and replace the unreleased changelog heading with the version and release date. Remove the contribution placeholder.
3. With MongoDB running, install dependencies and run `bundle exec rake test` using each supported adapter's `BUNDLE_GEMFILE`, for example `gemfiles/rails-6.0-mongo.gemfile` and `gemfiles/rails-6.0-mongoid.gemfile`. Run `bundle exec rubocop` with the default Gemfile.
4. Commit the preparation, push `main`, and wait for the complete GitHub Actions matrix to pass for that commit.
Before the first automated release, a maintainer must:

## Publish
1. Create the GitHub environment `release` in `mongoid/mongo_session_store`, for example with `gh api --method PUT repos/mongoid/mongo_session_store/environments/release`, and restrict its deployment branches to `main`. Add required reviewers to require maintainer approval before publication.
2. At [mongo_session_store's trusted publishers](https://rubygems.org/gems/mongo_session_store/trusted_publishers), add a GitHub Actions publisher with repository owner `mongoid`, repository `mongo_session_store`, 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 `main`. See the upstream [setup and permissions guidance](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#one-time-setup).

Do not use the legacy `rake release` task: it assumes `master` and performs interactive edits. Build and publish the prepared version explicitly:
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:

```sh
version=3.2.2 # Replace with the version being released.
gem build mongo_session_store.gemspec
git tag "v$version"
git push origin "v$version"
gem push "mongo_session_store-$version.gem"
gh workflow run release.yml --repo mongoid/mongo_session_store --ref main -f dry-run=true
```

Enter a fresh RubyGems MFA code when prompted. Create a GitHub release from the same tag, using the matching changelog section as the release notes:
## Prepare

Start with a clean, up-to-date `main` and verify that the latest [CI checks](https://github.com/mongoid/mongo_session_store/actions) pass. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/mongo_session_store/version.rb](lib/mongo_session_store/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
gh release create "v$version" --repo mongoid/mongo_session_store \
--verify-tag --title "$version" --notes-file /path/to/release-notes.md --latest
gh workflow run release.yml --repo mongoid/mongo_session_store --ref main
```

Verify the exact version at `https://rubygems.org/gems/mongo_session_store/versions/VERSION` and inspect `gh release view "v$version" --repo mongoid/mongo_session_store` to confirm a published, non-draft release.

If publication is interrupted, check the remote tag, RubyGems version, and GitHub release first. Resume only the missing step; never move a published tag or rebuild an already published version. If the gem push needs a new code, retry that command with `--otp CODE`.
Pass `-f version=x.y.z` to release a different version. Dispatching starts a real release; do not merge into `main` while it runs. The workflow prepares the release commit, starts MongoDB 8.0, 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/mongo_session_store), the tag, the [GitHub Release](https://github.com/mongoid/mongo_session_store/releases), and the next development commit.

## Next Development Version
## Recover a Partial Release

Increment the patch version in `lib/mongo_session_store/version.rb`, add a new `## (unreleased)` section with a contribution placeholder, and commit and push the changes to `main`. Remove the local built gem after successful publication.
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).
67 changes: 9 additions & 58 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,66 +23,17 @@ end
desc "Run the mongo_session_store gem test suite."
RSpec::Core::RakeTask.new :test => :mongo_prepare

desc "Release a new version of the mongo_session_store gem"
task :release do
GEMSPEC_NAME = "mongo_session_store"
GEM_NAME = "mongo_session_store"
VERSION_FILE = "lib/mongo_session_store/version.rb"
require "bundler/gem_tasks"

def reload_version
if defined?(MongoSessionStore::VERSION)
MongoSessionStore.send(:remove_const, :VERSION)
end
load File.expand_path(VERSION_FILE)
end

raise "$EDITOR should be set" unless ENV["EDITOR"]

def build_and_push_gem
puts "# Building gem"
system "gem build #{GEMSPEC_NAME}.gemspec"
puts "# Publishing Gem"
system "gem push #{GEM_NAME}-#{gem_version}.gem"
end

def update_repo
puts `git commit -am "Bump to #{version} [ci skip]"`
begin
puts `git tag #{version}`
puts `git push origin #{version}`
puts `git push origin master`
rescue
raise %(Tag: "#{version}" already exists)
end
end

def changes
git_status_to_array(`git status -s -u`)
end

def gem_version
MongoSessionStore::VERSION
end

def version
@version ||= "v" << gem_version
end

def git_status_to_array(changes)
changes.split("\n").map { |change| change.gsub(/^.. /, "") }
end

raise "Branch should hold no uncommitted file change)" unless changes.empty?

reload_version
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"
MongoSessionStoreRelease.workflow.install_tasks

system("$EDITOR #{VERSION_FILE}")
if changes.include?(VERSION_FILE)
reload_version
build_and_push_gem
update_repo
else
raise "Actually change the version in: #{VERSION_FILE}"
%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

Expand Down
5 changes: 5 additions & 0 deletions gemfiles/rails-current-mongo.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ gem "benchmark"
gem "ostruct"
gem "simplecov", "~> 0.22", :require => false if ENV["COVERAGE"] == "true"

if RUBY_ENGINE == "ruby" && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3")
gem "commonmarker", "~> 2.10", :require => false
gem "ruby-gem-release", "0.9.0", :require => false
end

gemspec :path => "../"
16 changes: 16 additions & 0 deletions script/release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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 MongoSessionStoreRelease
def self.workflow(**options)
RubyGemRelease::Workflow::RubyGem.new(
:version => RubyGemRelease::Version::RubyConstant.new(:path => "lib/mongo_session_store/version.rb",
:constant => "VERSION"),
:changelog => RubyGemRelease::Changelog::Intridea.new(:placeholder => "* Your contribution here."),
**options
)
end
end
85 changes: 85 additions & 0 deletions spec/release/release_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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 MongoSessionStoreRelease do
include RubyGemRelease::RSpec

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

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 prepare(project, notes)
project.environment.merge!(ENV.to_h.slice("MONGOID_VERSION", "RAILS_VERSION",
"SQLITE_VERSION"))
project.copy_files(:path => root, :files => fixture_files)
project.configure_workflow(:require => "script/release",
:builder => "MongoSessionStoreRelease.workflow")
project.write("CHANGELOG.md", changelog(notes))
write_version(project, "1.2.0")
project.commit!
end

def with_project(notes)
with_release_project do |project|
prepare(project, notes)
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
Loading