Publish the python library to TestPyPI and PyPI #907
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | ||
|
Check failure on line 1 in .github/workflows/pip.yml
|
||
| name: Pip Package | ||
| env: | ||
| DEFAULT_SAMPLES_REVISION: 11.0.0 | ||
| on: | ||
| workflow_dispatch: # manual triggering | ||
| inputs: | ||
| samples-revision: | ||
| default: 11.0.0 | ||
| description: khiops-samples repo revision | ||
| image-tag: | ||
| default: 11.0.0-b.0.0 | ||
| description: Development Docker Image Tag | ||
| publish-to-github: | ||
| type: boolean | ||
| default: true | ||
| description: Legacy publishing mode - github release (PRODUCTION) | ||
| publish-to-testpypi: | ||
| type: boolean | ||
| default: false | ||
| description: TestPyPI publishing mode (TEST) | ||
| publish-to-pypi: | ||
| type: boolean | ||
| default: false | ||
| description: PyPI publishing mode (PRODUCTION) | ||
| pull_request: | ||
| paths: | ||
| - setup.py | ||
| - setup.cfg | ||
| - pyproject.toml | ||
| - LICENSE.md | ||
| - versioneer.py | ||
| - khiops/_version.py | ||
| - .github/workflows/pip.yml | ||
| push: | ||
| tags: ['*'] | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-22.04 | ||
| permissions: | ||
| checks: write | ||
| contents: read | ||
| id-token: write | ||
| packages: read | ||
| steps: | ||
| - name: Checkout sources | ||
| # no explict branch specified so this step should check out the github.ref branch or tag | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Get Git tags so that versioneer can function correctly | ||
| # See issue https://github.com/actions/checkout/issues/701 | ||
| fetch-depth: 0 | ||
| - name: Build Pip package | ||
| run: | | ||
| # This is needed so that the Git tag is parsed and the version is retrieved | ||
| git config --global --add safe.directory $(realpath .) | ||
| # Upgrade Pip | ||
| pip install --upgrade pip | ||
| # Install required Python build dependency | ||
| pip install build | ||
| # Build the packages/distributions : | ||
| # a source distribution is built first (sdist) and | ||
| # a binary one (wheel) then | ||
| python3 -m build | ||
| - name: Upload the packages as artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: pip-packages | ||
| path: ./dist/ | ||
| test: | ||
| needs: build | ||
| runs-on: ubuntu-22.04 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| container: [ubuntu22.04, rocky9] | ||
| container: | ||
| # 'latest' default image tag cannot be set as an environment variable, | ||
| # because the `env` context is only accessible at the step level; | ||
| # hence, it is hard-coded | ||
| image: |- | ||
| ghcr.io/khiopsml/khiops-python/khiopspydev-${{ matrix.container }}:${{ inputs.image-tag || '11.0.0-b.0.0' }} | ||
| steps: | ||
| - name: Set parameters as env | ||
| run: | | ||
| SAMPLES_REVISION=${{ inputs.samples-revision || env.DEFAULT_SAMPLES_REVISION }} | ||
| echo "SAMPLES_REVISION=$SAMPLES_REVISION" >> "$GITHUB_ENV" | ||
| - name: Checkout Khiops samples | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: khiopsml/khiops-samples | ||
| ref: ${{ env.SAMPLES_REVISION }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| path: khiops-samples | ||
| - name: Download package artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: pip-packages | ||
| - name: Install package | ||
| run: | | ||
| pip install --upgrade pip | ||
| pip install $(ls khiops*.tar.gz) # install the source package | ||
| - name: Run tests | ||
| env: | ||
| KHIOPS_SAMPLES_DIR: ${{ github.workspace }}/khiops-samples | ||
| # Force > 2 CPU cores to launch mpiexec | ||
| KHIOPS_PROC_NUMBER: 4 | ||
| # Oversubscribe for MPI 4.x | ||
| rmaps_base_oversubscribe: true | ||
| # Oversubscribe for MPI > 4.x | ||
| OMPI_MCA_rmaps_base_oversubscribe: true | ||
| run: |- | ||
| # Make sure MPI support is not loaded through env modules | ||
| # Note: As the Docker container's shell is non-interactive, environment | ||
| # modules are currently not initializing the shell anyway | ||
| if [ -n "$MODULESHOME" ]; then module unload mpi; fi | ||
| # Print khiops installation status | ||
| kh-status | ||
| # Run some simple training tasks | ||
| kh-samples core -i train_predictor -e | ||
| kh-samples core -i train_coclustering -e | ||
| kh-samples sklearn -i khiops_classifier -e | ||
| # Test that the line containing "MPI command" does not contain "<empty>" | ||
| # (as given by kh-status in the absence of MPI support) | ||
| # The MPI command is not always named mpiexec, but can be orterun etc | ||
| # (as given by khiops_env) | ||
| kh-status | grep "MPI command" | grep -vwq "<empty>" | ||
| release: | ||
| if: github.ref_type == 'tag' # only publish on tag pushes | ||
| needs: [build, test] | ||
| runs-on: ubuntu-22.04 | ||
| permissions: | ||
| contents: write | ||
| id-token: write # IMPORTANT: mandatory for trusted publishing on TestPyPI and PyPI | ||
| steps: | ||
| - name: Download package artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: pip-packages | ||
| - name: Upload Pip source package to the github release (under condition) | ||
| if: publish-to-github | ||
| uses: ncipollo/release-action@v1.15.0 | ||
| with: | ||
| allowUpdates: true | ||
| artifacts: khiops*.tar.gz | ||
| body: '**For testing purposes only**' | ||
| draft: false | ||
| makeLatest: false | ||
| prerelease: true | ||
| updateOnlyUnreleased: true | ||
| - name: Publish Python 🐍 distribution 📦 to TestPyPI (under condition) | ||
| if: publish-to-testpypi | ||
| env: # required environment variables at step level | ||
| name: testpypi | ||
| url: https://test.pypi.org/p/khiops | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| verbose: true | ||
| repository-url: https://test.pypi.org/legacy/ | ||
| - name: Publish Python 🐍 distribution 📦 to PyPI (under condition) | ||
| if: publish-to-pypi | ||
| env: # required environment variables at step level | ||
| name: pypi | ||
| url: https://pypi.org/p/khiops | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| verbose: true | ||