11---
2+ # After building and testing the pip package,
3+ # this workflow publishes it to Github Release by default
4+ # and to Test PyPI (TEST) or PyPI (PROD) if requested
25name : Pip Package
36env :
47 DEFAULT_SAMPLES_REVISION : 11.0.0
1114 image-tag :
1215 default : 11.0.0-b.0.0
1316 description : Development Docker Image Tag
17+ pypi-target :
18+ type : choice
19+ default : None # no publishing to any Package Index by default
20+ options : [None, testpypi, pypi]
21+ description : Publish to Test PyPI or PyPI
1422 pull_request :
15- paths :
16- - setup.py
17- - setup.cfg
18- - pyproject.toml
19- - LICENSE.md
20- - versioneer.py
21- - khiops/_version.py
22- - .github/workflows/pip.yml
23+ paths : [pyproject.toml, LICENSE.md, .github/workflows/pip.yml]
2324 push :
2425 tags : ['*']
2526concurrency :
5152 # Install required Python build dependency
5253 pip install build
5354
54- # Build the package
55+ # Build the source package (sdist) only
5556 python3 -m build --sdist
56- - name : Upload package as artifact
57+ - name : Upload the package as artifact
5758 uses : actions/upload-artifact@v4
5859 with :
5960 name : pip-package
@@ -119,8 +120,12 @@ jobs:
119120 # The MPI command is not always named mpiexec, but can be orterun etc
120121 # (as given by khiops_env)
121122 kh-status | grep "MPI command" | grep -vwq "<empty>"
122- release :
123- if : github.ref_type == 'tag'
123+ # The implementation of a unique release job with multiple conditional steps
124+ # for each publishing mode is not chosen
125+ # because of the required job environment verified for Trusted Publishing
126+ release-github :
127+ # only publish on tag pushes
128+ if : github.ref_type == 'tag' && github.repository_owner == 'KhiopsML'
124129 needs : [build, test]
125130 runs-on : ubuntu-22.04
126131 permissions :
@@ -130,7 +135,7 @@ jobs:
130135 uses : actions/download-artifact@v4
131136 with :
132137 name : pip-package
133- - name : Upload Pip package to the release
138+ - name : Upload Pip source package to the github release
134139 uses : ncipollo/release-action@v1.15.0
135140 with :
136141 allowUpdates : true
@@ -140,3 +145,46 @@ jobs:
140145 makeLatest : false
141146 prerelease : true
142147 updateOnlyUnreleased : true
148+ release-testpypi :
149+ # only publish on testpypi if requested and on tag pushes
150+ if : inputs.pypi-target == 'testpypi' && github.ref_type == 'tag' && github.repository_owner == 'KhiopsML'
151+ needs : [build, test]
152+ runs-on : ubuntu-22.04
153+ permissions :
154+ # IMPORTANT: OIDC token mandatory for trusted publishing on TestPyPI and PyPI
155+ id-token : write
156+ # required job environment verified for Trusted Publishing
157+ environment :
158+ name : testpypi
159+ steps :
160+ - name : Download package artifact
161+ uses : actions/download-artifact@v4
162+ with :
163+ name : pip-package
164+ path : dist/
165+ - name : Publish Python distribution to TestPyPI
166+ uses : pypa/gh-action-pypi-publish@release/v1
167+ with :
168+ verbose : true
169+ repository-url : https://test.pypi.org/legacy/
170+ release-pypi :
171+ # only publish on pypi if requested and on tag pushes
172+ if : inputs.pypi-target == 'pypi' && github.ref_type == 'tag' && github.repository_owner == 'KhiopsML'
173+ needs : [build, test]
174+ runs-on : ubuntu-22.04
175+ permissions :
176+ # IMPORTANT: OIDC token mandatory for trusted publishing on TestPyPI and PyPI
177+ id-token : write
178+ # required job environment verified for Trusted Publishing
179+ environment :
180+ name : pypi
181+ steps :
182+ - name : Download package artifact
183+ uses : actions/download-artifact@v4
184+ with :
185+ name : pip-package
186+ path : dist/
187+ - name : Publish Python distribution to PyPI
188+ uses : pypa/gh-action-pypi-publish@release/v1
189+ with :
190+ verbose : true
0 commit comments