Version, Release, and Publish #16
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 }} | |
OLD_VERSION=$(grep 'version\s\=\s\".*\"' pyproject.toml | grep -o '"[^"]\+"' | sed 's/\"//g') | |
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 | |
echo "The current version matches the new version: $NEW_VERSION" | |
exit 1 | |
fi | |
create-github-release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
needs: version | |
permissions: | |
contents: read | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Check out latest HEAD commit | |
run: | | |
git fetch | |
git status | |
git checkout master | |
git checkout HEAD^ | |
git checkout master | |
- 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 | |
permissions: | |
contents: read | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Check out latest HEAD commit | |
run: | | |
git fetch | |
git log | |
git checkout 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 }} |