-
Notifications
You must be signed in to change notification settings - Fork 32
306 lines (280 loc) · 10.6 KB
/
solidity.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
name: Solidity
on:
pull_request:
paths:
- 'packages/contracts-core/**'
- 'packages/contracts-rfq/**'
- '.github/workflows/solidity.yml'
- 'packages/contracts-communication/**'
- 'packages/solidity-devops/**'
push:
paths:
- 'packages/contracts-core/**'
- 'packages/contracts-rfq/**'
- 'packages/contracts-communication/**'
- 'packages/solidity-devops/**'
- '.github/workflows/solidity.yml'
jobs:
changes:
needs: cancel-outdated
runs-on: ubuntu-latest
outputs:
# Expose matched filters as job 'packages' output variable
packages: ${{ steps.filter_solidity.outputs.changes }}
package_count: ${{ steps.length.outputs.FILTER_LENGTH }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# if any of these packages use submodules in the future, please uncomment this line
# submodules: 'recursive'
- uses: dorny/paths-filter@v2
id: filter_solidity
with:
# make sure to update run-goreleaser when adding a new package here
# also add to the get-project-id step
filters: |
contracts-core: 'packages/contracts-core/**'
contracts-rfq: 'packages/contracts-rfq/**'
solidity-devops: 'packages/solidity-devops/**'
contracts-communication: 'packages/contracts-communication/**'
- id: length
run: |
export FILTER_LENGTH=$(echo $FILTERED_PATHS | jq '. | length')
echo "##[set-output name=FILTER_LENGTH;]$(echo $FILTER_LENGTH)"
env:
FILTERED_PATHS: ${{ steps.filter_solidity.outputs.changes }}
docs:
name: Deploy Docs
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.package_count > 0 }}
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
env:
WORKING_DIRECTORY: 'packages/${{matrix.package}}'
VERCEL_TOKEN: '${{ secrets.VERCEL_TOKEN }}'
VERCEL_ORG_ID: '${{ secrets.VERCEL_ORG_ID }}'
NODE_ENV: 'production'
steps:
- uses: actions/checkout@v4
- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
with:
cache: 'npm'
cache-path: ''
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
# TODO: get back to nightly once `forge doc` is working with it
version: nightly-09fe3e041369a816365a020f715ad6f94dbce9f2
- name: Install Vercel CLI
run: npm install --global [email protected]
- name: Get Project ID
id: project_id
# see: https://stackoverflow.com/a/75231888 for details
run: |
PROJECT_IDS=$(cat <<END
{
"contracts-core": "${{ secrets.VERCEL_CONTRACT_DOCS_PROJECT_ID}}",
"contracts-rfq": "${{ secrets.VERCEL_CONTRACT_RFQ_DOCS_PROJECT_ID }}",
"contracts-communication": "${{ secrets.VERCEL_COMMUNICATION_DOCS_PROJECT_ID }}",
"solidity-devops": "${{ secrets.VERCEL_DEVOPS_DOCS_PROJECT_ID }}"
}
END
)
TARGET_ID=$(echo $PROJECT_IDS | jq -r 'to_entries[] | select(.key=="${{ matrix.package }}") | .value')
echo "##[set-output name=VERCEL_PROJECT_ID;]$(echo $TARGET_ID)"
- name: Build Docs
working-directory: 'packages/${{matrix.package}}'
# https://github.com/orgs/vercel/discussions/3322#discussioncomment-6480458
# TODO: dedupe vercel.package.json
run: |
forge doc
cp vercel.package.json docs/package.json
- name: Deploy (Prod)
if: ${{ format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
run: |
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
vercel build --token=${{ secrets.VERCEL_TOKEN }} --prod
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} --prod
env:
VERCEL_PROJECT_ID: ${{ steps.project_id.outputs.VERCEL_PROJECT_ID}}
- name: Deploy
run: |
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
vercel build --token=${{ secrets.VERCEL_TOKEN }}
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
env:
VERCEL_PROJECT_ID: ${{ steps.project_id.outputs.VERCEL_PROJECT_ID}}
cancel-outdated:
name: Cancel Outdated Jobs
runs-on: ubuntu-latest
steps:
- id: skip_check
if: ${{ format('refs/heads/{0}', github.event.repository.default_branch) != github.ref && !contains(github.event.head_commit.message, '[no_skip]') }}
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: 'true'
slither:
name: Slither
if: ${{ needs.changes.outputs.package_count > 0 }}
# see https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/setting-up-code-scanning-for-a-repository
runs-on: ubuntu-latest
needs: changes
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
permissions:
# always required
security-events: write
# only required for private repos
actions: read
contents: read
steps:
- name: Checkout repository
if: ${{ matrix.package != 'solidity-devops' }}
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: 'recursive'
- name: Setup NodeJS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs
- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
# TODO: find a flag for this
- name: Delete Untested Files
if: ${{ matrix.package != 'solidity-devops' }}
working-directory: './packages/${{matrix.package}}'
run: |
rm -rf test/ || true
rm -rf script/ || true
- name: Build Contracts
if: ${{ matrix.package != 'solidity-devops' }}
# TODO: unforunately, as of now concurrency needs to be 1 since if multiple instances of forge try to install the same version
# of solc at the same time, we get "text file busy" errors. See https://github.com/synapsecns/sanguine/actions/runs/8457116792/job/23168392860?pr=2234
# for an example.
run: |
npx lerna exec npm run build:slither --concurrency=1
- name: Run Slither
if: ${{ matrix.package != 'solidity-devops' }}
uses: crytic/[email protected]
continue-on-error: true
id: slither
with:
node-version: '${{steps.nvmrc.outputs.NVMRC}}'
target: './packages/${{matrix.package}}'
ignore-compile: true
sarif: results.sarif
solc-version: 0.8.17
- name: Upload SARIF file
if: ${{!github.event.repository.private && matrix.package != 'solidity-devops'}}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ./results.sarif
coverage:
name: Foundry Coverage
runs-on: ubuntu-latest
if: ${{ needs.changes.outputs.package_count > 0 }}
needs: changes
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
if: ${{ matrix.package != 'solidity-devops' }}
with:
submodules: recursive
- name: Setup Node JS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs
- name: Installing dependencies
if: ${{ matrix.package != 'solidity-devops' }}
run: yarn install --immutable
- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run Foundry Tests
if: ${{ matrix.package != 'solidity-devops' }}
working-directory: './packages/${{matrix.package}}'
run: forge coverage -vvv --report lcov --report summary >> $GITHUB_STEP_SUMMARY
- name: Send Coverage (Codecov)
if: ${{ matrix.package != 'solidity-devops' }}
uses: Wandalen/[email protected]
with:
action: codecov/codecov-action@v3
current_path: './packages/${{matrix.package}}'
with: |
token: ${{ secrets.CODECOV }}
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
flags: solidity
attempt_limit: 5
attempt_delay: 30000
snapshot:
runs-on: ubuntu-latest
name: Foundry Gas Snapshot
if: ${{ needs.changes.outputs.package_count > 0 }}
needs: changes
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
if: ${{ matrix.package != 'solidity-devops' }}
with:
submodules: recursive
- name: Setup Node JS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs
- name: Installing dependencies
if: ${{ matrix.package != 'solidity-devops' }}
run: yarn install --immutable
- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run snapshot
if: ${{ matrix.package != 'solidity-devops' }}
working-directory: './packages/${{matrix.package}}'
run: forge snapshot >> $GITHUB_STEP_SUMMARY
size-check:
name: Foundry Size Check
runs-on: ubuntu-latest
if: ${{ needs.changes.outputs.package_count > 0 }}
needs: changes
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
if: ${{ matrix.package != 'solidity-devops' }}
with:
submodules: recursive
- name: Setup Node JS
if: ${{ matrix.package != 'solidity-devops' }}
uses: ./.github/actions/setup-nodejs
- name: Install Foundry
if: ${{ matrix.package != 'solidity-devops' }}
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
# This will run https://book.getfoundry.sh/reference/forge/forge-build#build-options
- name: Run forge build --sizes
if: ${{ matrix.package != 'solidity-devops' }}
run: |
forge build --sizes
working-directory: './packages/${{matrix.package}}'