Skip to content

Commit

Permalink
chore: flesh out cibuildwheel workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 committed Aug 29, 2024
1 parent 6c7354e commit 486ac57
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 16 deletions.
97 changes: 84 additions & 13 deletions .github/workflows/cibuildwheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on:
# NOTE(vytas): Also allow to release to Test PyPi manually.
workflow_dispatch:

# TODO(vytas): Remove later (temporary testing).
pull_request:
branches:
- master

jobs:
build-sdist:
name: sdist
Expand All @@ -27,7 +32,8 @@ jobs:

- name: Build sdist
run: |
pip install build
pip install --upgrade pip
pip install --upgrade build
python -m build --sdist
- name: Upload artifacts
Expand All @@ -36,6 +42,13 @@ jobs:
name: cibw-sdist
path: dist/*.tar.gz

- name: Nuclear testing
run: |
echo ${{ github.event_name }}
echo ${{ github.event_name == 'release' }}
echo ${{ github.ref }}
python -c '0/0'
build-wheels:
name: ${{ matrix.python }}-${{ matrix.platform.name }}
needs: build-sdist
Expand Down Expand Up @@ -107,35 +120,93 @@ jobs:
name: cibw-wheel-${{ matrix.python }}-${{ matrix.platform.name }}
path: wheelhouse/*.whl

publish-sdist:
name: publish-sdist
needs:
- build-sdist
- build-wheels
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: cibw-sdist
path: dist

- name: Check collected artifacts
run: |
python tools/check_dist.py --dist-dir dist/
- name: Upload sdist to release
uses: AButler/[email protected]
if: github.event_name == 'release'
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
files: 'dist/*.tar.gz'

- name: Publish sdist to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'workflow_dispatch'
with:
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Publish sdist to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'release'
with:
password: ${{ secrets.PYPI_TOKEN }}

publish-wheels:
name: publish
name: publish-wheels
needs:
- build-sdist
- build-wheels
- publish-sdist
runs-on: ubuntu-latest

steps:
- name: Download packages
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: cibw-*
pattern: cibw-wheel-*
path: dist
merge-multiple: true

- name: Check collected artifacts
# TODO(vytas): Run a script to perform version sanity checks instead.
run: ls -l dist/
run: |
python tools/check_dist.py --dist-dir dist/
- name: Publish artifacts to TestPyPI
- name: Publish wheels to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'workflow_dispatch'
with:
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository-url: https://test.pypi.org/legacy/

# TODO(vytas): Enable this nuclear option once happy with other tests.
# - name: Publish artifacts to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# if: github.event_name == 'release'
# with:
# password: ${{ secrets.PYPI_TOKEN }}
- name: Publish wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'release'
with:
password: ${{ secrets.PYPI_TOKEN }}
5 changes: 2 additions & 3 deletions .github/workflows/create-wheels.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Create wheel

on:
# run when a release has been created
release:
types: [created]
# TODO(vytas): Phase out this workflow in favour of cibuildwheel.yaml.
workflow_dispatch:

env:
# set this so the falcon test uses the installed version and not the local one
Expand Down
70 changes: 70 additions & 0 deletions tools/check_dist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python

import argparse
import pathlib
import sys

HERE = pathlib.Path(__file__).resolve().parent
DIST = HERE.parent / 'dist'


def check_dist(dist):
sdist = None
versions = set()
wheels = []

for path in dist.iterdir():
if not path.is_file():
continue

if path.name.endswith('.tar.gz'):
assert sdist is None, f'sdist already exists: {sdist}'
sdist = path.name

elif path.name.endswith('.whl'):
wheels.append(path.name)

else:
sys.stderr.write(f'Unexpected file found in dist: {path.name}\n')
sys.exit(1)

package, _, _ = path.stem.partition('.tar')
falcon, version, *_ = package.split('-')
assert falcon == 'falcon', 'Unexpected package name: {path.name}'
versions.add(version)

if not versions:
sys.stderr.write('No artifacts collected!\n')
sys.exit(1)
if len(versions) > 1:
sys.stderr.write(f'Multiple versions found: {tuple(versions)}!\n')
sys.exit(1)
version = versions.pop()

wheel_list = ' None\n'
if wheels:
wheel_list = ''.join(f' {wheel}\n' for wheel in sorted(wheels))

print(f'[{dist}]\n')
print(f'sdist found:\n {sdist}\n')
print(f'wheels found:\n{wheel_list}')
print(f'version identified:\n {version}\n')


def main():
description = 'Check artifacts (sdist, wheels) inside dist dir.'

parser = argparse.ArgumentParser(description=description)
parser.add_argument(
'-d',
'--dist-dir',
default=str(DIST),
help='dist directory to check (default: %(default)s)',
)

args = parser.parse_args()
check_dist(pathlib.Path(args.dist_dir))


if __name__ == '__main__':
main()

0 comments on commit 486ac57

Please sign in to comment.