-
Notifications
You must be signed in to change notification settings - Fork 13
264 lines (233 loc) · 9.4 KB
/
release.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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# This is heavily inspired on
# https://github.com/PyO3/maturin/blob/main/.github/workflows/release.yml
# Maturin is a tool to build Rust crates as Python packages with minimal configuration,
# which uses cargo under the hood and ensures the binaries are compatible with a wide
# array of platforms and architectures.
# Although fontc itself is a pure Rust project and as such doesn't use Python,
# making it available on PyPI as a binary wheel package suitable to be installed by pip
# increases its reach among font developers accustomed to Python tools.
#
# The Release workflow uses maturin to build fontc for Linux (x86_64 and aarch64),
# Windows (i686 and x86_64) and macOS (universal2 'fat' binary supporting both
# x86_64 and arm64 architectures), package these as Python wheels, and upload to PyPI.
# The same fontc binaries are also uploaded as Github Release assets which can be used
# with `cargo binstall` command.
# The workflow runs automatically when a fontc version tag (i.e. starting with 'fontc-v')
# gets pushed, or can be manually triggered from Github Actions interface (in which case
# artifacts don't get published, just temporarily uploaded to Github Actions).
name: Release
on:
# only run on fontc-specific, version-tagged commits or manually
push:
tags: ["fontc-v*.*.*"]
# enables workflow to be run manually
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
workflow_dispatch:
# read-only access to repo contents by default; specific jobs may override it
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
contents: read
jobs:
build:
name: Build ${{ matrix.platform.target }}
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-apple-darwin
os: macos-latest
python-architecture: x64
archive: fontc-x86_64-apple-darwin.tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
python-architecture: x64
archive: fontc-x86_64-pc-windows-msvc.zip
- target: i686-pc-windows-msvc
os: windows-latest
python-architecture: x86
archive: fontc-i686-pc-windows-msvc.zip
runs-on: ${{ matrix.platform.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
architecture: ${{ matrix.platform.python-architecture }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
# Install gnu-tar because BSD tar is buggy
# https://github.com/actions/cache/issues/403
- name: Install GNU tar (macOS)
if: matrix.platform.os == 'macos-latest'
run: |
brew install gnu-tar
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
- name: Build wheel (macOS universal2) and sdist
if: matrix.platform.target == 'x86_64-apple-darwin'
uses: PyO3/maturin-action@v1
with:
target: universal2-apple-darwin
args: --release -o dist --sdist
- name: Build wheel (without sdist)
if: matrix.platform.target != 'x86_64-apple-darwin'
uses: PyO3/maturin-action@v1
with:
target: ${{matrix.platform.target}}
args: --release -o dist
- name: Install wheel
shell: bash
run: |
pip install --no-index --find-links dist/ --force-reinstall fontc
which fontc
fontc --version
- name: Check sdist metadata
if: matrix.platform.target == 'x86_64-apple-darwin'
run: pipx run twine check dist/*.tar.gz
- name: Archive binary
if: matrix.platform.os != 'windows-latest'
run: |
cd target/${{ matrix.platform.target }}/release
tar czvf ../../../${{ matrix.platform.archive }} fontc
cd -
- name: Archive binary (windows)
if: matrix.platform.os == 'windows-latest'
run: |
cd target/${{ matrix.platform.target }}/release
7z a ../../../${{ matrix.platform.archive }} fontc.exe
cd -
- name: Archive binary (macOS aarch64)
if: matrix.platform.os == 'macos-latest'
run: |
cd target/aarch64-apple-darwin/release
tar czvf ../../../fontc-aarch64-apple-darwin.tar.gz fontc
cd -
- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.platform.target }}
path: dist
- name: Upload binary artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.platform.target }}
path: |
*.tar.gz
*.zip
build_linux:
name: Build ${{ matrix.platform.target }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- target: "x86_64-unknown-linux-musl"
image_tag: "x86_64-musl"
compatibility: "manylinux2010 musllinux_1_1"
- target: "aarch64-unknown-linux-musl"
image_tag: "aarch64-musl"
compatibility: "manylinux2014 musllinux_1_1"
container:
image: docker://ghcr.io/rust-cross/rust-musl-cross:${{ matrix.platform.image_tag }}
steps:
# checkout@v3 doesn't work inside the manylinux container:
# https://github.com/actions/checkout/issues/1487
- uses: actions/checkout@v3
- name: Build Wheels
uses: PyO3/maturin-action@main
with:
target: ${{ matrix.platform.target }}
manylinux: ${{ matrix.platform.compatibility }}
container: off
args: --release -o dist
- name: Install x86_64 wheel
if: startsWith(matrix.platform.target, 'x86_64')
run: |
/usr/bin/python3 -m pip install --no-index --find-links dist/ --force-reinstall fontc
which fontc
fontc --version
- name: Archive binary
run: tar czvf target/release/fontc-${{ matrix.platform.target }}.tar.gz -C target/${{ matrix.platform.target }}/release fontc
- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.platform.target }}
path: dist
- name: Upload binary artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.platform.target }}
path: target/release/fontc-${{ matrix.platform.target }}.tar.gz
release-pypi:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/fontc-v')
needs: [build, build_linux]
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: wheels-*
# so that all artifacts are downloaded in the same directory specified by 'path'
merge-multiple: true
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
release-github:
permissions:
# Needed to upload release artifacts.
contents: write
name: Publish to GitHub releases
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/fontc-v')"
needs: [build, build_linux]
steps:
- uses: actions/download-artifact@v4
with:
pattern: binaries-*
merge-multiple: true
- uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: wheels
# this requirements.txt can be used to pip install fontc more securely
# https://pip.pypa.io/en/stable/topics/secure-installs/
- name: Generate requirements.txt with SHA256 hashes
run: |
echo fontc | pipx run --spec pip-tools pip-compile - --no-index --find-links wheels/ --no-emit-find-links --generate-hashes --pip-args '--only-binary=:all:' --no-annotate --no-header --output-file requirements.txt
- name: Compute checksums of release assets
run: |
sha256sum *.tar.gz *.zip requirements.txt > checksums.txt
- name: Detect if tag is a pre-release
id: before_release
env:
# e.g. v0.1.0a1, v1.2.0b2 or v2.3.0rc3, but not v1.0.0
PRERELEASE_TAG_PATTERN: "fontc-v[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+([ab]|rc)[[:digit:]]+"
run: |
# strip leading 'refs/tags/' to get the tag name
TAG_NAME="${GITHUB_REF##*/}"
if egrep -q "$PRERELEASE_TAG_PATTERN" <<< "$TAG_NAME"; then
echo "Tag ${TAG_NAME} contains a pre-release suffix"
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "Tag ${TAG_NAME} does not contain a pre-release suffix"
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
fi
# strip the redundant 'fontc-v' prefix from the Github Release title
echo "release_title=${TAG_NAME#fontc-v}" >> "$GITHUB_OUTPUT"
- name: Release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.before_release.outputs.release_title }}
files: |
*.tar.gz
*.zip
checksums.txt
requirements.txt
prerelease: ${{ steps.before_release.outputs.is_prerelease }}
generate_release_notes: true