-
Notifications
You must be signed in to change notification settings - Fork 382
458 lines (442 loc) · 17.7 KB
/
release.yml
File metadata and controls
458 lines (442 loc) · 17.7 KB
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
name: Release
# Using a single file workflow is the preferred solution for our CI over workflow_runs.
# 1. It generates only 1 action item in the list making it more readable
# 2. It includes the PR/Commit text in the action item
# 3. Artifacts are not available between workflows.
# This is only allowing pushes on the moonbeam repo or pull request.
# In the case of pull request, the CI executes the workflow from
# the commit the **PR is merging into**. This prevents malicious attack trying
# to change the CI in the PR.
####### DO NOT CHANGE THIS !! #######
on: ["push", "pull_request_target"]
jobs:
####### Check files and formatting #######
check-copyright:
runs-on: ubuntu-latest
steps:
- name: Checkout
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v2
# by default the pull_requst_target event checks out the base branch, i.e. dev
# so we need to explicitly checkout the head of the PR
# we use fetch-depth 0 to make sure the full history is checked out and we can compare against
# the base commit (branch) of the PR
# more info https://github.community/t/github-actions-are-severely-limited-on-prs/18179/16
# we checkout merge_commit here as this contains all new code from dev also. we don't need to compare against base_commit
with:
fetch-depth: 0
ref: refs/pull/${{ github.event.pull_request.number }}/merge
# repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Checkout
# for non PR runs we just checkout the default, which is a sha on a branch probably
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v2
- name: Find un-copyrighted files
run: |
find . -name '*.rs' -exec grep -H -E -o -c Copyright {} \; | grep ':0' || true
FILECOUNT=$(find . -name '*.rs' -exec grep -H -E -o -c 'Copyright' {} \; | grep -c ':0' || true)
if [[ $FILECOUNT -eq 0 ]]; then
true
else
false
fi
check-links:
runs-on: ubuntu-latest
steps:
- name: Checkout
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: Checkout
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v2
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: "yes"
check-editorconfig:
name: "Check editorconfig"
runs-on: ubuntu-latest
steps:
- name: Checkout
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: Checkout
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v2
- name: Setup editorconfig checker
run: |
wget https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.1.0/ec-linux-amd64.tar.gz
tar xvf ec-linux-amd64.tar.gz
chmod +x bin/ec-linux-amd64
- name: Check files
run: bin/ec-linux-amd64
check-prettier:
name: "Check with Prettier"
runs-on: ubuntu-latest
steps:
- name: Checkout
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: Checkout
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v2
- name: Check with Prettier
run: npx prettier --check --ignore-path .gitignore '**/*.(yml|js|ts|json)'
####### Building and Testing binaries #######
build:
runs-on: ubuntu-latest
outputs:
RUSTC: ${{ steps.get-rust-versions.outputs.rustc }}
steps:
- name: Checkout
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: Checkout
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v2
- name: Cache Rust dependencies
uses: actions/cache@v2
id: cache
with:
path: |
~/.cargo/registry
~/.cargo/git
target
node/standalone/target
key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.OS }}-build
- uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
# Toolchain is autodetected from `rust-toolchain` file
# https://github.com/actions-rs/toolchain#the-toolchain-file
#toolchain: ${{ env.WASM_BUILD_TOOLCHAIN }}
default: true
- id: get-rust-versions
run: |
echo "::set-output name=rustc::$(rustc --version)"
- name: Build Parachain Node
run: cargo build --release --verbose --all
- name: Build Standalone Node
run: |
cd node/standalone
cargo build --release --verbose --all
# We determine whether there are unmodified Cargo.lock files by:
# 1. Asking git for a list of all modified files
# 2. Using grep to reduce the list to only Cargo.lock files
# 3. Counting the number of lines of output
- name: Check Cargo Toml
run: |
FILECOUNT=$(git diff-index --name-only HEAD | grep Cargo.lock | wc -l)
if [[ $FILECOUNT -eq 0 ]]; then
echo "All lock files are valid"
else
echo "The following Cargo.lock files have uncommitted changes"
git diff-index --name-only HEAD | grep Cargo.lock
false
fi
- name: Run tests
run: cargo test --release --verbose --all
- name: Typescript tests (against standalone node)
run: |
cd tests
npm install
npm run test;
- name: Save parachain binary
run: |
mkdir -p build/alphanet
mkdir -p build/standalone
cp target/release/moonbase-alphanet build/alphanet/moonbase-alphanet;
cp node/standalone/target/release/moonbase-standalone build/standalone/moonbase-standalone;
- name: Upload moonbase-alphanet node
uses: actions/upload-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet
- name: Upload moonbase-standalone node
uses: actions/upload-artifact@v2
with:
name: moonbase-standalone
path: build/standalone
####### Prepare and Deploy Docker images #######
generate-parachain-specs:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet
- name: Generate specs
run: |
chmod uog+x build/alphanet/moonbase-alphanet
PARACHAIN_BINARY=build/alphanet/moonbase-alphanet scripts/generate-parachain-specs.sh
- name: Upload parachain specs
uses: actions/upload-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet
docker-parachain:
runs-on: ubuntu-latest
needs: ["build", "generate-parachain-specs"]
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=purestake/moonbase-parachain-testnet
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
driver-opts: |
image=moby/buildkit:master
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push parachain
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/moonbase-alphanet.Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
docker-standalone:
runs-on: ubuntu-latest
needs: ["build"]
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: moonbase-standalone
path: build/standalone
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=purestake/moonbase
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
driver-opts: |
image=moby/buildkit:master
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push standalone node
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/moonbase-standalone.Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
####### Prepare the release draft #######
publish-draft-release:
runs-on: ubuntu-latest
needs: ["build", "generate-parachain-specs"]
if: |
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
outputs:
release_url: ${{ steps.create-release.outputs.html_url }}
asset_upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
path: moonbeam
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7
- name: Generate release text
env:
RUSTC: ${{ needs.build.outputs.rustc }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gem install changelogerator git toml
ruby $GITHUB_WORKSPACE/moonbeam/scripts/github/generate_release_text.rb | tee release_text.md
- name: Create draft release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Moonbase Alphanet ${{ github.ref }}
body_path: ./release_text.md
draft: true
publish-runtimes:
runs-on: ubuntu-latest
needs: ["publish-draft-release"]
# We want to store the binaries also when it is not a version release. This is used
# in case such as providing binaries when creating a new tutorial version.
if: |
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
runtime: ["moonbase-alphanet"]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7
- name: Get runtime version
id: get-runtime-ver
run: |
runtime_ver="$(ruby -e 'require "./scripts/github/lib.rb"; puts get_runtime("${{ matrix.runtime }}")')"
echo "::set-output name=runtime_ver::$runtime_ver"
- name: Upload ${{ matrix.runtime }} wasm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-runtime.wasm
asset_name: ${{ matrix.runtime }}-runtime-v${{ steps.get-runtime-ver.outputs.runtime_ver }}.wasm
asset_content_type: application/wasm
- name: Upload ${{ matrix.runtime }} node
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}
asset_name: ${{ matrix.runtime }}
asset_content_type: application/octet-stream
- name: Upload ${{ matrix.runtime }} specs plain
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-specs-plain.json
asset_name: ${{ matrix.runtime }}-specs-plain.json
asset_content_type: application/json
- name: Upload ${{ matrix.runtime }} specs raw
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-specs-raw.json
asset_name: ${{ matrix.runtime }}-specs-raw.json
asset_content_type: application/json
- name: Upload ${{ matrix.runtime }} genesis
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-genesis.txt
asset_name: ${{ matrix.runtime }}-genesis.txt
asset_content_type: text/plain