Skip to content

Commit 34d63b4

Browse files
authored
chore(cicd): switched to python semantic release github action (#67)
The current workflow uses a release branch strategy (`release/*`) that required manual merging of release commits back to main. The problem was that those release tags were only on the release branch and needed to merge back to main. I tested this out in a fork and it's working [here](https://github.com/lempira/algokit-subscriber-py). It has everything except publishing to PyPi. ### Solution - **Replaced release branch triggers** with `workflow_dispatch` for manual production releases - **Added conditional release logic** using `python-semantic-release` GitHub Action: - Push to main → automatic beta releases - Manual dispatch with `production_release=true` → production releases - Manual dispatch with `production_release=false` → beta releases - **Simplified semantic-release config** to work directly on main branch with conditional prerelease behavior - **Added docs publishing control** - only publishes for production releases ### Key Changes - Removed `release/*` branch handling entirely - Added `workflow_dispatch` input for production release control - Switched to `python-semantic-release` GitHub Action for better integration - Updated semantic release config to use main branch with `prerelease=false` default - Added dynamic run names for better workflow visibility
2 parents c1e90df + 873360d commit 34d63b4

File tree

3 files changed

+41
-493
lines changed

3 files changed

+41
-493
lines changed

.github/workflows/cd.yaml

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
name: Continuous Delivery of Python package
22

3+
run-name: ${{ inputs.production_release && 'Production Release' || 'Beta Release' }}
4+
35
on:
46
push:
57
branches:
68
- main
7-
- release/*
9+
paths-ignore:
10+
- "docs/**"
11+
workflow_dispatch:
12+
inputs:
13+
production_release:
14+
description: "Production release?"
15+
type: boolean
16+
required: true
17+
default: true
818

919
concurrency: release
1020

@@ -17,7 +27,7 @@ jobs:
1727
name: Semantic Release
1828
runs-on: ubuntu-latest
1929
permissions:
20-
# IMPORTANT: this permission is mandatory for trusted publishing
30+
# IMPORTANT: mandatory for trusted publishing and GitHub releases
2131
id-token: write
2232
contents: write
2333
packages: read
@@ -37,58 +47,45 @@ jobs:
3747
- name: Setup Python and algokit
3848
uses: ./.github/actions/setup-algokit-python
3949

40-
- name: Check if version is already released
41-
id: check_version
42-
run: |
43-
rc=0
44-
poetry run semantic-release --strict --noop version || rc=$?
45-
echo "return_code=$rc" >> $GITHUB_OUTPUT
46-
if [ $rc -ne 2 ]; then
47-
exit $rc
48-
fi
49-
50-
- name: pre-commit and pytest
51-
if: steps.check_version.outputs.return_code == '0'
50+
- name: Run tests and quality checks (dummy for testing)
5251
run: |
5352
set -o pipefail
5453
poetry run pre-commit run --all-files && git diff --exit-code
5554
poetry run pytest
5655
57-
- name: Set Git user as GitHub actions
58-
if: steps.check_version.outputs.return_code == '0'
59-
run: git config --global user.email "actions@github.com" && git config --global user.name "github-actions"
60-
61-
- name: Update release
62-
if: steps.check_version.outputs.return_code == '0'
63-
run: poetry run semantic-release --strict version
64-
env:
65-
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
66-
67-
- name: Create Wheel
68-
if: steps.check_version.outputs.return_code == '0'
69-
run: poetry build --format wheel
56+
- name: Get branch name
57+
shell: bash
58+
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
59+
id: get_branch
7060

71-
- uses: actions/upload-artifact@v4 # upload artifacts so they are retained on the job
72-
if: steps.check_version.outputs.return_code == '0'
61+
- name: Python Semantic Release - Beta (non-prod)
62+
id: release-beta
63+
if: steps.get_branch.outputs.branch == 'main' && !inputs.production_release
64+
uses: python-semantic-release/python-semantic-release@v10.3.1
7365
with:
74-
path: dist
66+
github_token: ${{ steps.app-token.outputs.token }}
67+
prerelease: true
7568

76-
- name: Publish to GitHub
77-
if: steps.check_version.outputs.return_code == '0'
78-
run: poetry run semantic-release publish
79-
env:
80-
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
69+
- name: Python Semantic Release - Production
70+
id: release-prod
71+
if: steps.get_branch.outputs.branch == 'main' && inputs.production_release
72+
uses: python-semantic-release/python-semantic-release@v10.3.1
73+
with:
74+
github_token: ${{ steps.app-token.outputs.token }}
8175

8276
- name: Publish to PyPI
83-
if: steps.check_version.outputs.return_code == '0'
8477
uses: pypa/gh-action-pypi-publish@release/v1
78+
with:
79+
verbose: true
80+
8581

8682
publish-docs:
8783
name: Publish Docs
88-
# Don't publish canary docs
89-
if: github.ref != 'refs/heads/main'
84+
needs: release
85+
# Don't publish docs for beta releases from main
86+
if: inputs.production_release
9087
uses: ./.github/workflows/gh-pages.yaml
9188
permissions:
9289
contents: read
9390
pages: write
94-
id-token: write
91+
id-token: write

0 commit comments

Comments
 (0)