-
Notifications
You must be signed in to change notification settings - Fork 8
359 lines (301 loc) · 10.4 KB
/
ci.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
name: CI
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
- release/**
pull_request:
branches:
- main
- release/**
jobs:
# add get-diff job
get-diff:
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
contract: ${{ steps.get-diff-contract.outputs.diff }}
certora-contract: ${{ steps.get-diff-certora-contract.outputs.diff }}
certora-spec: ${{ steps.get-diff-certora-spec.outputs.diff }}
scripts: ${{ steps.get-diff-scripts.outputs.diff }}
agents: ${{ steps.get-diff-agents.outputs.diff }}
env: ${{ steps.get-diff-env.outputs.diff }}
steps:
- uses: actions/checkout@v3
- name: Get diff for contract
uses: technote-space/[email protected]
id: get-diff-contract # via outputs
with:
PATTERNS: |
+(contracts)/*.sol
+(contracts/**/*.sol
- name: Get diff for certora contract
uses: technote-space/[email protected]
id: get-diff-certora-contract # via outputs
with:
PATTERNS: |
+(certora)/**/*.sol
- name: Get diff for certora specs/scripts
uses: technote-space/[email protected]
id: get-diff-certora-spec # via outputs
with:
PATTERNS: |
+(certora)/**/*.spec
+(certora)/**/ci.sh
- name: Get diff for scripts/test
uses: technote-space/[email protected]
id: get-diff-scripts # via outputs
with:
PATTERNS: |
+(scripts|test)/*.+(js|ts)
+(scripts|test)/**/*.+(js|ts)
+hardhat.config.ts
+.eslintrc.js
- name: Get diff for agents
uses: technote-space/[email protected]
id: get-diff-agents # via outputs
with:
PATTERNS: |
+(agents)/*.+(js|ts)
+(agents)/**/*.+(js|ts)
+.eslintrc.js
- name: Get diff for example env
uses: technote-space/[email protected]
id: get-diff-env # via outputs
with:
PATTERNS: |
+.env.example.json
generate-json-schema:
name: .env JSON Schema Generator
runs-on: ubuntu-latest
needs: get-diff
if: needs.get-diff.outputs.env
steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: 16
- name: Generate JSON schema
run: |
yarn install
cp .env.example.json .env.json
npm install -g json-schema-generator
json-schema-generator .env.json -o env-schema.json --force --pretty
- name: Verify Schema
run: |
yarn compile
- name: Commit
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'CI: Generated Schema'
add: 'env-schema.json'
contract-size:
name: Contract Size
runs-on: ubuntu-latest
needs: generate-json-schema
if: ${{ always() && !contains(join(needs.generate-json-schema.result, ','), 'failure') && needs.get-diff.outputs.contract }}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 16
- name: Setup Environment
run: |
yarn install
cp .env.example.json .env.json
- name: Run Contract-sizer
run: |
yarn contract:size
test-contract:
name: Test Contract
runs-on: ubuntu-latest
needs: generate-json-schema
if: ${{ always() && !contains(join(needs.generate-json-schema.result, ','), 'failure') && (needs.get-diff.outputs.contract || needs.get-diff.outputs.scripts)}}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 16
- name: Setup Environment
run: |
yarn install
cp .env.example.json .env.json
- name: Run test
run: |
yarn test
linter:
name: Linter
runs-on: ubuntu-latest
needs: generate-json-schema
if: ${{ always() && !contains(join(needs.generate-json-schema.result, ','), 'failure') && (needs.get-diff.outputs.contract || needs.get-diff.outputs.certora-contract || needs.get-diff.outputs.scripts || needs.get-diff.outputs.agents)}}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 16
- name: Setup Environment
run: |
yarn install
- name: Run Linter Fix
run: |
yarn lint
- name: Commit
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'CI: Fix Lint'
solhint:
name: Solhint
runs-on: ubuntu-latest
needs: linter
if: needs.get-diff.outputs.contract
steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 16
- name: Setup Environment
run: |
yarn install
- name: Run Solhint
run: |
yarn solhint
generate-abis:
name: Generate ABIs
runs-on: ubuntu-latest
needs: linter
if: needs.get-diff.outputs.contract
steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: 16
- name: Setup environment
run: |
yarn install
cp .env.example.json .env.json
yarn compile
npm install -g fx
- name: Copy UI ABIs
run: |
mkdir -p abis/ui
cp artifacts/contracts/AddressStore.sol/AddressStore.json abis/ui/
cp artifacts/contracts/FeeVault.sol/FeeVault.json abis/ui/
cp artifacts/contracts/StakedBNBToken.sol/StakedBNBToken.json abis/ui/
cp artifacts/contracts/StakePool.sol/StakePool.json abis/ui/
cp artifacts/contracts/UndelegationHolder.sol/UndelegationHolder.json abis/ui/
cp artifacts/contracts/TimelockedAdmin.sol/TimelockedAdmin.json abis/ui/
- name: Extract info for Go ABIs
run: |
mkdir temp
fx artifacts/contracts/StakedBNBToken.sol/StakedBNBToken.json .abi > temp/StakedBNBToken.json
fx artifacts/contracts/StakedBNBToken.sol/StakedBNBToken.json .bytecode > temp/StakedBNBToken.bin
fx artifacts/contracts/StakePool.sol/StakePool.json .abi > temp/StakePool.json
fx artifacts/contracts/StakePool.sol/StakePool.json .bytecode > temp/StakePool.bin
fx artifacts/contracts/interfaces/ITokenHub.sol/ITokenHub.json .abi > temp/ITokenHub.json
fx artifacts/contracts/interfaces/ITokenHub.sol/ITokenHub.json .bytecode > temp/ITokenHub.bin
fx artifacts/contracts/interfaces/ITokenManager.sol/ITokenManager.json .abi > temp/ITokenManager.json
fx artifacts/contracts/interfaces/ITokenManager.sol/ITokenManager.json .bytecode > temp/ITokenManager.bin
- name: Generate Go ABIs
run: |
chmod 755 tools/abigen
mkdir -p abis/go
./tools/abigen --abi=temp/StakedBNBToken.json --bin=temp/StakedBNBToken.bin --pkg=contracts --type=StakedBNBToken --out=abis/go/staked_bnb_token.go
./tools/abigen --abi=temp/StakePool.json --bin=temp/StakePool.bin --pkg=contracts --type=StakePool --out=abis/go/stake_pool.go
./tools/abigen --abi=temp/ITokenHub.json --bin=temp/ITokenHub.bin --pkg=contracts --type=TokenHub --out=abis/go/token_hub.go
./tools/abigen --abi=temp/ITokenManager.json --bin=temp/ITokenManager.bin --pkg=contracts --type=TokenManager --out=abis/go/token_manager.go
rm -rf temp
- name: Commit
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'CI: Generated ABIs'
add: 'abis/*'
certora:
runs-on: ubuntu-latest
if: needs.get-diff.outputs.certora-contract || needs.get-diff.outputs.contract || needs.get-diff.outputs.certora-spec
needs: get-diff
steps:
- uses: actions/checkout@v3
- name: Use Node.js 14 LTS
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Installing dependencies
run: yarn install
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: actions/setup-java@v1
with:
java-version: "11"
java-package: jre
- name: Install dependencies
run: |
wget https://github.com/ethereum/solidity/releases/download/v0.8.7/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc
pip3 install certora-cli
- name: Prepare
run: |
chmod +x certora/scripts/*.sh
- name: Verify with Certora
run: |
certora/scripts/ci.sh
env:
CERTORAKEY: ${{ secrets.CERTORAKEY }}
slither-analyze:
name: Slither Analysis
runs-on: ubuntu-latest
needs: get-diff
permissions:
contents: read
actions: read
security-events: write
if: needs.get-diff.outputs.contract
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Environment
run: |
yarn install
cp .env.example.json .env.json
- name: Run Slither
uses: crytic/[email protected]
continue-on-error: true
id: slither
with:
node-version: 16
sarif: results.sarif
# - name: Upload SARIF file
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: "${{ steps.slither.outputs.sarif }}"