Version, Release, and Publish #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
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 | |
create-github-release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
needs: version | |
steps: | |
- name: Create GitHub release | |
uses: elgohr/Github-Release-Action@v5 | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
title: ${{ steps.update-version.outputs.VERSION }}" | |
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 }} |