- Notifications
You must be signed in to change notification settings - Fork5.7k
Publish to PyPI#14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
name:Publish to PyPI | |
on: | |
# manually trigger the workflow | |
workflow_dispatch: | |
permissions:{} | |
jobs: | |
build: | |
name:Build Distribution | |
runs-on:ubuntu-latest | |
outputs: | |
TAG:${{ steps.get_tag.outputs.TAG }} | |
permissions: | |
# for uploading artifacts | |
actions:write | |
steps: | |
-uses:actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683# v4.2.2 | |
with: | |
persist-credentials:false | |
-name:Set up Python | |
uses:actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38# v5.4.0 | |
with: | |
python-version:"3.x" | |
-name:Install pypa/build | |
run:>- | |
python3 -m pip install build --user | |
-name:Build a binary wheel and a source tarball | |
run:python3 -m build | |
-name:Store the distribution packages | |
uses:actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b# v4.5.0 | |
with: | |
name:python-package-distributions | |
path:dist/ | |
-name:Get Tag Name | |
id:get_tag | |
run:| | |
pip install . | |
TAG=$(python -c "from telegram import __version__; print(f'v{__version__}')") | |
echo "TAG=$TAG" >> $GITHUB_OUTPUT | |
publish-to-pypi: | |
name:Publish to PyPI | |
needs: | |
-build | |
runs-on:ubuntu-latest | |
environment: | |
name:release_pypi | |
url:https://pypi.org/p/python-telegram-bot | |
permissions: | |
id-token:write# IMPORTANT: mandatory for trusted publishing | |
actions:read# for downloading artifacts | |
steps: | |
-name:Download all the dists | |
uses:actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16# v4.1.8 | |
with: | |
name:python-package-distributions | |
path:dist/ | |
-name:Publish to PyPI | |
uses:pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70# v1.12.3 | |
compute-signatures: | |
name:Compute SHA1 Sums and Sign with Sigstore | |
runs-on:ubuntu-latest | |
needs: | |
-publish-to-pypi | |
permissions: | |
id-token:write# IMPORTANT: mandatory for sigstore | |
actions:write# for up/downloading artifacts | |
steps: | |
-name:Download all the dists | |
uses:actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16# v4.1.8 | |
with: | |
name:python-package-distributions | |
path:dist/ | |
-name:Compute SHA1 Sums | |
run:| | |
# Compute SHA1 sum of the distribution packages and save it to a file with the same name, | |
# but with .sha1 extension | |
for file in dist/*; do | |
sha1sum $file > $file.sha1 | |
done | |
-name:Sign the dists with Sigstore | |
uses:sigstore/gh-action-sigstore-python@f514d46b907ebcd5bedc05145c03b69c1edd8b46# v3.0.0 | |
with: | |
inputs:>- | |
./dist/*.tar.gz | |
./dist/*.whl | |
-name:Store the distribution packages and signatures | |
uses:actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b# v4.5.0 | |
with: | |
name:python-package-distributions-and-signatures | |
path:dist/ | |
github-release: | |
name:Upload to GitHub Release | |
needs: | |
-build | |
-compute-signatures | |
runs-on:ubuntu-latest | |
permissions: | |
contents:write# IMPORTANT: mandatory for making GitHub Releases | |
actions:read# for downloading artifacts | |
steps: | |
-name:Download all the dists | |
uses:actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16# v4.1.8 | |
with: | |
name:python-package-distributions-and-signatures | |
path:dist/ | |
-name:Create GitHub Release | |
env: | |
GITHUB_TOKEN:${{ github.token }} | |
TAG:${{ needs.build.outputs.TAG }} | |
# Create a tag and a GitHub Release. The description can be changed later, as for now | |
# we don't define it through this workflow. | |
run:>- | |
gh release create | |
"$TAG" | |
--repo '${{ github.repository }}' | |
--generate-notes | |
-name:Upload artifact signatures to GitHub Release | |
env: | |
GITHUB_TOKEN:${{ github.token }} | |
TAG:${{ needs.build.outputs.TAG }} | |
# Upload to GitHub Release using the `gh` CLI. | |
# `dist/` contains the built packages, and the | |
# sigstore-produced signatures and certificates. | |
run:>- | |
gh release upload | |
"$TAG" dist/** | |
--repo '${{ github.repository }}' |