Skip to content

Release

Release #18

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version_bump_command:
description: 'Type of semantic version bump'
required: true
type: choice
options:
- major
- minor
- patch
- premajor
- preminor
- prepatch
- prerelease
no_release:
description: "Don't create a Github Release or tag with the new version number"
required: true
type: boolean
no_publish:
description: "Don't publish the new version to pypi"
required: true
type: boolean
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Permacache Poetry
id: cache-poetry
uses: actions/cache@v4
with:
path: ~/.poetry
key: poetry
- name: Install Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
pipx install poetry==1.8.3
shell: bash
- name: Ensure Pipx Paths
run: |
pipx ensurepath
# Optionally check which packages were restored from the cache:
pipx list
shell: bash
- name: Bump version and add to env vars
id: bump-version
run: |
poetry version ${{ inputs.version_bump_command }}
echo "NEW_VERSION=$( poetry version --short )" >> "$GITHUB_ENV"
- name: Check Version
id: check-version
run: |
[[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true >> "$GITHUB_OUTPUT"
- name: Check pyproject.toml validity
run: poetry check --no-interaction
- name: Commit the changes to pyproject.toml
if: ${{ !inputs.no_release }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "ci: bump version to ${{ env.NEW_VERSION }} [skip-ci]"
file_pattern: 'pyproject.toml'
- name: Create and push tag
if: ${{ !inputs.no_release }}
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
default_bump: false
default_prerelease_bump: false
custom_tag: ${{ env.NEW_VERSION }}
- name: Build project for distribution
run: |
poetry build
- name: Create Release
if: ${{ !inputs.no_release }}
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
tag: ${{ steps.tag_version.outputs.new_tag }}
skipIfReleaseExists: true
draft: false
allowUpdates: true
generateReleaseNotes: false
body: ${{ steps.tag_version.outputs.changelog }}
artifacts: "dist/*"
prerelease: steps.check-version.outputs.prerelease == 'true'
- name: Publish to testPyPI
if: ${{ !inputs.no_publish }}
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi ${{ secrets.TESTPYPI_API_TOKEN }}
poetry publish -r testpypi
- name: Publish to Pypi
if: ${{ !inputs.no_publish }}
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
poetry publish