|
1 | 1 | 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 | + |
2 | 12 | permissions: |
3 | | - checks: write |
4 | 13 | 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 | + |
8 | 16 | "on": |
9 | 17 | push: |
10 | 18 | branches: |
11 | 19 | - main |
12 | 20 | paths: |
13 | 21 | - .speakeasy/gen.lock |
14 | 22 | workflow_dispatch: {} |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: publish |
| 26 | + cancel-in-progress: false |
| 27 | + |
15 | 28 | jobs: |
16 | 29 | publish: |
17 | | - uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15 |
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