Skip to content

Commit 534d39f

Browse files
committed
➕ Apply the new property of Python uploading authentication and add one new parameter about PyPI tokens if it needs.
1 parent c268288 commit 534d39f

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-14
lines changed

.github/workflows/rw_python_package.yaml

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ on:
3333
required: false
3434
default: 'python-package'
3535
type: string
36+
auth-method:
37+
description: 'Authentication method: oidc or token'
38+
required: false
39+
default: 'oidc'
40+
type: string
41+
secrets:
42+
PYPI_API_TOKEN:
43+
description: 'PyPI API token (only required if auth-method is token)'
44+
required: false
45+
TEST_PYPI_API_TOKEN:
46+
description: 'Test PyPI API token (only required if auth-method is token for TestPyPI)'
47+
required: false
3648

3749
outputs:
3850
build-success:
@@ -119,24 +131,43 @@ jobs:
119131
path: dist/
120132
retention-days: 30
121133

122-
- name: Publish to PyPI
123-
if: inputs.operation == 'publish-pypi'
124-
run: |
125-
echo "🚀 Publishing to PyPI..."
126-
uv publish
127-
echo "✅ Published to PyPI successfully"
134+
- name: Setup PyPI OIDC Authentication
135+
if: contains(fromJSON('["publish-pypi", "publish-testpypi"]'), inputs.operation) && inputs.auth-method == 'oidc'
136+
uses: pypa/gh-action-pypi-publish@release/v1
137+
with:
138+
print-hash: true
139+
verify-metadata: true
140+
packages-dir: dist/
141+
repository-url: ${{ inputs.operation == 'publish-testpypi' && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
128142

129-
- name: Publish to TestPyPI
130-
if: inputs.operation == 'publish-testpypi'
143+
- name: Setup PyPI Token Authentication
144+
if: contains(fromJSON('["publish-pypi", "publish-testpypi"]'), inputs.operation) && inputs.auth-method == 'token'
145+
env:
146+
TWINE_USERNAME: __token__
147+
TWINE_PASSWORD: ${{ inputs.operation == 'publish-pypi' && secrets.PYPI_API_TOKEN || secrets.TEST_PYPI_API_TOKEN }}
148+
TWINE_REPOSITORY_URL: ${{ inputs.operation == 'publish-testpypi' && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
131149
run: |
132-
echo "🚀 Publishing to TestPyPI..."
133-
uv publish --publish-url https://test.pypi.org/legacy/
134-
echo "✅ Published to TestPyPI successfully"
150+
echo "🔑 Using PyPI token authentication..."
151+
152+
# Verify token is available
153+
if [ -z "$TWINE_PASSWORD" ]; then
154+
echo "❌ Error: PyPI API token not found in secrets"
155+
echo "Please ensure ${{ inputs.operation == 'publish-pypi' && 'PYPI_API_TOKEN' || 'TEST_PYPI_API_TOKEN' }} is set in repository secrets"
156+
exit 1
157+
fi
158+
159+
echo "🚀 Publishing to ${{ inputs.operation == 'publish-pypi' && 'PyPI' || 'TestPyPI' }} using token authentication..."
160+
uv publish ${{ inputs.operation == 'publish-testpypi' && '--publish-url https://test.pypi.org/legacy/' || '' }}
161+
echo "✅ Published to ${{ inputs.operation == 'publish-pypi' && 'PyPI' || 'TestPyPI' }} successfully"
135162
136163
- name: Operation summary
137164
run: |
138165
echo "## Python Package Operation Summary" >> $GITHUB_STEP_SUMMARY
139166
echo "- **Operation**: ${{ inputs.operation }}" >> $GITHUB_STEP_SUMMARY
140167
echo "- **Version**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
141168
echo "- **Python**: ${{ inputs.python-version }}" >> $GITHUB_STEP_SUMMARY
169+
if [[ "${{ inputs.operation }}" == "publish-pypi" || "${{ inputs.operation }}" == "publish-testpypi" ]]; then
170+
echo "- **Auth Method**: ${{ inputs.auth-method == 'oidc' && '🔒 OIDC (Trusted Publisher)' || '🔑 API Token' }}" >> $GITHUB_STEP_SUMMARY
171+
echo "- **Repository**: ${{ inputs.operation == 'publish-pypi' && 'PyPI (production)' || 'TestPyPI (staging)' }}" >> $GITHUB_STEP_SUMMARY
172+
fi
142173
echo "- **Status**: ✅ Completed successfully" >> $GITHUB_STEP_SUMMARY

.github/workflows/rw_release_complete.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ on:
3232
type: string
3333
secrets:
3434
DOCKERHUB_USERNAME:
35-
description: 'Docker Hub username'
35+
description: 'DockerHub username'
3636
required: false
3737
DOCKERHUB_TOKEN:
38-
description: 'Docker Hub token'
38+
description: 'DockerHub access token'
39+
required: false
40+
PYPI_API_TOKEN:
41+
description: 'PyPI API token (required for token-based authentication)'
42+
required: false
43+
TEST_PYPI_API_TOKEN:
44+
description: 'Test PyPI API token (required for token-based authentication)'
3945
required: false
4046
outputs:
4147
version:
@@ -365,6 +371,10 @@ jobs:
365371
version: ${{ needs.bump_version.outputs.version }}
366372
checkout-sha: ${{ needs.bump_version.outputs.new_sha }}
367373
artifact-name: 'python-package-production'
374+
auth-method: ${{ needs.config.outputs.python_auth_method }}
375+
secrets:
376+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
377+
TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
368378

369379
release_docker_hub:
370380
name: Release to DockerHub

.github/workflows/rw_release_staging_complete.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ on:
1515
description: 'Docker Hub username'
1616
required: false
1717
DOCKERHUB_TOKEN:
18-
description: 'Docker Hub token'
18+
description: 'Docker Hub access token'
19+
required: false
20+
PYPI_API_TOKEN:
21+
description: 'PyPI API token (required for token-based authentication)'
22+
required: false
23+
TEST_PYPI_API_TOKEN:
24+
description: 'Test PyPI API token (required for token-based authentication)'
1925
required: false
2026
outputs:
2127
version:
@@ -107,6 +113,10 @@ jobs:
107113
version: ${{ needs.compute-version.outputs.version }}
108114
checkout-sha: ${{ github.sha }}
109115
artifact-name: 'staging-python-package'
116+
auth-method: ${{ needs.config.outputs.python_auth_method }}
117+
secrets:
118+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
119+
TEST_PYPI_API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
110120

111121
dockerhub-rc:
112122
name: Staging Release to DockerHub

0 commit comments

Comments
 (0)