-
Notifications
You must be signed in to change notification settings - Fork 1
321 lines (277 loc) · 9.9 KB
/
rust.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
name: Test and publish Supreme
on:
push:
branches: [main]
# Cancel previously running workflows
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Rust (nightly)
uses: dtolnay/rust-toolchain@nightly
id: rust-toolchain
with:
components: rustfmt, clippy
- name: Cache cargo
uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --locked
- name: Run linting
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Check formatting
run: cargo fmt --all -- --check
# Analyze commits and determine if a new release should be published
# If a new release should be published, the next version is outputted
next-version:
name: Get next version
runs-on: ubuntu-latest
outputs:
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install semantic-release-cargo
uses: taiki-e/install-action@v2
with:
tool: semantic-release-cargo@2
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
id: semantic
with:
dry_run: true
semantic_version: 17.1.1
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: New release should be published
if: steps.semantic.outputs.new_release_published == 'true'
run: |
echo ${{ steps.semantic.outputs.new_release_version }}
build:
name: Build
needs: [test, next-version]
if: needs.next-version.outputs.new_release_published == 'true'
runs-on: ${{ matrix.build.os }}
env:
NAME: supreme-${{ matrix.build.target }}
CARGO: cargo
strategy:
matrix:
build:
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
cross: true
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
cross: true
- os: ubuntu-latest
target: i686-unknown-linux-gnu
cross: true
- os: ubuntu-latest
target: i686-unknown-linux-musl
cross: true
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
cross: false
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
cross: false
- os: macOS-latest
target: x86_64-apple-darwin
cross: false
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Rust (nightly)
uses: dtolnay/rust-toolchain@nightly
id: rust-toolchain
with:
target: ${{ matrix.build.target }}
- name: Cache cargo
uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install semantic-release-cargo
uses: taiki-e/install-action@v2
with:
tool: semantic-release-cargo@2
- name: Prepare semantic-release for Rust
run: semantic-release-cargo prepare ${{ needs.next-version.outputs.new_release_version }}
- name: Install cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Configure cross
if: matrix.build.cross
run: echo "CARGO=cross" >> "$GITHUB_ENV"
- name: Compile release binary
run: ${{ env.CARGO }} build --bin supreme --release --target ${{ matrix.build.target }}
- name: Create release archive
id: release
run: |
mkdir "$NAME"
cp target/${{ matrix.build.target }}/release/supreme "$NAME/"
cp README.md "$NAME/"
tar -czvf "$NAME.tar.gz" "$NAME"
SHA=$(shasum -a 256 "$NAME.tar.gz" | cut -d " " -f 1)
echo "SHA=$SHA" >> $GITHUB_OUTPUT
- name: Upload release artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.build.target }}
path: ${{ env.NAME }}.tar.gz
if-no-files-found: error
retention-days: 1
build-macos:
name: Build (Apple Silicon)
needs: [test, next-version]
if: needs.next-version.outputs.new_release_published == 'true'
runs-on: macOS-latest
outputs:
sha: ${{ steps.release.outputs.SHA }}
env:
NAME: supreme-aarch64-apple-darwin
TARGET: aarch64-apple-darwin
CARGO: cargo
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Rust (nightly)
uses: dtolnay/rust-toolchain@nightly
id: rust-toolchain
with:
target: ${{ env.TARGET }}
- name: Cache cargo
uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install semantic-release-cargo
uses: taiki-e/install-action@v2
with:
tool: semantic-release-cargo@2
- name: Prepare semantic-release for Rust
run: semantic-release-cargo prepare ${{ needs.next-version.outputs.new_release_version }}
- name: Install cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Configure cross
run: echo "CARGO=cross" >> "$GITHUB_ENV"
- name: Compile release binary
run: ${{ env.CARGO }} build --bin supreme --release --target ${{ env.TARGET }}
- name: Create release archive
id: release
run: |
mkdir "$NAME"
cp target/${{ env.TARGET }}/release/supreme "$NAME/"
cp README.md "$NAME/"
tar -czvf "$NAME.tar.gz" "$NAME"
SHA=$(shasum -a 256 "$NAME.tar.gz" | cut -d " " -f 1)
echo "SHA=$SHA" >> $GITHUB_OUTPUT
- name: Upload release artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.TARGET }}
path: ${{ env.NAME }}.tar.gz
if-no-files-found: error
retention-days: 1
release:
name: Create release
needs: [build-macos, build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download release artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: ls artifacts
run: ls -R ./artifacts
- name: Install semantic-release-cargo
uses: taiki-e/install-action@v2
with:
tool: semantic-release-cargo@2
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
id: semantic
with:
semantic_version: 17.1.1
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
homebrew:
name: Publish on Homebrew
runs-on: ubuntu-latest
if: needs.next-version.outputs.new_release_published == 'true'
needs: [next-version, build-macos, release]
env:
SHA: ${{ needs.build-macos.outputs.sha }}
VERSION: ${{ needs.next-version.outputs.new_release_version }}
steps:
- name: Checkout Homebrew formula
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
repository: opendevtools/homebrew-supreme
path: homebrew-supreme
- name: Create template file
uses: "finnp/create-file-action@master"
env:
FILE_NAME: "homebrew-supreme/template.rb"
FILE_BASE64: "Y2xhc3MgU3VwcmVtZSA8IEZvcm11bGEKICB2ZXJzaW9uICJ7e3ZlcnNpb259fSIKICBkZXNjICJBIENMSSB0b29sIHRoYXQgaGVscHMgeW91IGdldCB1cCBhbiBydW5uaW5nIGZhc3QiCiAgaG9tZXBhZ2UgImh0dHBzOi8vZ2l0aHViLmNvbS9vcGVuZGV2dG9vbHMvc3VwcmVtZSIKICB1cmwgImh0dHBzOi8vZ2l0aHViLmNvbS9vcGVuZGV2dG9vbHMvc3VwcmVtZS9yZWxlYXNlcy9kb3dubG9hZC92I3t2ZXJzaW9ufS9zdXByZW1lLSN7dmVyc2lvbn0tYWFyY2g2NC1hcHBsZS1kYXJ3aW4udGFyLmd6IgogIHNoYTI1NiAie3tzaGF9fSIKCiAgZGVmIGluc3RhbGwKICAgIGJpbi5pbnN0YWxsICJzdXByZW1lIgogIGVuZAplbmQKCg=="
- name: Update Homebrew formula
working-directory: ./homebrew-supreme
run: |
git config --local user.name github-actions
git config --local user.email [email protected]
cat template.rb | sed -e 's/{{version}}/'"$VERSION"'/g' -e 's/{{sha}}/'"$SHA"'/g' > Formula/supreme.rb
rm template.rb
git commit -am "feat(release): $VERSION"
- name: Push changes
uses: ad-m/github-push-action@master
with:
directory: ./homebrew-supreme
github_token: ${{ secrets.SUPREME_HOMEBREW_PAT }}
branch: main
repository: opendevtools/homebrew-supreme