-
Notifications
You must be signed in to change notification settings - Fork 132
371 lines (339 loc) · 12.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
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
on:
schedule:
- cron: '0 3 * * *' # Nightly, run at 03:00 UTC
push:
tags:
- 'v[0-9]+.*' # Release tags matching v*, i.e. v1.0, v20.15.10
branches:
- 'ci/test/nightly' # For testing nightly build workflow
name: Release
jobs:
create_release:
name: Create release
if: >
github.repository_owner == 'input-output-hk'
|| startsWith(github.ref, 'refs/heads/ci/test/')
|| startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-ci-test.')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release_info.outputs.version }}
tag: ${{ steps.release_info.outputs.tag }}
date: ${{ steps.release_info.outputs.date }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: 'true'
- id: release_info
name: Get release information
run: python3 ./ci/release-info.py "$GITHUB_EVENT_NAME"
- if: ${{ steps.release_info.outputs.release_type == 'nightly' }}
name: Delete existing nightly releases
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set +e
git ls-remote --tags --refs origin 'refs/tags/nightly*' |
cut -f 2 |
while read ref; do
hub release delete ${ref#refs/tags/}
git push --delete origin $ref
done
- id: create_release
name: Create a draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
release_tag='${{ steps.release_info.outputs.tag }}'
hub release create ${{ steps.release_info.outputs.release_flags }} --draft \
-m "Release ${{ steps.release_info.outputs.version }} (in progress)" \
-t $GITHUB_SHA $release_tag
upload_url=$(timeout 1m bash -c "until hub release show -f '%uA' $release_tag; do sleep 1; done")
echo "::set-output name=upload_url::$upload_url"
cache_info:
name: Bootstrap cache
if: >
github.repository_owner == 'input-output-hk'
|| startsWith(github.ref, 'refs/heads/ci/test/')
|| startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-ci-test.')
runs-on: ubuntu-latest
outputs:
crates-io-index-head: ${{ steps.ls-crates-io-index.outputs.head }}
cargo-lock-hash: ${{ steps.hash-cargo-lock.outputs.hash }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: ls-crates-io-index
name: Get head commit hash of crates.io registry index
run: |
commit=$(
git ls-remote --heads https://github.com/rust-lang/crates.io-index.git master |
cut -f 1
)
echo "$commit"
echo "::set-output name=head::$commit"
- id: hash-cargo-lock
name: Calculate dependency cache key
run: |
hash=$(
ci/strip-own-version-from-cargo-lock.pl Cargo.lock |
sha1sum | cut -d ' ' -f 1
)
echo "$hash"
echo "::set-output name=hash::$hash"
update_deps:
name: Update dependencies
needs: cache_info
# Caches on Windows and Unix do not interop:
# https://github.com/actions/cache/issues/330#issuecomment-637701649
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Allow long paths on Windows
if: ${{ matrix.os == 'windows-latest' }}
shell: powershell
run: |
reg add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
git config --system core.longpaths true
- name: Cache cargo registry index
uses: actions/cache@v3
with:
path: ~/.cargo/registry/index
key: cargo-index-${{ needs.cache_info.outputs.crates-io-index-head }}
restore-keys: cargo-index-
- id: cargo-deps
name: Cache cargo dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-deps-v1-${{ needs.cache_info.outputs.cargo-lock-hash }}
- name: Check out the repository
uses: actions/checkout@v3
with:
submodules: true
- name: Fetch dependencies and update cargo registry
run: cargo fetch --locked
build_assets:
name: Build assets
needs: [create_release, cache_info, update_deps]
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
# Linux
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
# Macos
- { os: macos-latest, target: x86_64-apple-darwin }
target_cpu: [generic, broadwell]
toolchain: [stable]
cross: [false]
include:
# Windows
- config: { os: windows-latest, target: x86_64-pc-windows-msvc }
target_cpu: generic
toolchain: stable-x86_64-pc-windows-msvc
cross: false
- config: { os: windows-latest, target: x86_64-pc-windows-msvc }
target_cpu: broadwell
toolchain: stable-x86_64-pc-windows-msvc
cross: false
# Cross targets
- config: { os: ubuntu-latest, target: aarch64-unknown-linux-gnu }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: arm-unknown-linux-gnueabi }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: armv7-unknown-linux-gnueabihf }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
target_cpu: broadwell
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: aarch64-linux-android }
target_cpu: generic
toolchain: stable
cross: true
# - config: {os: ubuntu-latest, target: mips64el-unknown-linux-gnuabi64}
# target_cpu: generic
# toolchain: stable
# cross: true
# - config: {os: ubuntu-latest, target: powerpc64le-unknown-linux-gnu}
# target_cpu: generic
# toolchain: stable
# cross: true
steps:
- name: Allow long paths on Windows
if: ${{ matrix.os == 'windows-latest' }}
shell: powershell
run: |
reg add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
git config --system core.longpaths true
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.config.target }}
override: true
default: true
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: true
- name: Restore cargo registry index
uses: actions/cache@v3
with:
path: ~/.cargo/registry/index
key: cargo-index-${{ needs.cache_info.outputs.crates-io-index-head }}
- name: Restore cargo dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-deps-v1-${{ needs.cache_info.outputs.cargo-lock-hash }}
- name: Set up features and cargo config
shell: bash
run: |
case '${{ matrix.config.os }}' in
ubuntu-latest) features=systemd,gelf ;;
*) features=gelf ;;
esac
echo "JORMUNGANDR_FEATURES=$features" >> $GITHUB_ENV
mkdir .cargo
cat > .cargo/config.toml <<EOF
[target.${{ matrix.config.target }}]
rustflags = ["-C", "target-cpu=${{ matrix.target_cpu }}"]
[profile.release]
lto = "thin"
EOF
- if: ${{ matrix.cross }}
name: Create Cross.toml
shell: bash
run: |
cat > Cross.toml <<EOF
[build.env]
passthrough = ["DATE"]
EOF
- name: Build jormungandr
uses: actions-rs/cargo@v1
env:
DATE: ${{ needs.create_release.outputs.date }}
with:
use-cross: ${{ matrix.cross }}
command: build
args: >
--manifest-path jormungandr/Cargo.toml
--bin jormungandr
--no-default-features
--features ${{ env.JORMUNGANDR_FEATURES }}
--verbose
--locked
--release
--target ${{ matrix.config.target }}
- name: Build jcli
uses: actions-rs/cargo@v1
env:
DATE: ${{ needs.create_release.outputs.date }}
with:
use-cross: ${{ matrix.cross }}
command: build
args: >
--manifest-path jcli/Cargo.toml
--bin jcli
--verbose
--locked
--release
--target ${{ matrix.config.target }}
- id: pack-assets
name: Pack binaries
shell: bash
run: python3 ./ci/pack-assets.py ${{ needs.create_release.outputs.version }} ${{ matrix.config.target }} ${{ matrix.target_cpu }}
- name: Upload binaries to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ steps.pack-assets.outputs.release-archive }}
asset_name: ${{ steps.pack-assets.outputs.release-archive }}
asset_content_type: ${{ steps.pack-assets.outputs.release-content-type }}
- name: Upload checksum to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ steps.pack-assets.outputs.release-archive }}.sha256
asset_name: ${{ steps.pack-assets.outputs.release-archive }}.sha256
asset_content_type: text/plain
publish_release:
name: Publish release
needs: [create_release, build_assets]
runs-on: ubuntu-latest
outputs:
status: ${{ job.status }}
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Publish release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
hub release edit --draft=false \
-m 'Release ${{ needs.create_release.outputs.version }}' \
${{ needs.create_release.outputs.tag }}
remove_failed_release:
name: Remove the release upon a build failure
needs: [create_release, publish_release]
runs-on: ubuntu-latest
# we need always() to force the check to run even if one of the needed jobs fails
if: ${{ always() && needs.publish_release.outputs.status != 'success' }}
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Remove release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: hub release delete ${{ needs.create_release.outputs.tag }}
# send_slack_notification:
# name: Notify the team Slack channel about this release
# needs: [create_release, publish_release]
# runs-on: ubuntu-latest
# if: ${{ always() }}
# steps:
# - name: Produce action-slack-notify variables
# run: |
# status="${{ needs.publish_release.outputs.status }}"
# release="${{ needs.create_release.outputs.tag }}"
# if [ "$status" == "success" ]; then
# SLACK_STATUS="success"
# SLACK_MESSAGE=":rocket: Published release $release."
# else
# SLACK_STATUS="failure"
# SLACK_MESSAGE=":x: Release $release *FAILED*."
# fi
# cat <<EOF >> $GITHUB_ENV
# SLACK_STATUS=$SLACK_STATUS
# SLACK_MESSAGE=$SLACK_MESSAGE
# EOF
# - name: Send notification
# uses: eugene-babichenko/slack-notifier@v1
# with:
# webhook: ${{ secrets.SLACK_WEBHOOK }}
# status: ${{ env.SLACK_STATUS }}
# text: ${{ env.SLACK_MESSAGE }}