Skip to content

Commit

Permalink
CI Upload to pypi with GitHub actions (#18800)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
  • Loading branch information
thomasjpfan and ogrisel committed Dec 2, 2020
1 parent 59f41f0 commit 41f3fd5
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish to Pypi
on:
workflow_dispatch:
inputs:
version:
description: 'Version upload to pypi'
required: true
pypi_repo:
description: 'Repo to upload to (testpypi or pypi)'
default: 'testpypi'
required: true

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
pip install -U wheelhouse_uploader pyyaml
- name: Downloading wheels and sdist from staging
env:
SKLEARN_VERSION: ${{ github.event.inputs.version }}
run: |
echo "Download $SKLEARN_VERSION wheels and sdist"
python -m wheelhouse_uploader fetch \
--version $SKLEARN_VERSION \
--local-folder dist/ \
scikit-learn \
https://pypi.anaconda.org/scikit-learn-wheels-staging/simple/scikit-learn/
- name: Check dist has the correct number of artifacts
run: |
python build_tools/github/check_wheels.py
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@v1.4.1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
if: ${{ github.event.inputs.pypi_repo }} == 'testpypi'
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@v1.4.1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
if: ${{ github.event.inputs.pypi_repo }} == 'pypi'
32 changes: 32 additions & 0 deletions build_tools/github/check_wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Checks that dist/* contains the number of wheels built from the
.github/workflows/wheels.yml config."""
import yaml
from pathlib import Path
import sys

gh_wheel_path = Path.cwd() / ".github" / "workflows" / "wheels.yml"
with gh_wheel_path.open('r') as f:
wheel_config = yaml.safe_load(f)

build_matrix = wheel_config['jobs']['build_wheels']['strategy']['matrix']
n_python_versions = len(build_matrix['python'])

# For each python version we have: 5 wheels
# 1 osx wheel (x86_64)
# 2 linux wheel (i686 + x86_64)
# 2 windows wheel (win32 + wind_amd64)
n_wheels = 5 * n_python_versions

# plus one more for the sdist
n_wheels += 1

dist_files = list(Path("dist").glob('**/*'))
n_dist_files = len(dist_files)

if n_dist_files != n_wheels:
print(f"Expected {n_wheels} wheels in dist/* but "
f"got {n_dist_files} artifacts instead.")
sys.exit(1)

print(f"dist/* has the expected {n_wheels} wheels:")
print("\n".join(file.name for file in dist_files))

0 comments on commit 41f3fd5

Please sign in to comment.