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
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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-grid_fs' && 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 27017:27017 mongo:8.0
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 @@ -12,3 +12,5 @@ Gemfile.danger.lock
gemfiles/*.lock
pkg/*
coverage/
/vendor/bundle
/.bundle
5 changes: 5 additions & 0 deletions .spellcheck.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fredjean
Fs
fs
Gemfile
gemspec
GridFS
GridFs
GridIO
Expand All @@ -29,13 +30,15 @@ Ilib
InterfaceTests
interfacetests
IOProxy
JRuby
laCour
linter
localhost
md
minitest
Mongoid
mongoid
MongoidGridFsRelease
namespace
namespaces
ngty
Expand All @@ -53,7 +56,9 @@ README
Rebase
rebase
Rethrow
RSpec
RuboCop
RubyGems
StringIO
TODO
txt
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Your contribution here.
* [#90](https://github.com/mongoid/mongoid-grid_fs/pull/90): 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).
* [#91](https://github.com/mongoid/mongoid-grid_fs/pull/91): 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).
* [#92](https://github.com/mongoid/mongoid-grid_fs/pull/92): Release with ruby-gem-release from a manually dispatched GitHub Actions workflow using RubyGems Trusted Publishing, with dry runs - [@dblock](https://github.com/dblock).

### 2.6.0 (2024/11/19)

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

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
35 changes: 35 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Releasing Mongoid::GridFs

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-grid_fs`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.

## One-Time Setup

Before the first automated release, a maintainer must:

1. Create the GitHub environment `release` in `mongoid/mongoid-grid_fs`, for example with `gh api --method PUT repos/mongoid/mongoid-grid_fs/environments/release`, and restrict its deployment branches to `master`. Add required reviewers to require maintainer approval before publication.
2. At [mongoid-grid_fs's trusted publishers](https://rubygems.org/gems/mongoid-grid_fs/trusted_publishers), add a GitHub Actions publisher with repository owner `mongoid`, repository `mongoid-grid_fs`, 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).

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
gh workflow run release.yml --repo mongoid/mongoid-grid_fs --ref master -f dry-run=true
```

## Prepare

Start with a clean, up-to-date `master` and verify that the latest [CI checks](https://github.com/mongoid/mongoid-grid_fs/actions) pass. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/mongoid/grid_fs/version.rb](lib/mongoid/grid_fs/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. The release test in [test/release_test.rb](test/release_test.rb) runs 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 workflow run release.yml --repo mongoid/mongoid-grid_fs --ref master
```

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 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/mongoid-grid_fs), the tag, the [GitHub Release](https://github.com/mongoid/mongoid-grid_fs/releases), and the next development commit.

## Recover a Partial Release

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
@@ -1,4 +1,16 @@
require 'bundler/gem_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'
MongoidGridFsRelease.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 'bundler/setup'
require 'rake/testtask'

Expand Down
2 changes: 1 addition & 1 deletion mongoid-grid_fs.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'mongoid/grid_fs/version'
require_relative 'lib/mongoid/grid_fs/version'

Gem::Specification.new do |spec|
spec.name = 'mongoid-grid_fs'
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 MongoidGridFsRelease
def self.workflow(**options)
RubyGemRelease::Workflow::RubyGem.new(
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/mongoid/grid_fs/version.rb', constant: 'VERSION'),
changelog: RubyGemRelease::Changelog::Intridea.new(placeholder: '* Your contribution here.'),
**options
)
end
end
65 changes: 65 additions & 0 deletions test/release_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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 'minitest/autorun'
require_relative '../script/release'
require 'ruby-gem-release/rspec'

class ReleaseTest < Minitest::Test
include RubyGemRelease::RSpec

ROOT = File.expand_path('..', __dir__)
VERSION_PATH = 'lib/mongoid/grid_fs/version.rb'
PLACEHOLDER = '* Your contribution here.'
NOTE = '* [#1](https://github.com/mongoid/mongoid-grid_fs/pull/1): Added a feature.'
FILES = %w[mongoid-grid_fs.gemspec script/release.rb lib/**/*.rb CHANGELOG.md CONTRIBUTING.md LICENSE README.md].freeze

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

def with_project(notes)
with_release_project do |project|
project.copy_files(path: ROOT, files: FILES)
project.configure_workflow(require: 'script/release', builder: 'MongoidGridFsRelease.workflow')
project.write('CHANGELOG.md', changelog(notes))
source = File.read(File.join(ROOT, VERSION_PATH))
project.write(VERSION_PATH, source.sub(/VERSION = (['"])[^'"]+\1/, "VERSION = '1.2.0'"))
project.commit!
yield project
end
end

def test_builds_the_standard_workflow
assert_kind_of RubyGemRelease::Workflow::RubyGem, MongoidGridFsRelease.workflow
end

def test_dates_the_release_and_prepares_the_next_patch_version
with_project(NOTE) do |project|
project.release!

released = project.remote_file('v1.2.0', 'CHANGELOG.md')
assert_match(%r{\A### 1\.2\.0 \(\d{4}/\d{2}/\d{2}\)\n\n}, released)
assert_includes released, NOTE
refute_includes released, PLACEHOLDER
assert_includes project.remote_file('v1.2.0', VERSION_PATH), "VERSION = '1.2.0'"
assert project.remote_file('master', 'CHANGELOG.md').start_with?("### 1.2.1 (Next)\n\n#{PLACEHOLDER}\n\n### 1.2.0 (")
assert_includes project.remote_file('master', VERSION_PATH), "VERSION = '1.2.1'"
assert_empty project.git('status', '--porcelain')
end
end

def test_rejects_placeholder_only_notes_without_changing_remote_refs
with_project('') do |project|
original = project.git('rev-parse', 'origin/master')
project.run_task('release:workflow:capture')

error = assert_raises(RuntimeError) { project.run_task('release:validate') }
assert_match(/no pending changelog notes/, error.message)
assert_empty project.git('status', '--porcelain')
assert_equal original, project.git('rev-parse', 'origin/master')
end
end
end
end
Loading