-
Notifications
You must be signed in to change notification settings - Fork 6
77 lines (69 loc) · 2.92 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
74
75
76
77
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
environment: pypi
strategy:
matrix:
package:
- { dir: 'hugr-py', name: 'hugr' }
steps:
- uses: actions/checkout@v4
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.6
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.18"
enable-cache: true
- name: Install Python
run: uv python install 3.13
- 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 }}"
- name: Publish package distributions to PyPI
# This workflow is a trusted publisher on PyPI for this package.
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))) }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
skip-existing: true