Skip to content

Commit 3d95f90

Browse files
author
Thierry RAMORASOAVINA
committed
Publish the python library to TestPyPI and PyPI
- Github "Trusted Publisher" must be configured on TestPyPI & PyPI - Like previously the publishing triggering to TestPyPI, PyPI or github release is manual - an error will occur if the same version already exists on TestPyPI or PyPI
1 parent b9f51fa commit 3d95f90

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

.github/workflows/pip.yml

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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
25
name: Pip Package
36
env:
47
DEFAULT_SAMPLES_REVISION: 11.0.0
@@ -11,6 +14,11 @@ on:
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:
1523
paths:
1624
- setup.py
@@ -51,9 +59,9 @@ jobs:
5159
# Install required Python build dependency
5260
pip install build
5361
54-
# Build the package
62+
# Build the source package (sdist) only
5563
python3 -m build --sdist
56-
- name: Upload package as artifact
64+
- name: Upload the package as artifact
5765
uses: actions/upload-artifact@v4
5866
with:
5967
name: pip-package
@@ -119,8 +127,12 @@ jobs:
119127
# The MPI command is not always named mpiexec, but can be orterun etc
120128
# (as given by khiops_env)
121129
kh-status | grep "MPI command" | grep -vwq "<empty>"
122-
release:
123-
if: github.ref_type == 'tag'
130+
# The implementation of a unique release job with multiple conditional steps
131+
# for each publishing mode is not chosen
132+
# because of the required job environment verified for Trusted Publishing
133+
release-github:
134+
# only publish on tag pushes
135+
if: github.ref_type == 'tag' && github.repository_owner == 'KhiopsML'
124136
needs: [build, test]
125137
runs-on: ubuntu-22.04
126138
permissions:
@@ -130,7 +142,7 @@ jobs:
130142
uses: actions/download-artifact@v4
131143
with:
132144
name: pip-package
133-
- name: Upload Pip package to the release
145+
- name: Upload Pip source package to the github release
134146
uses: ncipollo/release-action@v1.15.0
135147
with:
136148
allowUpdates: true
@@ -140,3 +152,46 @@ jobs:
140152
makeLatest: false
141153
prerelease: true
142154
updateOnlyUnreleased: true
155+
release-testpypi:
156+
# only publish on testpypi if requested and on tag pushes
157+
if: inputs.pypi-target == 'testpypi' && github.ref_type == 'tag' && github.repository_owner == 'KhiopsML'
158+
needs: [build, test]
159+
runs-on: ubuntu-22.04
160+
permissions:
161+
# IMPORTANT: OIDC token mandatory for trusted publishing on TestPyPI and PyPI
162+
id-token: write
163+
# required job environment verified for Trusted Publishing
164+
environment:
165+
name: testpypi
166+
steps:
167+
- name: Download package artifact
168+
uses: actions/download-artifact@v4
169+
with:
170+
name: pip-package
171+
path: dist/
172+
- name: Publish Python distribution to TestPyPI
173+
uses: pypa/gh-action-pypi-publish@release/v1
174+
with:
175+
verbose: true
176+
repository-url: https://test.pypi.org/legacy/
177+
release-pypi:
178+
# only publish on pypi if requested and on tag pushes
179+
if: inputs.pypi-target == 'pypi' && github.ref_type == 'tag' && github.repository_owner == 'KhiopsML'
180+
needs: [build, test]
181+
runs-on: ubuntu-22.04
182+
permissions:
183+
# IMPORTANT: OIDC token mandatory for trusted publishing on TestPyPI and PyPI
184+
id-token: write
185+
# required job environment verified for Trusted Publishing
186+
environment:
187+
name: pypi
188+
steps:
189+
- name: Download package artifact
190+
uses: actions/download-artifact@v4
191+
with:
192+
name: pip-package
193+
path: dist/
194+
- name: Publish Python distribution to PyPI
195+
uses: pypa/gh-action-pypi-publish@release/v1
196+
with:
197+
verbose: true

0 commit comments

Comments
 (0)