Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use trusted publishing #72

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
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