Skip to content

Commit fa9ca21

Browse files
authored
Merge pull request #491 from KhiopsML/347-publish-to-pypi
Publish the python library to TestPyPI and PyPI
2 parents b9f51fa + f94d078 commit fa9ca21

File tree

4 files changed

+62
-21
lines changed

4 files changed

+62
-21
lines changed

.gitattributes

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
# Commit message template always have Unix endlines
22
.git_commit_template eol=lf
3-
4-
# Versioneer
5-
khiops/_version.py export-subst

.github/workflows/conda.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ on:
2323
tags: ['*']
2424
pull_request:
2525
paths:
26-
- setup.py
27-
- setup.cfg
2826
- pyproject.toml
2927
- LICENSE.md
30-
- versioneer.py
31-
- khiops/_version.py
3228
- packaging/conda/**,
3329
- '!packaging/conda/README.md'
3430
- .github/workflows/conda.yml

.github/workflows/pip.yml

Lines changed: 61 additions & 13 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,15 +14,13 @@ 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:
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: ['*']
2526
concurrency:
@@ -51,9 +52,9 @@ jobs:
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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
hooks:
1111
- id: pylint
1212
language_version: python3
13-
exclude: doc/convert_samples.py|doc/conf.py|versioneer.py|khiops/_version.py|setup.py
13+
exclude: doc/convert_samples.py|doc/conf.py
1414
- repo: https://github.com/pycqa/isort
1515
rev: 5.13.2
1616
hooks:

0 commit comments

Comments
 (0)