Skip to content

Commit

Permalink
Publish from GitHub Action and add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Jan 15, 2024
1 parent 6bb0726 commit 4e65216
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 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
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='
## v([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 '/^## v[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"

0 comments on commit 4e65216

Please sign in to comment.