-
Notifications
You must be signed in to change notification settings - Fork 162
246 lines (222 loc) · 8.52 KB
/
Copy pathrelease.yml
File metadata and controls
246 lines (222 loc) · 8.52 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name: Release
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Tag to build (e.g. v2026.04.01). If it does not exist, it will be created at the end. Leave empty for dev build.'
# Note: We do NOT pass this tag to actions/checkout. We checkout the
# branch selected in the UI (usually main), and this tag is created at
# the end of the workflow by the release step if it didn't exist.
required: false
default: ''
pull_request:
# This is meant to allow one to dry-run the release workflow from a PR
# tagged with the label "ci:wheels"
types: [labeled]
schedule:
- cron: '0 0 1 * *'
jobs:
setup-version:
name: Setup version and publication status
if: >-
github.event_name == 'workflow_dispatch' ||
github.event_name == 'schedule' ||
github.event.label.name == 'ci:wheels'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
should_publish: ${{ steps.get-version.outputs.should_publish }}
steps:
- name: Check out repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install Python 3.12
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Install dependencies
run: pip install requests
- name: Get version
id: get-version
shell: bash
run: |
python scripts/get_version.py \
--event "${{ github.event_name }}" \
--ref "${{ github.ref }}" \
--tag "${{ github.event.release.tag_name || inputs.tag_name || '' }}" \
--package "heir_py" \
--gha
build_sdist:
name: Build source distribution
needs: [setup-version]
if: >-
github.event_name == 'workflow_dispatch' ||
github.event_name == 'schedule' ||
github.event.label.name == 'ci:wheels'
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Install Python 3.12
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- run: python -m pip install build
- name: Build sdist
run: |
if [[ -n "${{ needs.setup-version.outputs.version }}" ]]; then
export SETUPTOOLS_SCM_PRETEND_VERSION="${{ needs.setup-version.outputs.version }}"
fi
python -m build --sdist
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-sdist
path: dist/*.tar.gz
build_wheels:
name: Build HEIR wheels on ${{ matrix.name }}
needs: [setup-version]
if: >-
github.event_name == 'workflow_dispatch' ||
github.event_name == 'schedule' ||
github.event.label.name == 'ci:wheels'
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x86_64
runner: ubuntu-24.04
- name: linux-aarch64
runner: ubuntu-24.04-arm
- name: macos-arm64
runner: macos-15
steps:
- name: Check out HEIR
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
name: Install Python 3.12
with:
python-version: "3.12"
- run: pip install --upgrade pip uv
- name: Build wheels on ${{ matrix.name }} using cibuildwheel
uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ needs.setup-version.outputs.version }}
CIBW_ENVIRONMENT_PASS: SETUPTOOLS_SCM_PRETEND_VERSION
- name: Upload HEIR ${{ matrix.name }} wheels
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-${{ matrix.name }}
path: wheelhouse/*.whl
create_archive:
name: Create source archive
needs: [setup-version]
if: >-
github.event_name == 'workflow_dispatch' ||
github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Create Archive
id: archive
run: |
TAG_NAME="${{ needs.setup-version.outputs.version }}"
if [[ ! "$TAG_NAME" =~ ^v ]]; then
TAG_NAME="v$TAG_NAME"
fi
git archive --format=tar.gz --prefix=heir-$TAG_NAME/ -o heir-$TAG_NAME.tar.gz HEAD
sha256sum heir-$TAG_NAME.tar.gz > heir-$TAG_NAME.tar.gz.sha256
echo "archive_file=heir-$TAG_NAME.tar.gz" >> "$GITHUB_OUTPUT"
echo "checksum_file=heir-$TAG_NAME.tar.gz.sha256" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: source-archive
path: heir-*.tar.gz*
perform_release:
name: Create GitHub Release and Upload Assets
needs: [setup-version, build_wheels, create_archive]
if: needs.setup-version.outputs.should_publish == 'true' || github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
path: dist
pattern: dist-*
merge-multiple: true
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
path: archive
name: source-archive
- name: Extract and rename binaries
shell: bash
run: |
mkdir -p extracted
for whl in dist/*.whl; do
filename=$(basename "$whl")
# Extract the platform tag from the wheel filename. Wheels are
# named: distribution-version-python_tag-abi_tag-platform_tag.whl We
# reverse the string, take the first part separated by '-', reverse
# it back, and strip the '.whl' extension. This gives us the platform
# tag robustly.
platform=$(echo "$filename" | rev | cut -d- -f1 | rev | cut -d. -f1)
echo "Processing wheel $whl for platform $platform"
# Extract specific binaries from the wheel. We use -j (junk paths)
# to extract them directly into tmp_extract without recreating the
# directory structure.
unzip -j "$whl" "heir/heir-opt" -d tmp_extract || true
unzip -j "$whl" "heir/heir-translate" -d tmp_extract || true
# Rename the extracted binaries to include the platform tag. This
# prevents them from overwriting each other when uploaded to the same
# release.
if [ -f tmp_extract/heir-opt ]; then
mv tmp_extract/heir-opt "extracted/heir-opt-$platform"
fi
if [ -f tmp_extract/heir-translate ]; then
mv tmp_extract/heir-translate "extracted/heir-translate-$platform"
fi
rm -rf tmp_extract
done
echo "Extracted files:"
ls -alh extracted/
- name: Determine Tag Name
id: tag
shell: bash
run: |
TAG_NAME="${{ needs.setup-version.outputs.version }}"
if [[ ! "$TAG_NAME" =~ ^v ]]; then
TAG_NAME="v$TAG_NAME"
fi
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
- name: Create Release
id: release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
with:
tag_name: ${{ steps.tag.outputs.tag_name }}
generate_release_notes: true
files: |
archive/*
extracted/*
pypi_upload:
name: Publish heir wheels to PyPI
needs: [setup-version, build_sdist, build_wheels]
if: needs.setup-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
path: dist
pattern: dist-*
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1.13
with:
verbose: true