11name : Publish Python 🐍 distribution 📦 to PyPI
22
3- on : push
3+ on :
4+ push :
5+ tags :
6+ - " v*"
7+ workflow_dispatch :
8+
9+ permissions :
10+ contents : read
11+
12+ concurrency :
13+ group : publish-${{ github.ref }}
14+ cancel-in-progress : false
415
516jobs :
617 build :
920
1021 steps :
1122 - uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0
1225 - name : Set up Python
1326 uses : actions/setup-python@v5
1427 with :
15- python-version : " 3.x "
16- - name : Install pypa/ build
28+ python-version : " 3.10 "
29+ - name : Install build tools
1730 run : >-
1831 python3 -m
1932 pip install
2033 build
34+ twine
2135 --user
2236 - name : Build a binary wheel and a source tarball
2337 run : python3 -m build
38+ - name : Check distribution metadata
39+ run : python3 -m twine check dist/*
40+ - name : Smoke test wheel install
41+ run : |
42+ python3 -m venv .venv-smoke
43+ . .venv-smoke/bin/activate
44+ python -m pip install --upgrade pip
45+ python -m pip install --no-deps dist/*.whl
46+ python -c "import importlib.metadata as metadata; print(metadata.version('transformer_nuggets'))"
2447 - name : Store the distribution packages
2548 uses : actions/upload-artifact@v4
2649 with :
@@ -30,15 +53,15 @@ jobs:
3053 publish-to-pypi :
3154 name : >-
3255 Publish Python 🐍 distribution 📦 to PyPI
33- if : startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
56+ if : startsWith(github.ref, 'refs/tags/v')
3457 needs :
3558 - build
3659 runs-on : ubuntu-latest
3760 environment :
3861 name : pypi
39- url : https://pypi.org/p/transformer_nuggets # Replace <package-name> with your PyPI project name
62+ url : https://pypi.org/p/transformer_nuggets
4063 permissions :
41- id-token : write # IMPORTANT: mandatory for trusted publishing
64+ id-token : write
4265
4366 steps :
4467 - name : Download all the dists
@@ -48,18 +71,21 @@ jobs:
4871 path : dist/
4972 - name : Publish distribution 📦 to PyPI
5073 uses : pypa/gh-action-pypi-publish@release/v1
74+ with :
75+ skip-existing : true
5176
5277 github-release :
5378 name : >-
5479 Sign the Python 🐍 distribution 📦 with Sigstore
5580 and upload them to GitHub Release
81+ if : startsWith(github.ref, 'refs/tags/v')
5682 needs :
5783 - publish-to-pypi
5884 runs-on : ubuntu-latest
5985
6086 permissions :
61- contents : write # IMPORTANT: mandatory for making GitHub Releases
62- id-token : write # IMPORTANT: mandatory for sigstore
87+ contents : write
88+ id-token : write
6389
6490 steps :
6591 - name : Download all the dists
@@ -76,18 +102,15 @@ jobs:
76102 - name : Create GitHub Release
77103 env :
78104 GITHUB_TOKEN : ${{ github.token }}
79- run : >-
80- gh release create
81- '${{ github.ref_name }}'
82- --repo '${{ github.repository }}'
83- --notes ""
105+ run : |
106+ if ! gh release view '${{ github.ref_name }}' --repo '${{ github.repository }}' >/dev/null 2>&1; then
107+ gh release create '${{ github.ref_name }}' --repo '${{ github.repository }}' --notes ""
108+ fi
84109 - name : Upload artifact signatures to GitHub Release
85110 env :
86111 GITHUB_TOKEN : ${{ github.token }}
87- # Upload to GitHub Release using the `gh` CLI.
88- # `dist/` contains the built packages, and the
89- # sigstore-produced signatures and certificates.
90112 run : >-
91113 gh release upload
92114 '${{ github.ref_name }}' dist/**
115+ --clobber
93116 --repo '${{ github.repository }}'
0 commit comments