Release on PyPI and GitHub #2
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
name: Release on PyPI and GitHub | |
on: | |
workflow_dispatch: | |
inputs: | |
release-type: | |
description: "Release type" | |
required: true | |
default: "tag-num" | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
- upgrade-beta | |
- new-beta-major | |
- new-beta-minor | |
- new-beta-patch | |
- final | |
skip-pypi: | |
description: "If true, skip publishing to PyPI" | |
default: false | |
type: boolean | |
jobs: | |
bumpver-pyproject: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.current-version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Install bumpver | |
run: python -m pip install bumpver | |
# Evaluate input and bumpver accordingly | |
- name: Execute script bumpver | |
run: ./.github/scripts/bump.sh ${{ inputs.release-type }} | |
# Commit modifications to pyproject.toml | |
- name: Commit changes | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
git commit -a -m "bump: bumpver" | |
git push | |
# Store current version for later use | |
- name: Current version | |
id: current-version | |
run: | | |
ver=$(bumpver show -n --environ | grep CUR | awk '{gsub(/CURRENT_VERSION=/, ""); print}') | |
echo "version=${ver}" >> "$GITHUB_OUTPUT" | |
build-n-publish: | |
name: Build and publish | |
if: ${{ !inputs.skip-pypi }} | |
needs: bumpver-pyproject | |
runs-on: ubuntu-latest | |
steps: | |
# Force with ref as https://github.com/orgs/community/discussions/110853 | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
# Build wheel to upload | |
- name: Install build and build a binary wheel | |
run: python -m pip install build && python -m build | |
# Publish to PyPI | |
- name: Publish distribution to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_TOKEN }} | |
tag-and-release: | |
name: Tag and release on Github | |
needs: [bumpver-pyproject] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
VERSION: ${{ needs.bumpver-pyproject.outputs.version }} | |
BETA: ${{ inputs.release-type == 'upgrade-beta' || startsWith(inputs.release-type, 'new-beta')}} | |
with: | |
name: ${{ env.VERSION }} | |
tag_name: ${{ env.VERSION }} | |
generate_release_notes: true | |
draft: false | |
prerelease: ${{ env.BETA }} |