Skip to content

Commit e9d72f1

Browse files
authored
Merge pull request #92 from maxmind/greg/release-workflow
Add release workflow using trusted publishing
2 parents 58f1cbc + 8c32191 commit e9d72f1

File tree

6 files changed

+116
-5
lines changed

6 files changed

+116
-5
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
release:
10+
types:
11+
- published
12+
13+
jobs:
14+
push:
15+
if: github.event_name == 'release' && github.event.action == 'published'
16+
runs-on: ubuntu-latest
17+
environment: release
18+
permissions:
19+
id-token: write
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Ruby
23+
uses: ruby/setup-ruby@v1
24+
with:
25+
bundler-cache: true
26+
ruby-version: ruby
27+
28+
- uses: rubygems/release-gem@v1

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## v2.4.0
3+
## v2.4.0 (2024-01-12)
44

55
* Ruby 2.7+ is now required. If you're using Ruby 2.5 or 2.6, please use
66
version 2.3.0 of this gem.

README.dev.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1+
# Prereqs
2+
3+
* You must have a local Ruby environment that can run the tests
4+
via `rake`.
5+
* You must have the [GitHub CLI tool (gh)](https://cli.github.com/)
6+
installed, in your path, and logged into an account that can
7+
make GitHub releases on the repo.
8+
* Your environment also must have `bash`, `git`, `perl`, and `sed`
9+
available.
10+
111
# How to release
212

3-
See
4-
[here](https://github.com/maxmind/MaxMind-DB-Reader-ruby/blob/main/README.dev.md).
13+
* Review open issues and PRs to see if anything needs to be addressed
14+
before release.
15+
* Create a branch e.g. `horgh/release` and switch to it.
16+
* `main` is protected.
17+
* Set the release version and release date in `CHANGELOG.md`. Be sure
18+
the version follows [Semantic Versioning](https://semver.org/).
19+
* Commit these changes.
20+
* Run `dev-bin/release.sh`.
21+
* Verify the release on the GitHub Releases page.
22+
* If everything goes well, the authorized releasers will receive an email
23+
to review the pending deployment. If you are an authorized releaser,
24+
you will need to approve the release deployment run. If you are not,
25+
you will have to wait for an authorized releaser to do so.
26+
* Double check it looks okay at https://rubygems.org/gems/minfraud and
27+
https://www.rubydoc.info/gems/minfraud.
28+
* Make a PR and get it merged.

dev-bin/release.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
changelog=$(cat CHANGELOG.md)
6+
7+
regex='
8+
## v([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
9+
10+
((.|
11+
)*)
12+
'
13+
14+
if [[ ! $changelog =~ $regex ]]; then
15+
echo "Could not find date line in change log!"
16+
exit 1
17+
fi
18+
19+
version="${BASH_REMATCH[1]}"
20+
date="${BASH_REMATCH[2]}"
21+
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -E '/^## v[0-9]+\.[0-9]+\.[0-9]+/,$!p')"
22+
23+
echo "$notes"
24+
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
25+
echo "$date is not today!"
26+
exit 1
27+
fi
28+
29+
tag="v$version"
30+
31+
if [ -n "$(git status --porcelain)" ]; then
32+
echo ". is not clean." >&2
33+
exit 1
34+
fi
35+
36+
perl -pi -e "s/(?<=VERSION = \').+?(?=\')/$version/g" lib/minfraud/version.rb
37+
38+
echo $"Test results:"
39+
40+
rake
41+
42+
echo $'\nDiff:'
43+
git diff
44+
45+
echo $'\nRelease notes:'
46+
echo "$notes"
47+
48+
read -e -p "Commit changes and push to origin? " should_push
49+
50+
if [ "$should_push" != "y" ]; then
51+
echo "Aborting"
52+
exit 1
53+
fi
54+
55+
git commit -m "Update for $tag" -a
56+
57+
git push
58+
59+
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"

lib/minfraud/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module Minfraud
44
# The Gem version.
5-
VERSION = '2.3.0'
5+
VERSION = '2.4.0'
66
end

minfraud.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
1717

1818
spec.required_ruby_version = '>= 2.7.0'
1919

20-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^.gitignore$|^(?:\.github|dev-bin|spec)/}) }
2121
spec.bindir = 'exe'
2222
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2323
spec.require_paths = ['lib']

0 commit comments

Comments
 (0)