-
Notifications
You must be signed in to change notification settings - Fork 12
275 lines (258 loc) · 9.81 KB
/
build.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
name: Build
# 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.
on:
pull_request:
push:
branches:
- main
- perm-*
workflow_dispatch:
inputs:
pull_request:
description: set to pull_request number to execute on external pr
required: false
env:
NODE_OPTIONS: "--max-old-space-size=12288"
jobs:
####### Check files and formatting #######
set-tags:
runs-on: ubuntu-latest
outputs:
git_branch: ${{ steps.check-git-ref.outputs.git_branch }}
git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
image_exists: ${{ steps.check-docker-image.outputs.image_exists }}
sha: ${{ steps.get-sha.outputs.sha }}
sha8: ${{ steps.get-sha.outputs.sha8 }}
polkadot_repo: ${{ steps.get-sha.outputs.polkadot_repo }}
polkadot_commit: ${{ steps.get-sha.outputs.polkadot_commit }}
polkadot_ver: ${{ steps.get-sha.outputs.polkadot_ver}}
steps:
- name: Check git ref
id: check-git-ref
# if PR
# else if manual PR
# else (push)
run: |
if [[ -n "${{ github.event.pull_request.head.sha }}" ]]; then
echo "git_branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
echo "git_ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
elif [[ -n "${{ github.event.inputs.pull_request }}" ]]; then
echo "git_branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
echo "git_ref=refs/pull/${{ github.event.inputs.pull_request }}/head" >> $GITHUB_OUTPUT
else
echo "git_branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
echo "git_ref=$GITHUB_REF" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
with:
ref: ${{ steps.check-git-ref.outputs.git_ref }}
- name: Get Sha
id: get-sha
run: |
echo "sha=$(git log -1 --format='%H')" >> $GITHUB_OUTPUT
echo "sha8=$(git log -1 --format='%H' | cut -c1-8)" >> $GITHUB_OUTPUT
echo "polkadot_repo=$(egrep -o 'https.*/polkadot' Cargo.lock | head -1)" >> $GITHUB_OUTPUT
echo "polkadot_commit=$(egrep -o '/polkadot.*#([^\"]*)' Cargo.lock | \
head -1 | sed 's/.*#//' | cut -c1-8)" >> $GITHUB_OUTPUT
echo "polkadot_ver=$(grep 'frame-system' Cargo.toml | sed -nE 's/.*polkadot-v([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' | head -1)" >> $GITHUB_OUTPUT
- name: Check existing docker image
id: check-docker-image
run: |
TAG=sha-${{ steps.get-sha.outputs.sha8 }}
echo "image_exists=$(docker image inspect purestake/moonbeam:$TAG > /dev/null && echo "true" || echo "false")" >> $GITHUB_OUTPUT
- name: Display variables
run: |
echo git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
echo sha: ${{ steps.get-sha.outputs.sha }}
echo sha8: ${{ steps.get-sha.outputs.sha8 }}
echo image_exists: ${{ steps.check-docker-image.outputs.image_exists }}
echo polkadot_repo: ${{ steps.get-sha.outputs.polkadot_repo }}
echo polkadot_commit: ${{ steps.get-sha.outputs.polkadot_commit }}
echo polkadot_ver: ${{ steps.get-sha.outputs.polkadot_ver }}
check-copyright:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Find un-copyrighted files
run: |
find . \! -name '*.expanded.rs' -name '*.rs' -exec grep -H -E -o -c Copyright {} \; | grep ':0' || true
FILECOUNT=$(find . \! -name '*.expanded.rs' -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
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: "yes"
max-depth: 4
check-editorconfig:
name: "Check editorconfig"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Setup editorconfig checker
run: |
ls /tmp/bin/ec-linux-amd64 || \
cd /tmp && \
wget https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.7.0/ec-linux-amd64.tar.gz && \
tar xvf ec-linux-amd64.tar.gz && \
chmod +x bin/ec-linux-amd64
- name: Check files
# Prettier and editorconfig-checker have different ideas about indentation
run: /tmp/bin/ec-linux-amd64 --exclude "(typescript-api\/src\/moon(?:base|beam|river)\/interfaces\/.*\.ts)|(test\/contracts\/lib\/.*)" -disable-indent-size
check-prettier:
name: "Check with Prettier"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Check with Prettier
run: |
npx prettier --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)' \
|| (git diff --quiet \
|| (echo 'Unable to show a diff because there are unstaged changes'; false) \
&& (npx prettier --ignore-path \
.prettierignore '**/*.(yml|js|ts|json)' -w --loglevel silent \
&& git --no-pager diff; git restore .) && false)
npx prettier --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
check-rust-fmt:
name: "Check with rustfmt"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: rustup show
- name: Format code with rustfmt
run: cargo fmt -- --check
####### Building and Testing binaries #######
cargo-clippy:
runs-on:
labels: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Setup Rust toolchain
run: rustup show
- name: Clippy
run: SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --features try-runtime,runtime-benchmarks
build:
runs-on:
labels: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
- name: Upload runtimes
uses: actions/[email protected]
with:
name: runtimes
path: runtimes
- name: Upload binary
uses: actions/[email protected]
with:
name: moonkit-template
path: build/moonkit-template
build-features:
runs-on:
labels: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
with:
features: "try-runtime,runtime-benchmarks"
- name: Upload binary
uses: actions/[email protected]
with:
name: moonkit-template-features
path: build/moonkit-template
rust-test:
runs-on:
labels: ubuntu-latest
needs: ["set-tags"]
env:
RUSTC_WRAPPER: "sccache"
CARGO_INCREMENTAL: "0"
SCCACHE_CACHE_SIZE: "100GB"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Setup Variables
shell: bash
run: |
echo "RUSTFLAGS=-C opt-level=3 -D warnings -C linker=clang -C link-arg=-fuse-ld=$(pwd)/mold/bin/mold" >> $GITHUB_ENV
- name: Setup Mold Linker
shell: bash
run: |
mkdir -p mold
curl -L --retry 10 --silent --show-error https://github.com/rui314/mold/releases/download/v1.1.1/mold-1.1.1-$(uname -m)-linux.tar.gz | tar -C $(realpath mold) --strip-components=1 -xzf -
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: |
if ! which "rustup" > /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
rustup show
# Checks are run after uploading artifacts since they are modified by the tests
- name: Unit tests
run: |
cargo test --profile testnet --all
- name: Run sccache stat for check pre test
run: ${SCCACHE_PATH} --show-stats