Skip to content

Commit 60cef5c

Browse files
authored
Implement version check for beta indicator in publish workflow and adding release workflow (#264)
* Implement version check for beta indicator in publish workflow - Added a step to the GitHub Actions workflow to verify that the version string includes a beta indicator ('b') before allowing publishing to PyPI. This ensures that only versions marked for beta release are published, preventing accidental major releases through the workflow. * Update GitHub Actions workflow to use latest setup-uv version - Changed the setup-uv action from version v2 to v6 in the publish-python-sdk.yml workflow file to ensure compatibility with the latest features and improvements.
1 parent 01f900d commit 60cef5c

2 files changed

Lines changed: 139 additions & 3 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Publish Python SDK on Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.12'
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v2
25+
26+
- name: Install dev dependencies with uv
27+
working-directory: python-sdk
28+
run: |
29+
uv sync --group dev
30+
31+
- name: Install python-sdk package (editable)
32+
working-directory: python-sdk
33+
run: |
34+
uv pip install -e .
35+
36+
- name: Run tests with pytest and coverage
37+
working-directory: python-sdk
38+
run: |
39+
uv run pytest --cov=exospherehost --cov-report=xml --cov-report=term-missing -v --junitxml=pytest-report.xml
40+
41+
- name: Upload coverage reports to Codecov
42+
uses: codecov/codecov-action@v5
43+
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}
45+
slug: exospherehost/exospherehost
46+
files: python-sdk/coverage.xml
47+
flags: python-sdk-unittests
48+
name: python-sdk-coverage-report
49+
fail_ci_if_error: true
50+
51+
- name: Upload test results
52+
uses: actions/upload-artifact@v4
53+
if: always()
54+
with:
55+
name: python-sdk-test-results
56+
path: python-sdk/pytest-report.xml
57+
retention-days: 30
58+
59+
publish:
60+
runs-on: ubuntu-latest
61+
needs: test
62+
defaults:
63+
run:
64+
working-directory: python-sdk
65+
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- uses: astral-sh/setup-uv@v6
70+
name: Install uv
71+
72+
- run: uv python install
73+
74+
- run: uv sync --locked --dev
75+
76+
- name: Update version to release tag
77+
run: |
78+
# Extract version from tag (remove 'v' or 'V' prefix if present)
79+
RELEASE_VERSION="${{ github.ref_name }}"
80+
81+
# Handle empty or invalid tags
82+
if [[ -z "$RELEASE_VERSION" ]]; then
83+
echo "ERROR: Release tag is empty"
84+
exit 1
85+
fi
86+
87+
# Remove 'v' or 'V' prefix (case insensitive)
88+
if [[ $RELEASE_VERSION =~ ^[vV] ]]; then
89+
RELEASE_VERSION="${RELEASE_VERSION#?}" # Remove first character
90+
fi
91+
92+
# Validate the extracted version is not empty
93+
if [[ -z "$RELEASE_VERSION" ]]; then
94+
echo "ERROR: Invalid tag format - version part is empty"
95+
exit 1
96+
fi
97+
98+
# Update the version file
99+
echo "version = \"$RELEASE_VERSION\"" > exospherehost/_version.py
100+
101+
echo "Updated version to $RELEASE_VERSION for release"
102+
103+
- name: Verify version format
104+
run: |
105+
python -c "
106+
import sys
107+
sys.path.append('.')
108+
from exospherehost._version import version
109+
import re
110+
111+
# Check if version matches semantic versioning pattern
112+
if not re.match(r'^\d+\.\d+\.\d+$', version):
113+
print(f'ERROR: Version {version} does not match semantic versioning pattern (x.y.z)')
114+
sys.exit(1)
115+
116+
# Ensure it's not a beta version (should not contain 'b')
117+
if 'b' in version:
118+
print(f'ERROR: Release version {version} contains beta indicator. Release versions should not be beta.')
119+
sys.exit(1)
120+
121+
print(f'Version {version} is valid for release publishing')
122+
"
123+
124+
- run: uv build
125+
126+
- run: uv publish

.github/workflows/publish-python-sdk.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ jobs:
2525
python-version: '3.12'
2626

2727
- name: Install uv
28-
uses: astral-sh/setup-uv@v2
29-
with:
30-
cache: true
28+
uses: astral-sh/setup-uv@v6
3129

3230
- name: Install dev dependencies with uv
3331
working-directory: python-sdk
@@ -79,6 +77,18 @@ jobs:
7977

8078
- run: uv sync --locked --dev
8179

80+
- name: Check version for beta indicator
81+
run: |
82+
python -c "
83+
import sys
84+
sys.path.append('.')
85+
from exospherehost._version import version
86+
if 'b' not in version:
87+
print(f'ERROR: Version {version} does not contain beta indicator (b). Major releases are only allowed through GitHub releases.')
88+
sys.exit(1)
89+
print(f'Version {version} is valid for PyPI publishing (contains beta indicator)')
90+
"
91+
8292
- run: uv build
8393

8494
- run: uv publish

0 commit comments

Comments
 (0)