-
Notifications
You must be signed in to change notification settings - Fork 7
349 lines (316 loc) · 12.1 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
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
on:
push:
tags:
- v*
name: Release
jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/44937/highlight/true#M5978
- name: Get the version
id: get_version
run: |
set -x
version=${GITHUB_REF/refs\/tags\//}
echo VERSION=$version >> $GITHUB_ENV
# remove the leading "v" for subsequent usage
version=${version/v/}
# check if this is a "preview" release and should be marked as "prerelease" in GitHub releases
if [[ $version == *"preview"* ]]; then
echo PRERELEASE=true >> $GITHUB_ENV
else
# check that the version in Cargo.toml is equal to the tag
grep -q "^version = \"${version}\"" Cargo.toml || (echo "$(tput setaf 1)Tag version did NOT match version in Cargo.toml" && false)
echo PRERELEASE=false >> $GITHUB_ENV
fi
shell: bash
- name: Create GitHub release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
prerelease: ${{ env.PRERELEASE }}
- name: Save artifacts
run: |
mkdir artifacts
echo "${{ steps.release.outputs.upload_url }}" | tee artifacts/release-upload-url
echo $VERSION | tee artifacts/release-version
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts
release:
name: Build and Upload
needs: ['create-release']
strategy:
matrix:
binary: ["pewpew", "pewpew-config-updater"]
build: ["linux", "arm-v7", "aarch64", "macos", "windows"]
include:
- binary: "pewpew"
build_param: "--bin"
- binary: "pewpew-config-updater"
build_param: "-p"
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl
cross: false
- build: arm-v7
os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
linker: gcc-arm-linux-gnueabihf
cross: true
- build: aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-musl
linker: gcc-aarch64-linux-gnu
cross: true
- build: macos
os: macos-latest
cross: false
- build: windows
os: windows-latest
cross: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: artifacts
path: artifacts
- name: Get upload data
id: upload_data
shell: bash
run: |
release_upload_url="$(cat artifacts/release-upload-url)"
echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
release_version="$(cat artifacts/release-version)"
echo "VERSION=$release_version" >> $GITHUB_ENV
- name: Set Cargo.toml version
id: set_cargo_version
shell: bash
run: |
# remove the leading "v" for subsequent usage
version=${VERSION/v/}
# replace the version value in Cargo.toml with the tag version (so we don't need to create extraneous commits for every preview version)
cp Cargo.toml Cargo2.toml
sed "0,/^version = \".*\"/s//version = \"$version\"/" Cargo2.toml > Cargo.toml
- name: Install Linker
if: matrix.cross
run: |
sudo apt update
sudo apt install ${{ matrix.linker }}
- name: Build for non-Linux # Windows and MacOS
uses: actions-rs/toolchain@v1
if: matrix.os != 'ubuntu-latest'
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
if: matrix.os != 'ubuntu-latest'
with:
command: build
args: -q --release ${{ matrix.build_param }} ${{ matrix.binary }}
# https://github.com/actions-rs/cargo#cross-compilation
- name: Build with cross # ARM builds
uses: actions-rs/toolchain@v1
if: matrix.cross
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
- uses: actions-rs/cargo@v1
if: matrix.cross
with:
use-cross: true
command: build
args: -q --release ${{ matrix.build_param }} ${{ matrix.binary }} --target ${{ matrix.target }}
- name: Build for Linux
uses: ./.github/actions/linux-x86_64-musl/
if: matrix.build == 'linux'
with:
args: cargo build -q --release ${{ matrix.build_param }} ${{ matrix.binary }} --target x86_64-unknown-linux-musl
- name: Compress for Linux/Arm
if: matrix.os == 'ubuntu-latest'
run: |
TARGET=$(echo "${{ matrix.target }}" | sed -e "s/-musl.*//" -e "s/-unknown//")
asset_name="${{ matrix.binary }}-$VERSION-$TARGET.tar.xz"
echo "ASSET_NAME=$asset_name" >> $GITHUB_ENV
XZ_OPT=-9 tar -C ./target/${{ matrix.target }}/release/ -cJf $asset_name ${{ matrix.binary }}
- name: Compress for Windows
if: matrix.os == 'windows-latest'
shell: bash
run: |
asset_name="${{ matrix.binary }}-$VERSION-windows-x86_64.zip"
echo "ASSET_NAME=$asset_name" >> $GITHUB_ENV
7z a -mm=Deflate64 -mfb=258 -mpass=15 $asset_name ./target/release/${{ matrix.binary }}.exe
- name: Compress for macOS
if: matrix.os == 'macos-latest'
run: |
asset_name="${{ matrix.binary }}-$VERSION-apple-darwin-x86_64.tar.xz"
echo "ASSET_NAME=$asset_name" >> $GITHUB_ENV
XZ_OPT=-9 tar -C ./target/release/ -cJf $asset_name ${{ matrix.binary }}
- name: Upload release asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: ${{ env.ASSET_NAME }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: application/octet-stream
wasm-release-config:
name: Wasm Pack and Upload Node Release
needs: ['create-release']
strategy:
matrix:
wasm-dirctory: ["config-wasm"]
include:
- wasm-dirctory: config-wasm
file-prefix: config
runs-on: ubuntu-latest
env:
working-directory: ./lib/${{ matrix.wasm-dirctory }}
steps:
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: artifacts
path: artifacts
- name: Get upload data
id: upload_data
shell: bash
run: |
release_upload_url="$(cat artifacts/release-upload-url)"
echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
release_version="$(cat artifacts/release-version)"
echo "VERSION=$release_version" >> $GITHUB_ENV
- name: Set Cargo.toml version
id: set_cargo_version
shell: bash
run: |
# remove the leading "v" for subsequent usage
version=${VERSION/v/}
# replace the version value in Cargo.toml with the tag version (so we don't need to create extraneous commits for every preview version)
cp Cargo.toml Cargo2.toml
sed "0,/^version = \".*\"/s//version = \"$version\"/" Cargo2.toml > Cargo.toml
echo "version = $version"
echo "Cargo $(grep "^version =" Cargo.toml )"
working-directory: ${{env.working-directory}}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Create the Web Assembly
id: wasm_pack
run: |
set -x
# install wasm-pack
mkdir ~/bin
PATH=$PATH:~/bin
curl -sSL https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz \
| tar -xz --strip-components=1 -C ~/bin --no-anchored wasm-pack
wasm-pack build --release -t nodejs --scope fs
working-directory: ${{env.working-directory}}
shell: bash
- name: Compress for Linux
run: |
asset_name="pewpew-$VERSION-${{ matrix.wasm-dirctory }}.tar.xz"
echo "ASSET_NAME=$asset_name" >> $GITHUB_ENV
XZ_OPT=-9 tar -C ./ -cJf $asset_name package.json ${{ matrix.file-prefix }}*
working-directory: ${{env.working-directory}}/pkg/
- name: Upload release asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: ${{env.working-directory}}/pkg/${{ env.ASSET_NAME }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: application/octet-stream
# The hdr-histogram-wasm and config-gen need to be build with bundler rather than nodejs
wasm-release-histogram:
name: Wasm Pack and Upload Bundler Release
needs: ['create-release']
strategy:
matrix:
wasm-dirctory: ["hdr-histogram-wasm", "config-gen"]
include:
- wasm-dirctory: hdr-histogram-wasm
file-prefix: hdr
- wasm-dirctory: config-gen
file-prefix: config
runs-on: ubuntu-latest
env:
working-directory: ./lib/${{ matrix.wasm-dirctory }}
steps:
- uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: artifacts
path: artifacts
- name: Get upload data
id: upload_data
shell: bash
run: |
release_upload_url="$(cat artifacts/release-upload-url)"
echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
release_version="$(cat artifacts/release-version)"
echo "VERSION=$release_version" >> $GITHUB_ENV
- name: Set Cargo.toml version
id: set_cargo_version
shell: bash
run: |
# remove the leading "v" for subsequent usage
version=${VERSION/v/}
# replace the version value in Cargo.toml with the tag version (so we don't need to create extraneous commits for every preview version)
cp Cargo.toml Cargo2.toml
sed "0,/^version = \".*\"/s//version = \"$version\"/" Cargo2.toml > Cargo.toml
echo "version = $version"
echo "Cargo $(grep "^version =" Cargo.toml )"
working-directory: ${{env.working-directory}}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Create the Web Assembly
id: wasm_pack
run: |
set -x
# install wasm-pack
mkdir ~/bin
PATH=$PATH:~/bin
curl -sSL https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz \
| tar -xz --strip-components=1 -C ~/bin --no-anchored wasm-pack
wasm-pack build --release -t bundler --scope fs
working-directory: ${{env.working-directory}}
shell: bash
- name: Compress for Linux
run: |
asset_name="pewpew-$VERSION-${{ matrix.wasm-dirctory }}.tar.xz"
echo "ASSET_NAME=$asset_name" >> $GITHUB_ENV
XZ_OPT=-9 tar -C ./ -cJf $asset_name package.json ${{ matrix.file-prefix }}*
working-directory: ${{env.working-directory}}/pkg/
- name: Upload release asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: ${{env.working-directory}}/pkg/${{ env.ASSET_NAME }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: application/octet-stream