-
Notifications
You must be signed in to change notification settings - Fork 0
387 lines (316 loc) · 11.6 KB
/
build.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
name: Build, test and release crate
on:
pull_request:
push:
branches:
- master
- dev
env:
GIT_USER: glslt
GIT_USER_EMAIL: [email protected]
jobs:
version:
name: Compute next version
runs-on: ubuntu-latest
outputs:
new_release: ${{ steps.outputs.outputs.new_release }}
version: ${{ steps.outputs.outputs.version }}
bundle_file: ${{ steps.outputs.outputs.bundle_file }}
artifact_name: ${{ steps.outputs.outputs.artifact_name }}
check_success: ${{ steps.outputs.outputs.check_success }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Store repository head
id: head_before_release
shell: bash
run: echo head=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
- name: Check conventional commits
uses: cocogitto/[email protected]
# We handle the failure explicitely so this doesn't block the build
continue-on-error: true
id: check
with:
check-latest-tag-only: true
git-user: ${{ env.GIT_USER }}
git-user-email: ${{ env.GIT_USER_EMAIL }}
- name: Compute release changes
uses: cocogitto/[email protected]
# We need to continue on errors since no release is an error for cocogitto-action
continue-on-error: true
id: release
with:
check: false
release: true
git-user: ${{ env.GIT_USER }}
git-user-email: ${{ env.GIT_USER_EMAIL }}
# Only try to release on success
if: steps.check.outcome == 'success'
- name: Compute workflow outputs
id: outputs
run: |
if [[ "${{ steps.check.outcome }}" == "success" && "${{ steps.release.outcome }}" == "success" && "$(git rev-parse HEAD)" != "${{ steps.head_before_release.outputs.head }}" ]]; then
echo "A new release will be created: ${{ steps.release.outputs.version }}"
# Generate changelog
cog changelog --at ${{ steps.release.outputs.version }} -t full_hash > GITHUB_CHANGELOG.md
# Generate bundle for latest commit
bundle_file=release.bundle
git bundle create $bundle_file HEAD
echo "new_release=true" >> $GITHUB_OUTPUT
echo "version=${{ steps.release.outputs.version }}" >> $GITHUB_OUTPUT
echo "bundle_file=$bundle_file" >> $GITHUB_OUTPUT
echo "artifact_name=release-commit" >> $GITHUB_OUTPUT
echo "check_success=true" >> $GITHUB_OUTPUT
elif [[ "${{ steps.check.outcome }}" != "success" ]]; then
echo "::error title=Cocogitto check failed::There were errors in the changelog. Continuing with the build, but this won't be released."
echo "new_release=false" >> $GITHUB_OUTPUT
echo "check_success=false" >> $GITHUB_OUTPUT
else
echo "No new release will be created."
echo "new_release=false" >> $GITHUB_OUTPUT
echo "check_success=true" >> $GITHUB_OUTPUT
fi
- name: Upload commit artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.outputs.outputs.artifact_name }}
path: |
${{ steps.outputs.outputs.bundle_file }}
GITHUB_CHANGELOG.md
if: steps.outputs.outputs.new_release == 'true'
check:
name: Check crate
needs:
- version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}
- uses: actions/cache@v4
with:
key: ${{ runner.os }}
path: |
~/.cargo/bin/cargo-readme
- name: Install cargo-readme
run: |
cargo-readme -V || (
cargo install --force cargo-readme && cargo-readme -V
)
- name: Check READMEs
run: ./ci/readme.sh -c
- name: Check formatting
run: cargo fmt -- --check
- name: Check clippy lints
run: cargo clippy -- -D warnings -A clippy::result_large_err
test:
name: Test crate
needs:
- version
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-pc-windows-msvc
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}
- name: Run tests
run: cargo test
build-wheels:
name: Build wheels
needs:
- version
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-pc-windows-msvc
include:
- target: x86_64-unknown-linux-gnu
target_arch: x86_64
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
target_arch: x86_64
os: windows-latest
runs-on: ${{ matrix.os }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}
- name: Build windows wheels
run: ./ci/build_wheels.ps1 ${{ matrix.target }}
if: matrix.os == 'windows-latest'
- name: Build linux wheels
uses: addnab/docker-run-action@v3
with:
image: quay.io/pypa/manylinux2014_${{ matrix.target_arch }}
run: /io/ci/build_wheels.sh
options: -v ${{ github.workspace }}:/io
if: matrix.os == 'ubuntu-latest'
- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.target }}
path: |
target/wheels/*.tar.gz
target/wheels/*.whl
build-binaries:
name: Build binaries
needs:
- version
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-pc-windows-msvc
include:
- target: x86_64-unknown-linux-gnu
target_arch: x86_64
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
target_arch: x86_64
os: windows-latest
runs-on: ${{ matrix.os }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}
- name: Build CLI binary
run: cargo rustc -p glslt_cli --bin glsltc --release
- name: Strip CLI binary
run: strip target/${{ matrix.target }}/release/glsltc
if: matrix.os == 'ubuntu-latest'
- name: Prepare release
run: |
RELEASE_NAME=$(git describe --tags --abbrev=0 --always)
(cd target/${{ matrix.target }}/release && tar czf ${{ github.workspace }}/target/glslt-$RELEASE_NAME-${{ matrix.target }}.tar.gz glsltc)
if: matrix.os == 'ubuntu-latest'
- name: Prepare release
run: |
del target\glslt*.tar.gz
$ReleaseName = & git describe --tags --abbrev=0 --always
cd target/${{ matrix.target }}/release
7z a ${{ github.workspace }}/target/glslt-$ReleaseName-${{ matrix.target }}.7z glsltc.exe
if: matrix.os == 'windows-latest'
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.target }}
path: |
target/*.tar.gz
target/*.7z
release:
name: Release crate
needs:
- version
- check
- test
- build-binaries
- build-wheels
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}
- uses: ./.github/actions/apply-version-bundle
with:
new_release: ${{ needs.version.outputs.new_release }}
version: ${{ needs.version.outputs.version }}
bundle_file: ${{ needs.version.outputs.bundle_file }}
artifact_name: ${{ needs.version.outputs.artifact_name }}
- name: Download build artifacts (x86_64-unknown-linux-gnu)
uses: actions/download-artifact@v4
with:
name: build-x86_64-unknown-linux-gnu
path: dist/
- name: Download build artifacts (x86_64-pc-windows-msvc)
uses: actions/download-artifact@v4
with:
name: build-x86_64-pc-windows-msvc
path: dist/
- name: Download wheels artifacts (x86_64-unknown-linux-gnu)
uses: actions/download-artifact@v4
with:
name: wheels-x86_64-unknown-linux-gnu
path: wheels/
- name: Download wheels artifacts (x86_64-pc-windows-msvc)
uses: actions/download-artifact@v4
with:
name: wheels-x86_64-pc-windows-msvc
path: wheels/
- name: Print release file list
run: |
echo "::group::Binaries"
ls -al dist
echo "::endgroup::"
echo "::group::Wheels"
ls -al wheels
echo "::endgroup::"
- name: Install twine
run: pip install twine==4.0.2
- name: Check PyPI distribution
run: twine check wheels/*
- name: Check conventional commits
run: |
if [[ "${{ needs.version.outputs.check_success }}" != "true" ]]; then
echo "::error title=Cocogitto check failed::The changelog is invalid, please check the output of the version step and try again."
exit 1
fi
- name: Push repository changes
run: |
git push origin
git push origin ${{ needs.version.outputs.version }}
if: needs.version.outputs.new_release == 'true' && github.ref == 'refs/heads/master'
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GH_PAT }}
body_path: GITHUB_CHANGELOG.md
tag_name: ${{ needs.version.outputs.version }}
files: dist/glslt-${{ needs.version.outputs.version }}-*
if: needs.version.outputs.new_release == 'true' && github.ref == 'refs/heads/master'
- name: Push package manager artifacts
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: ./ci/release.sh
if: needs.version.outputs.new_release == 'true' && github.ref == 'refs/heads/master'
# vim: ft=yaml:ts=2:sw=2:et