1+ name : Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
2+
3+ on :
4+ release :
5+ push :
6+ tags :
7+ - " v*"
8+ pull_request :
9+ workflow_dispatch :
10+
11+ jobs :
12+ build :
13+ name : Build distribution 📦
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - uses : actions/checkout@v4
18+ with :
19+ persist-credentials : false
20+ - name : Set up Python
21+ uses : actions/setup-python@v5
22+ with :
23+ python-version : " 3.x"
24+ - name : Install pypa/build
25+ run : >-
26+ python3 -m
27+ pip install
28+ build
29+ --user
30+ - name : Build a binary wheel and a source tarball
31+ run : python3 -m build
32+ - name : Store the distribution packages
33+ uses : actions/upload-artifact@v4
34+ with :
35+ name : python-package-distributions
36+ path : dist/
37+
38+ publish-to-pypi :
39+ name : >-
40+ Publish Python 🐍 distribution 📦 to PyPI
41+ if : startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
42+ needs :
43+ - build
44+ runs-on : ubuntu-latest
45+ environment :
46+ name : pypi
47+ url : https://pypi.org/p/<package-name> # Replace <package-name> with your PyPI project name
48+ permissions :
49+ id-token : write # IMPORTANT: mandatory for trusted publishing
50+
51+ steps :
52+ - name : Download all the dists
53+ uses : actions/download-artifact@v4
54+ with :
55+ name : python-package-distributions
56+ path : dist/
57+ - name : Publish distribution 📦 to PyPI
58+ uses : pypa/gh-action-pypi-publish@release/v1
59+
60+ publish-to-testpypi :
61+ name : Publish Python 🐍 distribution 📦 to TestPyPI
62+ needs :
63+ - build
64+ runs-on : ubuntu-latest
65+
66+ environment :
67+ name : testpypi
68+ url : https://test.pypi.org/p/<package-name>
69+
70+ permissions :
71+ id-token : write # IMPORTANT: mandatory for trusted publishing
72+
73+ steps :
74+ - name : Download all the dists
75+ uses : actions/download-artifact@v4
76+ with :
77+ name : python-package-distributions
78+ path : dist/
79+ - name : Publish distribution 📦 to TestPyPI
80+ uses : pypa/gh-action-pypi-publish@release/v1
81+ with :
82+ repository-url : https://test.pypi.org/legacy/
0 commit comments