-
Notifications
You must be signed in to change notification settings - Fork 0
295 lines (283 loc) · 11.3 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
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
# Release-plz workflow from:
# https://release-plz.ieni.dev/docs/github/quickstart
# https://release-plz.ieni.dev/docs/github/output
name: Test, Build, and Release
permissions:
pull-requests: write
contents: write
on:
push:
branches:
- main
jobs:
mac-test:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Install Ninja
run: brew install ninja
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
- name: Install LLVM tools
run: brew install llvm
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Run tests with coverage
run: cargo llvm-cov --workspace --lcov --output-path ./target/lcov.info
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Install cargo bundle
run: cargo install cargo-bundle
- name: Bundle the application
run: cargo bundle --release
- name: Tarball the Mac App
run: tar -czvf target/release/bundle/osx/Weave.tar.gz target/release/bundle/osx/Weave.app
- name: Upload Mac App to GitHub
uses: actions/upload-artifact@v4
with:
name: mac-app
path: target/release/bundle/osx/Weave.tar.gz
if-no-files-found: error
compression-level: 9
overwrite: true
linux-test:
# It builds on my machine which is Mantic until i `do-release-upgrade`
# so let's try Mantic. Mantic won't start on GH actions, so let's try focal.
runs-on: ubuntu-focal
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Install CUDA
run: sudo apt-get install nvidia-cuda-toolkit nvidia-cudnn nvidia-cuda-dev
- name: Install LLVM tools
run: sudo apt-get install llvm
- name: Install Ninja
run: sudo apt-get install ninja-build
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
# fails because:
# https://github.com/taiki-e/cargo-llvm-cov/issues/370
# - name: Run tests with coverage
# run: cargo llvm-cov --workspace --lcov --output-path ./target/lcov.info
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Install cargo bundle
run: cargo install cargo-bundle
- name: Bundle the application
run: cargo bundle --release
- name: Tarball the Linux binary
run: tar -czvf target/release/bundle/linux/Weave.tar.gz target/release/bundle/linux/weave
- name: Upload Linux binary to GitHub
uses: actions/upload-artifact@v4
with:
name: linux-binary
# This will be a problem since the path includes the version and we
# don't know that until release runs. So the release build will have
# to happen after `release-plz` runs. But for now let's test this.
path: target/release/bundle/deb/weave_0.0.0_amd64.deb
if-no-files-found: error
compression-level: 9
overwrite: true
windows-test:
runs-on: windows-2019
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Install Ninja
run: choco install ninja
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
version: "18"
- name: Install Cuda Toolkit
uses: Jimver/cuda-toolkit@v0.2.15
with:
cuda: "12.4.1"
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
- name: Install LLVM tools
run: choco install llvm
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Run tests with coverage
run: cargo llvm-cov --workspace --lcov --output-path ./target/lcov.info
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.4.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Install cargo bundle
run: cargo install cargo-bundle
- name: Bundle the application
run: cargo bundle --release
- name: Upload Linux binary to GitHub
uses: actions/upload-artifact@v4
with:
name: windows-exe
path: target/release/bundle/windows/
if-no-files-found: error
compression-level: 9
overwrite: true
release-plz:
name: Create a release on crates.io
needs: [mac-test, linux-test, windows-test]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Run release-plz
id: release-plz
uses: MarcoIeni/release-plz-action@v0.5
env:
# not sure how I feel about this being an env var
GITHUB_TOKEN: ${{ secrets.PAT }}
# ditto
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Read release output
env:
RELEASES: ${{ steps.release-plz.outputs.releases }}
PRS: ${{ steps.release-plz.outputs.prs }}
PR: ${{ steps.release-plz.outputs.pr }}
PRS_CREATED: ${{ steps.release-plz.outputs.prs_created }}
RELEASES_CREATED: ${{ steps.release-plz.outputs.releases_created }}
run: |
set -e
echo "releases: $RELEASES" # example: [{"package_name":"my-package","prs":[{"html_url":"https://github.com/user/proj/pull/1439","number":1439}],"tag":"v0.1.0","version":"0.1.0"}]
echo "prs: $PRS" # example: [{"base_branch":"main","head_branch":"release-plz-2024-05-01T20-38-05Z","html_url":"https://github.com/MarcoIeni/rust-workspace-example/pull/198","number":198}]
echo "pr: $PR" # example: {"base_branch":"main","head_branch":"release-plz-2024-05-01T20-38-05Z","html_url":"https://github.com/MarcoIeni/rust-workspace-example/pull/198","number":198}
echo "prs_created: $PRS_CREATED" # example: true
echo "releases_created: $RELEASES_CREATED" # example: true
# get the number of releases with jq
releases_length=$(echo "$RELEASES" | jq 'length')
echo "releases_length: $releases_length"
# access the first release with jq
release_version=$(echo "$RELEASES" | jq -r '.[0].version')
echo "release_version: $release_version"
# access the first release with fromJSON. Docs: https://docs.github.com/en/actions/learn-github-actions/expressions
echo "release_version: ${{ fromJSON(steps.release-plz.outputs.releases)[0].version }}"
release_tag=$(echo "$RELEASES" | jq -r '.[0].tag')
echo "release_tag: $release_tag"
release_package_name=$(echo "$RELEASES" | jq -r '.[0].package_name')
echo "release_package_name: $release_package_name"
# print all names of released packages, one per line
echo "package_names: $(echo "$RELEASES" | jq -r '.[].package_name')"
# TODO: show how to store this in a variable and iterate over it (maybe an array?). PR welcome!
# iterate over released packages
for package_name in $(echo "$RELEASES" | jq -r '.[].package_name'); do
echo "released $package_name"
done
echo "pr_number: ${{ fromJSON(steps.release-plz.outputs.pr).number }}"
echo "pr_html_url: ${{ fromJSON(steps.release-plz.outputs.pr).html_url }}"
echo "pr_head_branch: ${{ fromJSON(steps.release-plz.outputs.pr).head_branch }}"
echo "pr_base_branch: ${{ fromJSON(steps.release-plz.outputs.pr).base_branch }}"
- name: Tag released PRs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASES: ${{ steps.release-plz.outputs.releases }}
run: |
set -e
# Iterate over released packages and add a label to the PRs
# shipped with the release.
for release in $(echo "$RELEASES" | jq -r -c '.[]'); do
package_name=$(echo "$release" | jq -r '.package_name')
version=$(echo "$release" | jq -r '.version')
prs_length=$(echo "$release" | jq '.prs | length')
if [ "$prs_length" -gt 0 ]; then
# Create label.
# Use `--force` to overwrite the label,
# so that the command does not fail if the label already exists.
label="released:$package_name-$version"
echo "Creating label $label"
gh label create $label --color BFD4F2 --force
for pr in $(echo "$release" | jq -r -c '.prs[]'); do
pr_number=$(echo "$pr" | jq -r '.number')
echo "Adding label $label to PR #$pr_number"
gh pr edit $pr_number --add-label $label
done
else
echo "No PRs found for package $package_name"
fi
done
publish-mac:
name: Publish Mac binary to GitHub
needs: [mac-test]
runs-on: ubuntu-latest
steps:
- name: Download Mac App
uses: actions/download-artifact@v4
with:
name: mac-app
path: target/release/bundle/osx/Weave.tar.gz
- name: Publish Mac App
uses: softprops/action-gh-release@v2.0.5
if: startsWith(github.ref, 'refs/tags/')
with:
files: target/release/bundle/osx/Weave.tar.gz
token: ${{ secrets.PAT }}
publish-linux:
name: Publish Linux binary to GitHub
needs: [linux-test]
runs-on: ubuntu-latest
steps:
- name: Download Linux binary
uses: actions/download-artifact@v4
with:
name: linux-binary
path: target/release/bundle/linux/Weave.tar.gz
- name: Publish Linux binary
uses: softprops/action-gh-release@v2.0.5
if: startsWith(github.ref, 'refs/tags/')
with:
files: target/release/bundle/deb/weave_0.0.0_amd64.deb
token: ${{ secrets.PAT }}
publish-windows:
name: Publish Windows binary to GitHub
needs: [windows-test]
runs-on: ubuntu-latest
steps:
- name: Download Windows binary
uses: actions/download-artifact@v4
with:
name: windows-exe
path: target/release/bundle/windows/
- name: Publish Windows binary
uses: softprops/action-gh-release@v2.0.5
if: startsWith(github.ref, 'refs/tags/')
with:
files: target/release/bundle/windows/
token: ${{ secrets.PAT }}