Publish to PyPI #14
Workflow file for this run
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: Publish to PyPI | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to release' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- 'major' | |
- 'minor' | |
- 'patch' | |
repository: | |
description: 'Repository to publish to' | |
required: true | |
default: 'testpypi' | |
type: choice | |
options: | |
- 'pypi' | |
- 'testpypi' | |
permissions: | |
contents: write | |
id-token: write | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Install Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install Poetry | |
uses: Gr1N/setup-poetry@v8 | |
with: | |
poetry-version: '1.8.3' | |
- name: Install dependencies | |
run: poetry install | |
- name: Bump version | |
id: bump_version | |
run: | | |
echo "::set-output name=previous_version::$(poetry run python handle_versioning.py read)" | |
poetry run python handle_versioning.py ${{ github.event.inputs.version }} | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
git add pyproject.toml | |
new_version=$(poetry run python handle_versioning.py read) | |
git commit -m "Bump version to $new_version" | |
git push | |
echo "::set-output name=latest_version::$new_version | |
- name: Get merged PRs | |
id: pr_notes | |
run: | | |
latest_tag=${{ steps.bumb_version.outputs.latest_version }} | |
previous_tag=${{ steps.bumb_version.outputs.previous_version }} | |
if [ -z "$previous_tag" ]; then | |
pr_descriptions=$(git log $latest_tag --merges --pretty=format:"%s%n%b" --grep='Merge pull request') | |
else | |
pr_descriptions=$(git log $previous_tag..$latest_tag --merges --pretty=format:"%s%n%b" --grep='Merge pull request') | |
fi | |
echo "::set-output name=pr_descriptions::$pr_descriptions" | |
- name: Create tag | |
id: create_tags | |
run: | | |
current_version=$(steps.bump_version.outputs.latest_version) | |
git tag $current_version | |
git push origin $current_version | |
- name: Create release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.bump_version.outputs.latest_version}} | |
release_name: Release ${{ steps.bump_version.outputs.latest_version}} | |
body: | | |
Added Features: | |
${{steps.pr_notes.outputs.pr_descriptions}} | |
draft: false | |
prerelease: false | |
- name: Build package | |
run: | | |
poetry build | |
- name: Publish to TestPyPI or PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: ${{ github.event.inputs.repository == 'pypi' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }} | |
username: __token__ | |
password: ${{ github.event.inputs.repository == 'pypi' && secrets.PYPI_API_TOKEN || secrets.TEST_PYPI_API_TOKEN }} | |
env: | |
POETRY_PYPI_TOKEN: ${{ github.event.inputs.repository == 'pypi' && secrets.PYPI_POETRY_TOKEN || secrets.TEST_PYPI_POETRY_TOKEN }} |