Continuous Delivery of Python package #77
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: Continuous Delivery of Python package | |
on: | |
workflow_dispatch: | |
inputs: | |
compiler_wheel: | |
description: "Include compiler wheel?" | |
type: boolean | |
required: true | |
default: true | |
stubs_wheel: | |
description: "Include stubs wheel?" | |
type: boolean | |
required: true | |
default: true | |
bump_version: | |
description: "Bump version, set to false to re-publish with current version" | |
type: boolean | |
required: true | |
default: true | |
publish_github: | |
description: "Publish to Github?" | |
type: boolean | |
required: true | |
default: true | |
publish_pypi: | |
description: "Publish to PyPi?" | |
type: boolean | |
required: true | |
default: true | |
publish_docs: | |
description: "Publish Docs?" | |
type: boolean | |
required: true | |
default: true | |
run_checks: | |
description: "Run checks?" | |
type: boolean | |
required: true | |
default: true | |
dry_run: | |
description: "Dry Run? If true, won't commit or publish anything" | |
type: boolean | |
required: true | |
default: false | |
concurrency: release | |
permissions: | |
contents: write | |
packages: read | |
jobs: | |
release: | |
name: Release Library | |
runs-on: ubuntu-latest | |
permissions: | |
# IMPORTANT: this permission is mandatory for trusted publishing | |
id-token: write | |
contents: write | |
packages: read | |
env: | |
DRY_RUN: ${{ inputs.dry_run && '--noop' || '' }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Fetch entire repository history so we can determine version number from it | |
fetch-depth: 0 | |
token: ${{ secrets.RELEASE_GITHUB_TOKEN }} | |
- name: Install poetry | |
run: pipx install poetry | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12.6" | |
cache: "poetry" | |
- name: Install dependencies | |
run: poetry install --no-interaction --with cicd | |
- name: pre-commit and pytest | |
if: inputs.run_checks | |
run: | | |
set -o pipefail | |
source $(poetry env info --path)/bin/activate | |
pre-commit run --all-files && git diff --exit-code | |
algokit localnet start | |
pytest | |
- name: Get branch name | |
shell: bash | |
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
id: get_branch | |
- name: Set Git user as GitHub actions | |
run: git config --global user.email "[email protected]" && git config --global user.name "github-actions" | |
- name: Update release | |
if: inputs.bump_version | |
run: poetry run semantic-release $DRY_RUN --strict version | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} | |
- name: Create Compiler Wheel | |
if: inputs.compiler_wheel | |
run: poetry build --format wheel | |
- name: Create Stubs Wheel | |
if: inputs.stubs_wheel | |
run: | | |
pushd stubs | |
poetry build --format wheel | |
popd | |
- uses: actions/upload-artifact@v4 # upload artifacts so they are retained on the job | |
with: | |
path: | | |
dist | |
stubs/dist | |
- name: Publish to GitHub | |
if: steps.get_branch.outputs.branch == 'main' && !inputs.dry_run && inputs.publish_github | |
run: poetry run semantic-release $DRY_RUN publish | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} | |
- name: Publish to PyPI - Compiler | |
if: steps.get_branch.outputs.branch == 'main' && !inputs.dry_run && inputs.publish_pypi && inputs.compiler_wheel | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
- name: Publish to PyPI - Stubs | |
if: steps.get_branch.outputs.branch == 'main' && !inputs.dry_run && inputs.publish_pypi && inputs.stubs_wheel | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: stubs/dist | |
publish-docs: | |
name: Publish Docs | |
if: ${{ !inputs.dry_run && inputs.publish_docs }} | |
uses: ./.github/workflows/gh-pages.yaml | |
permissions: | |
contents: read | |
pages: write | |
id-token: write |