-
Notifications
You must be signed in to change notification settings - Fork 38
136 lines (123 loc) · 4.93 KB
/
Copy pathpython-wheels.yml
File metadata and controls
136 lines (123 loc) · 4.93 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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 and **will not** publish the created wheels.
#
# When running on a release event or as a workflow dispatch for a tag,
# and if the tag matches `guppylang-v*` or `guppylang-internals-v*`,
# this workflow will publish the corresponding wheels to pypi.
# If the version is already published, pypi just ignores it.
on:
workflow_dispatch:
push:
branches:
- main
release:
types:
- published
pull_request:
branches:
- main
merge_group:
env:
# Pinned version for the uv package manager
UV_VERSION: "0.9.5"
jobs:
build:
name: Package wheels and test
runs-on: ubuntu-latest
steps:
# Skip the workflow when triggered by a release event for a non guppylang package.
- name: Check tag
id: check-tag
run: |
echo "run=$SHOULD_RUN" >> $GITHUB_OUTPUT
env:
SHOULD_RUN: ${{ (github.event_name != 'release' && (github.ref == 'refs/heads/main' || startsWith(github.head_ref, 'release-please-')) ) || ( github.ref_type == 'tag' && (startsWith(github.ref, 'refs/tags/guppylang-v') || startsWith(github.ref, 'refs/tags/guppylang-internals-v'))) }}
- uses: actions/checkout@v6
if: ${{ steps.check-tag.outputs.run == 'true' }}
- name: Run sccache-cache
if: ${{ steps.check-tag.outputs.run == 'true' }}
uses: mozilla-actions/sccache-action@v0.0.10
- name: Set up uv
if: ${{ steps.check-tag.outputs.run == 'true' }}
uses: astral-sh/setup-uv@v7
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
- name: Install Python 3.13
run: uv python install 3.13
if: ${{ steps.check-tag.outputs.run == 'true' }}
- name: Build sdist and wheels
if: ${{ steps.check-tag.outputs.run == 'true' }}
run: |
uvx --directory guppylang-internals --from build pyproject-build --installer uv --outdir ../dist
uvx --directory guppylang --from build pyproject-build --installer uv --outdir ../dist
- name: Upload the built guppylang-internals package as an artifact
if: ${{ steps.check-tag.outputs.run == 'true' }}
uses: actions/upload-artifact@v7
with:
name: build-guppylang-internals-sdist
path: |
dist/guppylang_internals-*.tar.gz
dist/guppylang_internals-*.whl
- name: Upload the built guppylang package as an artifact
if: ${{ steps.check-tag.outputs.run == 'true' }}
uses: actions/upload-artifact@v7
with:
name: build-guppylang-sdist
path: |
dist/guppylang-*.tar.gz
dist/guppylang-*.whl
- name: Test installing the built wheels
if: ${{ steps.check-tag.outputs.run == 'true' }}
run: |
echo "Testing the newly built wheels..."
uv run -f dist --with guppylang --with guppylang-internals --refresh-package guppylang --refresh-package guppylang-internals --no-project -- python -c "import guppylang; import guppylang_internals; print('Smoke test done')"
uvx twine check --strict dist/*
publish:
name: Publish wheels to PyPI
if: (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && github.ref_type == 'tag'
runs-on: ubuntu-latest
needs: build
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
strategy:
matrix:
target:
- guppylang
- guppylang-internals
steps:
# Check the release tag against the package name.
#
# Skip the workflow when triggered by a release event for any other package.
- name: Check tag
id: check-tag
run: |
echo "run=$SHOULD_RUN" >> $GITHUB_OUTPUT
env:
SHOULD_RUN: ${{ startsWith(github.ref, format('refs/tags/{0}-v', matrix.target)) }}
- name: Download the ${{ matrix.target }} wheel artifact
if: ${{ steps.check-tag.outputs.run == 'true' }}
uses: actions/download-artifact@v8
with:
name: build-${{ matrix.target }}-sdist
path: dist
- name: Report
if: ${{ steps.check-tag.outputs.run == 'true' }}
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 for the packages on PyPI.
if: ${{ steps.check-tag.outputs.run == 'true' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
skip-existing: true