Skip to content

Commit c5f149f

Browse files
authored
Merge pull request #3 from AIBlockOfficial/ci/publish-pypi
CI: force token auth, validate secrets; avoid OIDC fallback causing i…
2 parents 6685e12 + 9c0ad47 commit c5f149f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

.github/workflows/publish.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Publish to PyPI
33
on:
44
push:
55
branches: [ "main" ]
6+
workflow_dispatch:
67

78
concurrency:
89
group: publish-pypi-${{ github.ref }}
@@ -14,7 +15,6 @@ jobs:
1415
runs-on: ubuntu-latest
1516
permissions:
1617
contents: read
17-
id-token: write
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
@@ -32,10 +32,28 @@ jobs:
3232
- name: Build sdist and wheel
3333
run: python -m build
3434

35+
- name: Validate PyPI token is available
36+
run: |
37+
if [ -z "${{ secrets.PYPI_API_TOKEN }}" ] && [ -z "${{ secrets.TWINE_PASSWORD }}" ]; then
38+
echo "::error::Missing PyPI API token. Set repository secret PYPI_API_TOKEN (preferred) or TWINE_PASSWORD."
39+
exit 1
40+
fi
41+
42+
- name: Resolve token
43+
id: resolve-token
44+
run: |
45+
if [ -n "${{ secrets.PYPI_API_TOKEN }}" ]; then
46+
echo "token=${{ secrets.PYPI_API_TOKEN }}" >> $GITHUB_OUTPUT
47+
elif [ -n "${{ secrets.TWINE_PASSWORD }}" ]; then
48+
echo "token=${{ secrets.TWINE_PASSWORD }}" >> $GITHUB_OUTPUT
49+
else
50+
echo "token=" >> $GITHUB_OUTPUT
51+
fi
52+
3553
- name: Publish to PyPI
3654
uses: pypa/gh-action-pypi-publish@release/v1
3755
with:
38-
password: ${{ secrets.PYPI_API_TOKEN }}
56+
password: ${{ steps.resolve-token.outputs.token }}
3957
skip-existing: true
4058

4159

0 commit comments

Comments
 (0)