Skip to content

Commit d4d5d26

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 d4d5d26

1 file changed

Lines changed: 68 additions & 8 deletions

File tree

.github/workflows/pip.yml

Lines changed: 68 additions & 8 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: testpypi
20+
options: [testpypi, pypi]
21+
description: Publish to Test PyPI (TEST) or PyPI (PROD)
1422
pull_request:
1523
paths:
1624
- setup.py
@@ -35,6 +43,7 @@ jobs:
3543
packages: read
3644
steps:
3745
- name: Checkout sources
46+
# no explict branch specified so this step should check out the github.ref branch or tag
3847
uses: actions/checkout@v4
3948
with:
4049
# Get Git tags so that versioneer can function correctly
@@ -51,13 +60,14 @@ jobs:
5160
# Install required Python build dependency
5261
pip install build
5362
54-
# Build the package
63+
# Build the source package (sdist) only
64+
# a binary one (wheel) - platform dependent - would be a hassle
5565
python3 -m build --sdist
56-
- name: Upload package as artifact
66+
- name: Upload the package as artifact
5767
uses: actions/upload-artifact@v4
5868
with:
5969
name: pip-package
60-
path: ./dist/khiops*.tar.gz
70+
path: ./dist/
6171
test:
6272
needs: build
6373
runs-on: ubuntu-22.04
@@ -83,14 +93,14 @@ jobs:
8393
ref: ${{ env.SAMPLES_REVISION }}
8494
token: ${{ secrets.GITHUB_TOKEN }}
8595
path: khiops-samples
86-
- name: Download package artifact
96+
- name: Download package artifacts
8797
uses: actions/download-artifact@v4
8898
with:
8999
name: pip-package
90100
- name: Install package
91101
run: |
92102
pip install --upgrade pip
93-
pip install $(ls khiops*.tar.gz)
103+
pip install $(ls khiops*.tar.gz) # install the source package
94104
- name: Run tests
95105
env:
96106
KHIOPS_SAMPLES_DIR: ${{ github.workspace }}/khiops-samples
@@ -119,7 +129,11 @@ jobs:
119129
# The MPI command is not always named mpiexec, but can be orterun etc
120130
# (as given by khiops_env)
121131
kh-status | grep "MPI command" | grep -vwq "<empty>"
122-
release:
132+
# The implementation of a unique release job with multiple conditional steps
133+
# for each publishing mode is not chosen
134+
# because of the required job environment verified for Trusted Publishing
135+
release-github:
136+
# only publish on tag pushes
123137
if: github.ref_type == 'tag'
124138
needs: [build, test]
125139
runs-on: ubuntu-22.04
@@ -130,13 +144,59 @@ jobs:
130144
uses: actions/download-artifact@v4
131145
with:
132146
name: pip-package
133-
- name: Upload Pip package to the release
147+
path: dist/
148+
- name: Upload Pip source package to the github release
134149
uses: ncipollo/release-action@v1.15.0
135150
with:
136151
allowUpdates: true
137-
artifacts: khiops*.tar.gz
152+
artifacts: dist/khiops*.tar.gz
138153
body: '**For testing purposes only**'
139154
draft: false
140155
makeLatest: false
141156
prerelease: true
142157
updateOnlyUnreleased: true
158+
release-testpypi:
159+
# only publish on testpypi if requested and on tag pushes
160+
if: inputs.pypi-target == 'testpypi' && github.ref_type == 'tag'
161+
needs: [build, test]
162+
runs-on: ubuntu-22.04
163+
permissions:
164+
# IMPORTANT: OIDC token mandatory for trusted publishing on TestPyPI and PyPI
165+
id-token: write
166+
# required job environment verified for Trusted Publishing
167+
environment:
168+
name: testpypi
169+
url: https://test.pypi.org/p/khiops
170+
steps:
171+
- name: Download package artifact
172+
uses: actions/download-artifact@v4
173+
with:
174+
name: pip-package
175+
path: dist/
176+
- name: Publish Python distribution to TestPyPI
177+
uses: pypa/gh-action-pypi-publish@release/v1
178+
with:
179+
verbose: true
180+
repository-url: https://test.pypi.org/legacy/
181+
release-pypi:
182+
# only publish on pypi if requested and on tag pushes
183+
if: inputs.pypi-target == 'pypi' && github.ref_type == 'tag'
184+
needs: [build, test]
185+
runs-on: ubuntu-22.04
186+
permissions:
187+
# IMPORTANT: OIDC token mandatory for trusted publishing on TestPyPI and PyPI
188+
id-token: write
189+
# required job environment verified for Trusted Publishing
190+
environment:
191+
name: pypi
192+
url: https://pypi.org/p/khiops
193+
steps:
194+
- name: Download package artifact
195+
uses: actions/download-artifact@v4
196+
with:
197+
name: pip-package
198+
path: dist/
199+
- name: Publish Python distribution to PyPI
200+
uses: pypa/gh-action-pypi-publish@release/v1
201+
with:
202+
verbose: true

0 commit comments

Comments
 (0)