Skip to content

Commit ade55d2

Browse files
jkebingerclaude
andauthored
Add PyPI publish workflow with duplicate version check (#129)
Backports the publish workflow from ReforgeHQ/sdk-python and adapts it for prefab-cloud-python. Key features: - Triggers on push to main or manual workflow dispatch - Checks PyPI before publishing to prevent duplicate releases - Uses trusted publishing (OIDC) for secure authentication - Runs tests before publishing - Only publishes if version doesn't already exist on PyPI Changes from sdk-python workflow: - Uses pyproject.toml for version (instead of VERSION file) - Uses prefab-cloud-python as PyPI package name - Uses PREFAB_INTEGRATION_TEST_API_KEY secret - Runs pytest with '-k not integration' filter (matches CI) PyPI coordinates: https://pypi.org/project/prefab-cloud-python 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0fa7895 commit ade55d2

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "Publish to PyPI"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
if: github.ref == 'refs/heads/main'
13+
environment: release
14+
permissions:
15+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
16+
contents: read
17+
18+
steps:
19+
- name: Checkout repo + submodules
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: recursive
23+
24+
- name: Install Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: "3.10"
28+
29+
- name: Check if version already published
30+
id: version-check
31+
run: |
32+
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
33+
echo "Current version: $VERSION"
34+
35+
# Check if this version exists on PyPI
36+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/prefab-cloud-python/$VERSION/json")
37+
38+
if [ "$HTTP_STATUS" = "200" ]; then
39+
echo "Version $VERSION already exists on PyPI"
40+
echo "skip=true" >> $GITHUB_OUTPUT
41+
else
42+
echo "Version $VERSION not found on PyPI, proceeding with publish"
43+
echo "skip=false" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Install Poetry
47+
if: steps.version-check.outputs.skip == 'false'
48+
uses: snok/install-poetry@v1
49+
with:
50+
virtualenvs-create: true
51+
52+
- name: Install dependencies
53+
if: steps.version-check.outputs.skip == 'false'
54+
run: |
55+
poetry install --no-interaction
56+
57+
- name: Run tests
58+
if: steps.version-check.outputs.skip == 'false'
59+
run: poetry run pytest -k 'not integration'
60+
env:
61+
PREFAB_INTEGRATION_TEST_API_KEY: ${{ secrets.PREFAB_INTEGRATION_TEST_API_KEY }}
62+
63+
- name: Build package
64+
if: steps.version-check.outputs.skip == 'false'
65+
run: poetry build
66+
67+
- name: Publish to PyPI
68+
if: steps.version-check.outputs.skip == 'false'
69+
uses: pypa/gh-action-pypi-publish@release/v1
70+
with:
71+
packages-dir: dist/

0 commit comments

Comments
 (0)