Skip to content

Commit

Permalink
Merge pull request #72 from maxmind/greg/trusted-publishing
Browse files Browse the repository at this point in the history
Use trusted publishing
  • Loading branch information
horgh authored Jan 15, 2024
2 parents 6bb0726 + f3fbc5d commit 21cb417
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 44 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
release:
types:
- published

jobs:
push:
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ruby

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


# Prerequisites

## Step 1
Sign up for an account at rubygems.org if you don't have one.

Enable multi factor authentication (for both UI and API).


## Step 2
Ask someone who is an owner of the gem to add you as one.

They do this by using the `gem owner` command
([docs](https://guides.rubygems.org/command-reference/#gem-owner)).


## Step 3
Run `gem signin`. This will prompt you for your username and password, and
then create an API key for you. Select the scopes `index_rubygems` and
`push_rubygem` (I'm not sure the former is required, but anyway).

Note you may need an up to date version of rubygems to do this as I believe
support for API keys like this is a newer addition.
See
[here](https://github.com/maxmind/minfraud-api-ruby/blob/main/README.dev.md).
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'

Expand Down
59 changes: 59 additions & 0 deletions dev-bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -eu -o pipefail

changelog=$(cat CHANGELOG.md)

regex='
## ([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
((.|
)*)
'

if [[ ! $changelog =~ $regex ]]; then
echo "Could not find date line in change log!"
exit 1
fi

version="${BASH_REMATCH[1]}"
date="${BASH_REMATCH[2]}"
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -E '/^## [0-9]+\.[0-9]+\.[0-9]+/,$!p')"

echo "$notes"
if [[ "$date" != "$(date +"%Y-%m-%d")" ]]; then
echo "$date is not today!"
exit 1
fi

tag="v$version"

if [ -n "$(git status --porcelain)" ]; then
echo ". is not clean." >&2
exit 1
fi

perl -pi -e "s/(?<=s.version\s{,20}=\s{,20}\').+?(?=\')/$version/g" maxmind-db.gemspec

echo $"Test results:"

rake

echo $'\nDiff:'
git diff

echo $'\nRelease notes:'
echo "$notes"

read -e -p "Commit changes and push to origin? " should_push

if [ "$should_push" != "y" ]; then
echo "Aborting"
exit 1
fi

git commit -m "Update for $tag" -a

git push

gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"
2 changes: 1 addition & 1 deletion maxmind-db.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

0 comments on commit 21cb417

Please sign in to comment.