Skip to content

Commit 41f6756

Browse files
author
Thierry RAMORASOAVINA
committed
Publish the python library to TestPyPI and PyPI
- Github "Trusted Publisher" must be configured on TestPyPI & PyPI - publish to PyPI only if github.ref is a tag
1 parent be078f9 commit 41f6756

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: Publish
3+
on:
4+
pull_request: # automatic publication while developing the "publish" workflow
5+
paths: [.github/workflows/publish.yml]
6+
workflow_dispatch: # manual triggering (when the workflow is in the default branch)
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: true
10+
jobs:
11+
build:
12+
name: Build distribution 📦
13+
runs-on: ubuntu-22.04
14+
steps:
15+
# not explict branch specified so this step should check out the github.ref branch or tag
16+
- name: Checkout sources
17+
uses: actions/checkout@v4
18+
with:
19+
persist-credentials: false
20+
# Get Git tags so that versioneer can function correctly
21+
# See issue https://github.com/actions/checkout/issues/701
22+
fetch-depth: 0
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: 3.x
27+
- name: Install pypa/build
28+
run: >-
29+
python3 -m pip install build --user
30+
- name: Build a binary wheel and a source tarball
31+
run: python3 -m build
32+
- name: Store the distribution packages
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: python-package-distributions
36+
path: dist/
37+
publish-to-testpypi:
38+
name: Publish Python 🐍 distribution 📦 to TestPyPI
39+
needs: [build]
40+
runs-on: ubuntu-22.04
41+
environment:
42+
name: testpypi
43+
url: https://test.pypi.org/p/khiops
44+
permissions:
45+
id-token: write # IMPORTANT: mandatory for trusted publishing
46+
steps:
47+
- name: Download all the dists
48+
uses: actions/download-artifact@v4
49+
with:
50+
name: python-package-distributions
51+
path: dist/
52+
- name: Publish distribution 📦 to TestPyPI
53+
uses: pypa/gh-action-pypi-publish@release/v1
54+
with:
55+
repository-url: https://test.pypi.org/legacy/
56+
publish-to-pypi:
57+
name: >-
58+
Publish Python 🐍 distribution 📦 to PyPI
59+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
60+
needs: [build]
61+
runs-on: ubuntu-22.04
62+
environment:
63+
name: pypi
64+
url: https://pypi.org/p/khiops
65+
permissions:
66+
id-token: write # IMPORTANT: mandatory for trusted publishing
67+
steps:
68+
- name: Download all the dists
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: python-package-distributions
72+
path: dist/
73+
- name: Publish distribution 📦 to PyPI
74+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)