Skip to content

Commit 21cb417

Browse files
authored
Merge pull request #72 from maxmind/greg/trusted-publishing
Use trusted publishing
2 parents 6bb0726 + f3fbc5d commit 21cb417

File tree

5 files changed

+91
-44
lines changed

5 files changed

+91
-44
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

README.dev.md

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,4 @@
11
# How to release
2-
* Ensure tests pass: `rake`
3-
* Update changelog: Set version and release date
4-
* Set version in `maxmind-db.gemspec`
5-
* Add them: `git add -p`
6-
* Create a branch e.g. `horgh/release` and switch to it.
7-
* `main` is protected.
8-
* Commit: `git commit -m v1.0.0`
9-
* Tag: `git tag -a v1.0.0 -m v1.0.0`
10-
* Clean up to be sure nothing stray gets into gem: `git clean -dxff`
11-
* Create `.gem` file: `gem build maxmind-db.gemspec`
12-
* Complete prerequisites (see below)
13-
* You only need to do this once. You can tell if this is necessary if you
14-
are lacking `:rubygems_api_key` in `~/.local/share/gem/credentials`
15-
(previously `~/.gem/credentials`)
16-
* Upload to rubygems.org: `gem push maxmind-db-1.0.0.gem`
17-
* Push: `git push`
18-
* Push tag: `git push --tags`
19-
* Make a PR and get it merged.
20-
* Double check it looks okay at https://rubygems.org/gems/maxmind-db and
21-
https://www.rubydoc.info/gems/maxmind-db
222

23-
24-
# Prerequisites
25-
26-
## Step 1
27-
Sign up for an account at rubygems.org if you don't have one.
28-
29-
Enable multi factor authentication (for both UI and API).
30-
31-
32-
## Step 2
33-
Ask someone who is an owner of the gem to add you as one.
34-
35-
They do this by using the `gem owner` command
36-
([docs](https://guides.rubygems.org/command-reference/#gem-owner)).
37-
38-
39-
## Step 3
40-
Run `gem signin`. This will prompt you for your username and password, and
41-
then create an API key for you. Select the scopes `index_rubygems` and
42-
`push_rubygem` (I'm not sure the former is required, but anyway).
43-
44-
Note you may need an up to date version of rubygems to do this as I believe
45-
support for API keys like this is a newer addition.
3+
See
4+
[here](https://github.com/maxmind/minfraud-api-ruby/blob/main/README.dev.md).

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'bundler/gem_tasks'
34
require 'rake/testtask'
45
require 'rubocop/rake_task'
56

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+
## ([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 '/^## [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/(?<=s.version\s{,20}=\s{,20}\').+?(?=\')/$version/g" maxmind-db.gemspec
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"

maxmind-db.gemspec

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

33
Gem::Specification.new do |s|
44
s.authors = ['William Storey']
5-
s.files = Dir['**/*']
5+
s.files = Dir['**/*'].difference(Dir['.github/**/*', 'dev-bin/**/*'])
66
s.name = 'maxmind-db'
77
s.summary = 'A gem for reading MaxMind DB files.'
88
s.version = '1.2.0'

0 commit comments

Comments
 (0)