Skip to content

Commit 3ed4075

Browse files
committed
beta pypi release
1 parent 0a83df2 commit 3ed4075

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: PyPI Release
22

33
on:
4+
# Manual trigger with version input
45
workflow_dispatch:
56
inputs:
67
version:
@@ -10,17 +11,29 @@ on:
1011
description: "Confirm all tests have passed"
1112
type: boolean
1213
required: true
14+
is_prerelease:
15+
description: "Is this a pre-release?"
16+
type: boolean
17+
default: false
18+
required: false
19+
# Auto-trigger for beta releases when merged to dev
20+
push:
21+
branches:
22+
- dev
1323

1424
jobs:
15-
release:
25+
# Job for manual releases (stable or pre-release)
26+
manual_release:
1627
runs-on: ubuntu-latest
17-
if: github.event.inputs.confirm_tests == 'true'
28+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.confirm_tests == 'true'
1829
permissions:
1930
contents: write
2031
steps:
2132
- uses: actions/checkout@v3
33+
with:
34+
fetch-depth: 0
2235
- name: Set up Python
23-
uses: actions/setup-python@v4
36+
uses: actions/setup-python@v5
2437
with:
2538
python-version: "3.10"
2639
- name: Install dependencies
@@ -37,9 +50,71 @@ jobs:
3750
git config user.email github-actions@github.com
3851
git tag v${{ github.event.inputs.version }}
3952
git push origin v${{ github.event.inputs.version }}
40-
gh release create v${{ github.event.inputs.version }} --generate-notes
53+
if [ "${{ github.event.inputs.is_prerelease }}" == "true" ]; then
54+
gh release create v${{ github.event.inputs.version }} --prerelease --generate-notes
55+
else
56+
gh release create v${{ github.event.inputs.version }} --generate-notes
57+
fi
4158
- name: Publish to PyPI
4259
env:
4360
TWINE_USERNAME: __token__
4461
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
4562
run: twine upload dist/*
63+
64+
# Job for automatic beta releases on merge to dev
65+
auto_beta_release:
66+
runs-on: ubuntu-latest
67+
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
68+
permissions:
69+
contents: write
70+
steps:
71+
- uses: actions/checkout@v3
72+
with:
73+
fetch-depth: 0
74+
- name: Set up Python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: "3.10"
78+
- name: Install dependencies
79+
run: |
80+
python -m pip install --upgrade pip
81+
pip install build twine setuptools-scm
82+
- name: Generate beta version
83+
id: beta_version
84+
run: |
85+
# Get the latest tag
86+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
87+
# Remove the 'v' prefix if present
88+
LATEST_VERSION=${LATEST_TAG#v}
89+
# Split version into components
90+
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION"
91+
# Extract any existing beta suffix
92+
PATCH_NUM=${PATCH%%b*}
93+
# Get commit count since last tag for unique beta number
94+
COMMIT_COUNT=$(git rev-list --count $LATEST_TAG..HEAD 2>/dev/null || echo "1")
95+
# Generate beta version
96+
BETA_VERSION="$MAJOR.$MINOR.$(($PATCH_NUM))b$COMMIT_COUNT"
97+
echo "Generated beta version: $BETA_VERSION"
98+
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT
99+
# Update version in setup.py or pyproject.toml if needed
100+
# This depends on how your versioning is configured
101+
- name: Build package
102+
run: python -m build
103+
- name: Create GitHub Pre-Release
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.pypi }}
106+
BETA_VERSION: ${{ steps.beta_version.outputs.version }}
107+
run: |
108+
git config user.name github-actions
109+
git config user.email github-actions@github.com
110+
git tag v$BETA_VERSION
111+
git push origin v$BETA_VERSION
112+
gh release create v$BETA_VERSION --prerelease --title "Beta Release v$BETA_VERSION" --notes "Automated beta release from dev branch"
113+
- name: Publish to PyPI as Beta
114+
env:
115+
TWINE_USERNAME: __token__
116+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
117+
BETA_VERSION: ${{ steps.beta_version.outputs.version }}
118+
run: |
119+
# Ensure package is marked as beta in PyPI
120+
twine upload --skip-existing dist/*

0 commit comments

Comments
 (0)