Skip to content

Commit 92109fd

Browse files
LukasParkeclaude
andcommitted
ci: publish PyPI releases directly instead of via Speakeasy
Replace speakeasy-api/sdk-generation-action's sdk-publish.yaml reusable workflow with an in-repo job that reads releaseVersion from gen.lock, publishes (skipping versions already released), and creates the v<version> GitHub release. Generation still uses Speakeasy. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 67c04f1 commit 92109fd

1 file changed

Lines changed: 96 additions & 11 deletions

File tree

‎.github/workflows/sdk_publish.yaml‎

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,108 @@
11
name: Publish
2+
3+
# Publishes the openrouter package to PyPI and creates the matching GitHub
4+
# release when a Speakeasy regen lands on main (gen.lock changes). Generation
5+
# still runs through speakeasy-api/sdk-generation-action; publishing is done
6+
# here directly rather than through its sdk-publish.yaml reusable workflow.
7+
#
8+
# Both steps are idempotent so a failed run can simply be re-run: a PyPI
9+
# version that already exists is not re-uploaded, and an existing release is
10+
# left alone.
11+
212
permissions:
3-
checks: write
413
contents: write
5-
pull-requests: write
6-
statuses: write
7-
id-token: write
14+
id-token: write # allows switching to PyPI trusted publishing without workflow changes
15+
816
"on":
917
push:
1018
branches:
1119
- main
1220
paths:
1321
- .speakeasy/gen.lock
1422
workflow_dispatch: {}
23+
24+
concurrency:
25+
group: publish
26+
cancel-in-progress: false
27+
1528
jobs:
1629
publish:
17-
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@68f3bfefb79354d39358bf4699863dabd2cea0f6 # v15.60.11
18-
with:
19-
target: open-router
20-
secrets:
21-
github_access_token: ${{ secrets.GITHUB_TOKEN }}
22-
pypi_token: ${{ secrets.PYPI_TOKEN }}
23-
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
30+
name: Publish to PyPI
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v5
34+
35+
- name: Resolve release version
36+
id: version
37+
run: |
38+
VERSION=$(yq '.management.releaseVersion' .speakeasy/gen.lock)
39+
PKG_VERSION=$(yq -p toml -oy '.project.version' pyproject.toml)
40+
PKG_NAME=$(yq -p toml -oy '.project.name' pyproject.toml)
41+
if [ "$VERSION" != "$PKG_VERSION" ]; then
42+
echo "::error::gen.lock releaseVersion ($VERSION) does not match pyproject.toml version ($PKG_VERSION)"
43+
exit 1
44+
fi
45+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
46+
echo "name=$PKG_NAME" >> "$GITHUB_OUTPUT"
47+
echo "Resolved $PKG_NAME==$VERSION"
48+
49+
- name: Check PyPI for existing version
50+
id: pypi
51+
env:
52+
PKG_NAME: ${{ steps.version.outputs.name }}
53+
VERSION: ${{ steps.version.outputs.version }}
54+
run: |
55+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' "https://pypi.org/pypi/$PKG_NAME/$VERSION/json")
56+
if [ "$STATUS" = "200" ]; then
57+
echo "$PKG_NAME==$VERSION is already on PyPI — skipping publish"
58+
echo "published=true" >> "$GITHUB_OUTPUT"
59+
elif [ "$STATUS" = "404" ]; then
60+
echo "published=false" >> "$GITHUB_OUTPUT"
61+
else
62+
echo "::error::Unexpected HTTP $STATUS from PyPI while checking $PKG_NAME==$VERSION"
63+
exit 1
64+
fi
65+
66+
- name: Install uv
67+
if: steps.pypi.outputs.published == 'false'
68+
uses: astral-sh/setup-uv@v5
69+
70+
- name: Build
71+
if: steps.pypi.outputs.published == 'false'
72+
run: |
73+
uv run python scripts/prepare_readme.py
74+
uv build
75+
76+
- name: Publish
77+
if: steps.pypi.outputs.published == 'false'
78+
env:
79+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
80+
run: uv publish
81+
82+
- name: Create GitHub release
83+
env:
84+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
VERSION: ${{ steps.version.outputs.version }}
86+
PKG_NAME: ${{ steps.version.outputs.name }}
87+
run: |
88+
TAG="v$VERSION"
89+
if gh release view "$TAG" >/dev/null 2>&1; then
90+
echo "Release $TAG already exists — nothing to do"
91+
exit 0
92+
fi
93+
94+
{
95+
echo "[$PKG_NAME $VERSION](https://pypi.org/project/$PKG_NAME/$VERSION)"
96+
yq '.releaseNotes // ""' .speakeasy/gen.lock
97+
echo "Generated with [Speakeasy CLI $(yq '.management.speakeasyVersion' .speakeasy/gen.lock)](https://github.com/speakeasy-api/speakeasy/releases)"
98+
} > "$RUNNER_TEMP/notes.md"
99+
100+
ARGS=()
101+
if [[ "$VERSION" == *"-"* ]]; then
102+
ARGS+=(--prerelease --latest=false)
103+
fi
104+
gh release create "$TAG" \
105+
--target "$GITHUB_SHA" \
106+
--title "python - $TAG - $(date -u '+%Y-%m-%d %H:%M:%S')" \
107+
--notes-file "$RUNNER_TEMP/notes.md" \
108+
"${ARGS[@]}"

0 commit comments

Comments
 (0)