Continuous Delivery of Python package #454
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: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "docs/**" | |
- "**.md" | |
- ".vscode/**" | |
- ".idea/**" | |
- ".gitignore" | |
- ".editorconfig" | |
- ".pre-commit-config.yaml" | |
- ".github/**" | |
- "tests/**" | |
- "scripts/**" | |
workflow_dispatch: | |
inputs: | |
production_release: | |
description: "Production release?" | |
required: true | |
default: "true" | |
concurrency: release | |
permissions: | |
contents: write | |
packages: read | |
jobs: | |
ci-check-python: | |
name: Check Python | |
uses: ./.github/workflows/check-python.yaml | |
ci-build-python: | |
name: Build Python | |
uses: ./.github/workflows/build-python.yaml | |
needs: ci-check-python | |
release: | |
name: Release wheels to pypi | |
needs: ci-build-python | |
runs-on: ubuntu-latest | |
outputs: | |
release_version: ${{ steps.get_release_version.outputs.RELEASE_VERSION }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Fetch entire repository history so we can determine version number from it | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Set up Poetry | |
uses: ./.github/actions/setup-poetry | |
- name: Install dependencies | |
run: poetry install --no-interaction --no-root | |
- 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 "actions@github.com" && git config --global user.name "github-actions" | |
- name: Create Continuous Deployment - Feature Branch | |
if: steps.get_branch.outputs.branch != 'main' && inputs.production_release != 'true' | |
run: | | |
poetry run semantic-release \ | |
-v DEBUG \ | |
--prerelease \ | |
--patch \ | |
--define=prerelease_tag=beta+${{ steps.get_branch.outputs.branch }} \ | |
--define=branch=${{ steps.get_branch.outputs.branch }} \ | |
publish | |
release_version_tag="$(git describe $(git rev-list --tags --max-count=1))" | |
gh release edit --prerelease $release_version_tag | |
echo "RELEASE_VERSION=${release_version_tag:1}" >> $GITHUB_ENV | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPOSITORY_USERNAME: __token__ | |
REPOSITORY_PASSWORD: ${{ secrets.PYPI_API_KEY }} | |
- name: Create Continuous Deployment - Beta (non-prod) | |
if: steps.get_branch.outputs.branch == 'main' && inputs.production_release != 'true' | |
run: | | |
poetry run semantic-release \ | |
-v DEBUG \ | |
--prerelease \ | |
--define=branch=main \ | |
publish | |
release_version="$(poetry run semantic-release print-version --current)" | |
gh release edit --prerelease "v$release_version" | |
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPOSITORY_USERNAME: __token__ | |
REPOSITORY_PASSWORD: ${{ secrets.PYPI_API_KEY }} | |
- name: Create Continuous Deployment - Production | |
if: steps.get_branch.outputs.branch == 'main' && inputs.production_release == 'true' | |
run: | | |
poetry run semantic-release \ | |
-v DEBUG \ | |
--define=version_source="commit" \ | |
--define=patch_without_tag=true \ | |
--define=upload_to_repository=true \ | |
--define=branch=main \ | |
publish | |
release_version="$(poetry run semantic-release print-version --current)" | |
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPOSITORY_USERNAME: __token__ | |
REPOSITORY_PASSWORD: ${{ secrets.PYPI_API_KEY }} | |
- name: Get release version | |
shell: bash | |
run: echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT | |
id: get_release_version | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: algokit-cli | |
path: dist/algokit*-py3-none-any.whl | |
if-no-files-found: error | |
build-and-upload-binaries: | |
name: Build and Upload Binaries | |
if: ${{ github.ref_name == 'main' }} | |
uses: ./.github/workflows/build-binaries.yaml | |
needs: release | |
with: | |
production_release: ${{ inputs.production_release }} | |
python_version: "3.12" | |
release_version: ${{ needs.release.outputs.release_version }} | |
secrets: inherit | |
cd-publish-release-packages: | |
name: Release binaries via distribution channels | |
needs: | |
- release | |
- build-and-upload-binaries | |
if: ${{ github.ref_name == 'main' && inputs.production_release == 'true' }} # Might want to adjust this to publish (pre-release) on merge as well. | |
uses: ./.github/workflows/publish-release-packages.yaml | |
with: | |
artifactName: algokit-cli | |
release_version: ${{ needs.release.outputs.release_version }} | |
secrets: inherit |