Skip to content

Version, Release, and Publish #3

Version, Release, and Publish

Version, Release, and Publish #3

on:
workflow_dispatch: # this is required to manually run workflows; it is terribly named
inputs:
new-version:
description: The new version; e.g. '1.0.0'.
required: true
name: Version, Release, and Publish
jobs:
version:
name: Increment Version
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the added or changed files to the repository.
contents: write
steps:
- name: Checkout latest
uses: actions/checkout@v4
- name: Update pyproject.toml version
id: update-version
run: |
NEW_VERSION=${{ github.event.inputs.new-version }}
OLD_VERSION=$(grep -o 'version\s=\s.*' pyproject.toml)
if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then
sed -i "s/^version\s*=.*/version = \"$NEW_VERSION\"/" pyproject.toml
cat pyproject.toml
# uhh https://github.com/marketplace/actions/checkout#Push-a-commit-using-the-built-in-token
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "updated pyproject.toml version"
git push
echo "VERSION=$THIS_VERSION" >> $GITHUB_OUTPUT
else
exit 0
fi
create-github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: version
steps:
- name: Checkout latest since pyproject.toml update
uses: actions/checkout@v4
with:
ref: "HEAD"
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
# This token is provided by Actions, you do not need to create your own token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.new-version }}
release_name: v${{ github.event.inputs.new-version }}
draft: false
prerelease: false
publish-to-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: create-github-release
steps:
- name: Checkout latest since pyproject.toml update
uses: actions/checkout@v4
with:
ref: "HEAD"
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1.8
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}