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

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write
id-token: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Ruby
uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
with:
bundler-cache: true

- name: Check tag matches version.rb
run: |
version="$(ruby -Ilib -remailable/version -e 'print Emailable::VERSION')"
if [ "$GITHUB_REF_NAME" != "$version" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match version.rb version $version. Run 'bundle exec rake release:prepare[x.y.z]'."
exit 1
fi

- name: Run tests
run: bundle exec rake test

- name: Publish to RubyGems
uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1

- name: Create GitHub release
run: gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes
env:
GH_TOKEN: ${{ github.token }}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
`rake test` to run the tests. You can also run `bin/console` for an interactive
prompt that will allow you to experiment.

## Cutting a Release

Run `bundle exec rake "release:prepare[x.y.z]"` on an up to date `master` with
a clean tree, then `git push --follow-tags`. It runs the tests and RuboCop,
bumps `lib/emailable/version.rb`, commits, and tags `x.y.z`. Pushing the tag
triggers the release workflow, which publishes to RubyGems and creates the
GitHub release.

## Contributing

Bug reports and pull requests are welcome on GitHub at
Expand Down
35 changes: 35 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
require 'bundler/gem_tasks'
require 'rake/testtask'

# Tags are bare versions like 4.2.3, not Bundler's default v4.2.3.
Bundler::GemHelper.instance.define_singleton_method(:version_tag) do
version.to_s
end

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

task :default => :test

namespace :release do
desc 'Check, bump, commit, and tag a release, e.g. rake release:prepare[1.2.3]'
task :prepare, [:version] do |_, args|
version = args[:version].to_s
abort 'error: version must be x.y.z' unless version.match?(/\A\d+\.\d+\.\d+\z/)
abort 'error: working tree not clean' unless `git status --porcelain`.empty?
abort 'error: release from master' unless `git branch --show-current`.strip == 'master'

sh 'git fetch -q --tags origin master'
unless `git rev-parse HEAD` == `git rev-parse origin/master`
abort 'error: master is not in sync with origin'
end

current = Bundler::GemHelper.instance.gemspec.version
unless Gem::Version.new(version) > current
abort "error: version must be greater than #{current}"
end
abort "error: tag #{version} already exists" unless `git tag -l #{version}`.empty?

Rake::Task[:test].invoke
sh 'bundle exec rubocop'

path = 'lib/emailable/version.rb'
Comment thread
jclusso marked this conversation as resolved.
Resolved
File.write(path, File.read(path).sub(/VERSION = '.*'/, "VERSION = '#{version}'"))
sh "git commit -q -am 'Release #{version}'"
sh "git tag -a #{version} -m #{version}"
puts "Tagged #{version}. Push the commit and tag to release: git push --follow-tags"
end
end
3 changes: 2 additions & 1 deletion emailable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Gem::Specification.new do |s|
s.metadata = {
'bug_tracker_uri' => 'https://github.com/emailable/emailable-ruby/issues',
'documentation_uri' => 'https://emailable.com/docs/api/?ruby',
'source_code_uri' => 'https://github.com/emailable/emailable-ruby'
'source_code_uri' => 'https://github.com/emailable/emailable-ruby',
'rubygems_mfa_required' => 'true'
}

s.files = `git ls-files`.split("\n")
Expand Down
Loading