11name : CI
22
33on :
4- push :
5- branches :
6- - main
74 workflow_dispatch :
8- inputs :
9- workflow_to_run :
10- type : choice
11- description : Which workflow to run?
12- required : true
13- options :
14- - all
15- - hardhat-tests
16- - foundry-tests
175 pull_request :
18- types :
19- - ready_for_review
20- - review_requested
21- pull_request_review :
22- types : [submitted]
23-
24- defaults :
25- run :
26- shell : bash
6+ push :
7+ branches :
8+ - " main"
279
2810jobs :
29- run-linters :
30- if : github.ref == 'refs/heads/main' || github.event.review.state == 'approved' || github.event.action == 'ready_for_review' || github.event.action == 'review_requested'
11+ lint :
3112 runs-on : ubuntu-latest
3213 steps :
33- - uses : actions/checkout@v2
34- - uses : actions/setup-node@v2
35- with :
36- node-version : 14
37- - uses : actions/cache@v2
14+ - uses : actions/checkout@v3
15+
16+ - uses : actions/setup-node@v3
3817 with :
39- path : node_modules
40- key : yarn-${{ hashFiles('yarn.lock') }}
41- restore-keys : yarn-
18+ node-version : 18
19+ cache : " yarn"
20+
4221 - name : Install dependencies
43- run : |
44- npm config set //registry.npmjs.org/
45- yarn install --frozen-lockfile
22+ run : yarn install
23+
4624 - name : Run solhint
47- run : yarn lint:sol
48- - name : Run eslint
49- run : yarn lint:js:fix
25+ run : yarn lint:check
5026
51- hardhat-tests :
52- if : github.ref == 'refs/heads/main' || github.event.inputs.workflow_to_run == 'all' || github.event.inputs.workflow_to_run == 'hardhat-tests' || github.event.review.state == 'approved' || github.event.action == 'ready_for_review' || github.event.action == 'review_requested'
27+ - name : " Add lint summary"
28+ run : |
29+ echo "## Lint result" >> $GITHUB_STEP_SUMMARY
30+ echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
31+ build :
5332 runs-on : ubuntu-latest
5433 steps :
55- - uses : actions/checkout@v2
56- - uses : actions/setup-node@v2
34+ - uses : actions/checkout@v3
5735 with :
58- node-version : 14
59- - uses : actions/cache@v2
36+ submodules : " recursive"
37+
38+ - uses : actions/setup-node@v3
6039 with :
61- path : node_modules
62- key : yarn-${{ hashFiles('yarn.lock') }}
63- restore-keys : yarn-
40+ node-version : 18
41+ cache : " yarn"
42+
6443 - name : Install dependencies
65- run : |
66- npm config set //registry.npmjs.org/
67- yarn install --frozen-lockfile
68- # This is required separately from yarn test because it generates the typechain definitions
69- - name : Compile
44+ run : yarn install --frozen-lockfile
45+
46+ - name : Compile hardhat
7047 run : yarn hardhat:compile
48+
49+ - name : Install Foundry
50+ uses : foundry-rs/foundry-toolchain@v1
51+ with :
52+ version : nightly
53+
54+ - name : Compile foundry
55+ run : yarn foundry:compile --sizes
56+
57+ - name : " Cache the build so that it can be re-used by the other jobs"
58+ uses : " actions/cache/save@v3"
59+ with :
60+ key : " build-${{ github.sha }}"
61+ path : |
62+ cache-forge
63+ out
64+ cache-hh
65+ artifacts
66+ typechain
67+ node_modules
68+ - name : " Add build summary"
69+ run : |
70+ echo "## Build result" >> $GITHUB_STEP_SUMMARY
71+ echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
72+
73+ hardhat-tests :
74+ needs : ["build", "lint"]
75+ runs-on : ubuntu-latest
76+ steps :
77+ - uses : actions/checkout@v3
78+
79+ - uses : actions/setup-node@v3
80+ with :
81+ node-version : 18
82+ cache : " yarn"
83+
84+ - name : " Restore the cached build"
85+ uses : " actions/cache/restore@v3"
86+ with :
87+ fail-on-cache-miss : true
88+ key : " build-${{ github.sha }}"
89+ path : |
90+ cache-forge
91+ out
92+ cache-hh
93+ artifacts
94+ typechain
95+ node_modules
7196 - run : export NODE_OPTIONS=--max_old_space_size=11264
97+
7298 - name : Run unit tests
7399 run : yarn hardhat:test
74100 env :
@@ -78,30 +104,75 @@ jobs:
78104 ETH_NODE_URI_FORK : ${{ secrets.ETH_NODE_URI_FORK }}
79105 ETH_NODE_URI_MAINNET : ${{ secrets.ETH_NODE_URI_MAINNET }}
80106
107+ - name : " Add test summary"
108+ run : |
109+ echo "## Hardhat Unit tests result" >> $GITHUB_STEP_SUMMARY
110+ echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
111+
81112 foundry-tests :
82- if : github.ref == 'refs/heads/main' || github.event.inputs.workflow_to_run == 'all' || github.event.inputs.workflow_to_run == 'foundry-tests' || github.event.review.state == 'approved' || github.event.action == 'ready_for_review' || github.event.action == 'review_requested'
113+ needs : ["build", "lint"]
83114 runs-on : ubuntu-latest
84115 steps :
85116 - uses : actions/checkout@v2
86-
87- - uses : actions/setup-node@v2
88117 with :
89- node-version : 14
90- - uses : actions/cache@v2
91- with :
92- path : node_modules
93- key : yarn-${{ hashFiles('yarn.lock') }}
94- restore-keys : yarn-
95- - run : yarn install --frozen-lockfile
118+ submodules : " recursive"
96119
97120 - name : Install Foundry
98121 uses : foundry-rs/foundry-toolchain@v1
99122 with :
100123 version : nightly
124+
125+ - name : " Restore the cached build"
126+ uses : " actions/cache/restore@v3"
127+ with :
128+ fail-on-cache-miss : true
129+ key : " build-${{ github.sha }}"
130+ path : |
131+ cache-forge
132+ out
133+ cache-hh
134+ artifacts
135+ typechain
136+ node_modules
101137 - name : Run Foundry tests
102138 run : yarn foundry:test
103139 env :
104140 ETH_NODE_URI_MAINNET : ${{ secrets.ETH_NODE_URI_MAINNET }}
105141 ETH_NODE_URI_POLYGON : ${{ secrets.ETH_NODE_URI_POLYGON }}
106142 ETH_NODE_URI_GOERLI : ${{ secrets.ETH_NODE_URI_GOERLI }}
107143 ETH_NODE_URI_FANTOM : ${{ secrets.ETH_NODE_URI_FANTOM }}
144+ FOUNDRY_FUZZ_RUNS : " 5000"
145+
146+ - name : " Add test summary"
147+ run : |
148+ echo "## Foundry Unit tests result" >> $GITHUB_STEP_SUMMARY
149+ echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
150+
151+ slither-analyze :
152+ needs : ["build", "lint"]
153+ permissions :
154+ actions : " read"
155+ contents : " read"
156+ security-events : " write"
157+ runs-on : " ubuntu-latest"
158+ steps :
159+ - name : " Check out the repo"
160+ uses : " actions/checkout@v3"
161+
162+ - name : " Run Slither analysis"
163+ uses : " crytic/slither-action@v0.3.0"
164+ id : " slither"
165+ with :
166+ fail-on : " none"
167+ sarif : " results.sarif"
168+ node-version : 18
169+
170+ - name : " Upload SARIF file to GitHub code scanning"
171+ uses : " github/codeql-action/upload-sarif@v2"
172+ with :
173+ sarif_file : ${{ steps.slither.outputs.sarif }}
174+
175+ - name : " Add Slither summary"
176+ run : |
177+ echo "## Slither result" >> $GITHUB_STEP_SUMMARY
178+ echo "✅ Uploaded to GitHub code scanning" >> $GITHUB_STEP_SUMMARY
0 commit comments