-
Notifications
You must be signed in to change notification settings - Fork 6
73 lines (65 loc) · 2.55 KB
/
python-wheels.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Build and publish python wheels
# Builds and publishes the wheels on pypi.
#
# When running on a push-to-main event, or as a workflow dispatch on a branch,
# this workflow will do a dry-run publish to test-pypi.
#
# When running on a release event or as a workflow dispatch for a tag,
# and if the tag matches `hugr-py-v*`,
# this workflow will publish the wheels to pypi.
# If the version is already published, pypi just ignores it.
on:
workflow_dispatch:
push:
branches:
- main
release:
types:
- published
jobs:
build-publish:
name: Build and publish wheels
runs-on: ubuntu-latest
strategy:
matrix:
package:
- { dir: 'hugr-py', name: 'hugr' }
steps:
- uses: actions/checkout@v4
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.5
- name: Set up uv
run: .github/script/install-uv.sh
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build sdist and wheels
run: |
cd ${{ matrix.package.dir }}
uvx --from build pyproject-build --installer uv --outdir ../dist
- name: Upload the built packages as artifacts
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.package.name }}-sdist
path: |
dist/*.tar.gz
dist/*.whl
- name: Test installing the built wheels
run: |
echo "Testing the newly built ${{ matrix.package.name }} wheels..."
uv run -f dist --with ${{ matrix.package.name }} --refresh-package ${{ matrix.package.name }} --no-project -- python -c "import ${{ matrix.package.name }}"
uvx twine check --strict dist/*
- name: Publish to PyPI
if: ${{ (github.event_name == 'release' && github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.package.dir))) || (github.event_name == 'workflow_dispatch' && github.ref_type == 'tag' && startsWith(github.ref, format('refs/tags/{0}-v', matrix.package.dir))) }}
run: |
echo "Publishing to PyPI..."
echo "Based on the following workflow variables, this is a new version tag push:"
echo " - event_name: ${{ github.event_name }}"
echo " - ref_type: ${{ github.ref_type }}"
echo " - ref: ${{ github.ref }}"
uvx twine upload --skip-existing --verbose dist/*
env:
TWINE_NON_INTERACTIVE: 1
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PUBLISH }}