@@ -6,6 +6,8 @@ name: Upload Python Package
66on :
77 release :
88 types : [created]
9+ pull_request :
10+ types : [opened, synchronize, reopened]
911
1012 # Allows to run this workflow manually
1113 workflow_dispatch :
@@ -14,30 +16,75 @@ permissions:
1416 contents : read
1517
1618jobs :
17- deploy :
18-
19+ build :
20+ name : Build distribution 📦
1921 runs-on : ubuntu-latest
20- environment : PyPi
21- permissions :
22- id-token : write
2322
2423 steps :
25- - name : Harden the runner (Audit all outbound calls)
26- uses : step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
27- with :
28- egress-policy : audit
29-
3024 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
25+ with :
26+ persist-credentials : false
3127 - name : Set up Python
3228 uses : actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
3329 with :
3430 python-version : ' 3.x'
3531 - name : Install dependencies
3632 run : |
3733 python -m pip install --upgrade pip
38- pip install setuptools build
39- python -m pip install git+https://github.com/takluyver/twine@ec859fbfd285284e800461c45d22187f7948a275#egg=twine
40- - name : Build and publish
34+ pip install setuptools build --user
35+ - name : Build a binary wheel and a source tarball
36+ run : python3 -m build
37+ - name : Store the distribution packages
38+ uses : actions/upload-artifact@v4
39+ with :
40+ name : python-package-distributions
41+ path : dist/
42+
43+ publish-to-testpypi :
44+ name : Publish Python distribution 📦 to TestPyPI
45+ needs :
46+ - build
47+ runs-on : ubuntu-latest
48+
49+ environment :
50+ name : testpypi
51+ url : https://test.pypi.org/p/dfetch
52+
53+ permissions :
54+ id-token : write
55+
56+ steps :
57+ - name : Download all the dists
58+ uses : actions/download-artifact@v4
59+ with :
60+ name : python-package-distributions
61+ path : dist/
62+ - name : Publish distribution 📦 to TestPyPI
63+ uses : pypa/gh-action-pypi-publish@release/v1
64+ with :
65+ repository-url : https://test.pypi.org/legacy/
66+
67+ - name : Test install from TestPyPI
4168 run : |
42- python -m build
43- twine upload dist/*
69+ pip install --index-url https://test.pypi.org/simple/ dfetch --extra-index-url https://pypi.org/simple
70+ python -c "import dfetch; print(dfetch.__version__)"
71+
72+ deploy :
73+ if : github.event_name == 'release'
74+ runs-on : ubuntu-latest
75+ needs :
76+ - build
77+ environment :
78+ name : pypi
79+ url : https://pypi.org/p/dfetch
80+ permissions :
81+ id-token : write
82+
83+ steps :
84+ - name : Download all the dists
85+ uses : actions/download-artifact@v4
86+ with :
87+ name : python-package-distributions
88+ path : dist/
89+ - name : Publish distribution 📦 to PyPI
90+ uses : pypa/gh-action-pypi-publish@release/v1
0 commit comments