Skip to content

Release

Release #24

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
release_type:
description: "release type"
required: true
default: dev
type: choice
options:
- major
- minor
- patch
- pre
- dev
jobs:
Release:
runs-on: ubuntu-latest
if: ${{ always() && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4.0.0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- name: Install Hatch
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Check release requirements
run: |
# check that hatch can access the version
hatch version ||
{ echo "no version info found with Hatch, exiting" && exit 1; }
# check for "## Unreleased Changes" section in changelog if it exists
[[ -f CHANGELOG.md ]] &&
{ grep -q "## Unreleased Changes" CHANGELOG.md ||
{ echo "Did not find '##Unreleased Changes' section in changelog. \
Please document your changes." && exit 1; }; }
- name: Bump version and update changelog
run: |
VERSION=`hatch version`
hatch version ${{ inputs.release_type }}
NEW_VERSION=`hatch version`
echo "bumping version: $VERSION → $NEW_VERSION"
now=$(date +"%b. %d, %Y")
# check that the new version is not already documented in the changelog
[[ -f CHANGELOG.md ]] &&
{ grep -q "## v$NEW_VERSION" CHANGELOG.md &&
{ echo "Version 'v$NEW_VERSION' is already documented in CHANGELOG.md. \
Please dont add versions manually but use '## Unreleased Changes' header." &&
exit 1; }; }
[[ -f CHANGELOG.md ]] &&
sed -i "s/## Unreleased Changes/## v$NEW_VERSION - $now/" CHANGELOG.md
[[ -f CHANGELOG.md ]] && sed -i '3i ## Unreleased Changes\n\n' CHANGELOG.md
# change image links in the readme
[[ -f README.md ]] &&
sed -i "/https:\/\/github.com/s/\/v$VERSION\//\/v$NEW_VERSION\//" README.md
git config user.name github-actions
git config user.email github-actions@github.com
git add -A
git commit -m "bump version: $VERSION → $NEW_VERSION"
git tag -a "v$NEW_VERSION" -m "release v$NEW_VERSION"
git push && git push --tags
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_VERSION=`hatch version`
TAG="v$NEW_VERSION"
gh release create "$TAG" \
--repo="$GITHUB_REPOSITORY" \
--title="${TAG}" \
--generate-notes \
--verify-tag