@@ -2,6 +2,17 @@ name: Python Package Publication
22
33on :
44 pull_request :
5+ branches : [master]
6+ paths :
7+ - ' **.cpp'
8+ - ' **.hpp'
9+ - ' **.py'
10+ - ' setup.py'
11+ - ' setup.cfg'
12+ - ' pyproject.toml'
13+ - ' **.yml'
14+
15+ pull_request_target :
516 types : [closed]
617 branches : [master]
718 paths :
1122 - ' setup.py'
1223 - ' setup.cfg'
1324 - ' pyproject.toml'
25+
26+ workflow_dispatch :
27+ inputs :
28+ dry-run :
29+ description : ' Dry run (no actual upload to PyPI)'
30+ type : boolean
31+ default : true
1432
1533jobs :
1634 linux-build :
1735 runs-on : ubuntu-latest
1836 env :
1937 TWINE_USERNAME : __token__
20- TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
38+ IS_DRY_RUN : ${{ !(github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) }}
2139 steps :
2240 - uses : actions/checkout@v3
2341 with :
@@ -29,24 +47,35 @@ jobs:
2947 - name : Python wheels manylinux stable build
3048 uses : RalfG/python-wheels-manylinux-build@v0.5.0
3149 with :
32- python-versions : ' cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311'
33- - name : upload wheel
34- if : github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
50+ python-versions : ' cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312'
51+ - name : Upload wheel testpypi
52+ if : env.IS_DRY_RUN == 'true'
53+ env :
54+ TWINE_PASSWORD : ${{ secrets.TEST_PYPI_TOKEN }}
55+ run : |
56+ python -m pip install wheel setuptools twine packaging
57+ python -m pip install --upgrade twine packaging
58+ python -m twine upload --repository testpypi dist/*-manylinux*.whl --verbose
59+ continue-on-error : ${{ env.IS_DRY_RUN == 'true' }}
60+ - name : Upload wheel to production
61+ if : env.IS_DRY_RUN == 'false'
62+ env :
63+ TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
3564 run : |
36- python -m pip install --upgrade pip
37- python -m pip install wheel setuptools twine packaging>=24.2
38- twine upload dist/*-manylinux*.whl
39- continue-on-error : false
65+ python -m pip install wheel setuptools twine packaging
66+ python -m pip install --upgrade twine packaging
67+ python -m twine upload dist/*-manylinux*.whl
68+ continue-on-error : ${{ env.IS_DRY_RUN == 'true' }}
4069
4170 other-os-build :
4271 runs-on : ${{ matrix.os }}
4372 env :
4473 TWINE_USERNAME : __token__
45- TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
74+ IS_DRY_RUN : ${{ !(github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) }}
4675 strategy :
4776 matrix :
4877 os : [macos-latest, windows-latest]
49- python-version : ['3.8', '3. 9', '3.10', '3.11', '3.12']
78+ python-version : ['3.9', '3.10', '3.11', '3.12']
5079 steps :
5180 - uses : actions/checkout@v3
5281 with :
@@ -61,18 +90,30 @@ jobs:
6190 python-version : ${{ matrix.python-version }}
6291 - name : build wheel
6392 run : |
64- python -m pip install --upgrade pip
65- python -m pip install wheel setuptools twine packaging>=24.2
93+ python -m pip install wheel setuptools twine packaging
94+ python -m pip install --upgrade twine packaging
6695 python setup.py bdist_wheel
67- - name : upload wheel
68- if : github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
96+ - name : Upload wheel testpypi
97+ if : env.IS_DRY_RUN == 'true'
98+ env :
99+ TWINE_PASSWORD : ${{ secrets.TEST_PYPI_TOKEN }}
100+ run : |
101+ python -m pip install wheel setuptools twine packaging
102+ python -m pip install --upgrade twine packaging
103+ python -m twine upload --repository testpypi dist/* --verbose
104+ continue-on-error : ${{ env.IS_DRY_RUN == 'true' }}
105+ - name : Upload wheel to production
106+ if : env.IS_DRY_RUN == 'false'
107+ env :
108+ TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
69109 run : |
70- twine upload dist/*
71- continue-on-error : false
72-
110+ python -m pip install wheel setuptools twine packaging
111+ python -m pip install --upgrade twine packaging
112+ python -m twine upload dist/*
113+ continue-on-error : ${{ env.IS_DRY_RUN == 'true' }}
73114 release-build :
74- if : github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
75115 needs : [ linux-build, other-os-build ]
116+ if : (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true)
76117 runs-on : ubuntu-latest
77118 steps :
78119 - uses : actions/checkout@v3
0 commit comments