-
Notifications
You must be signed in to change notification settings - Fork 59
198 lines (167 loc) · 5.59 KB
/
ci-code-review-rust.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
name: Code Review - Rust
on:
push:
paths:
[
'bin/cli/**',
'client/**',
'programs/**',
'bin/keeper/**',
'lib/**',
'bin/liquidator/**',
'bin/settle-bot/**',
'anchor/cli/**',
'Cargo.lock',
]
pull_request:
branches: ['main', 'dev']
paths:
[
'bin/cli/**',
'client/**',
'programs/**',
'bin/keeper/**',
'lib/**',
'bin/liquidator/**',
'bin/settle-bot/**',
'anchor/cli/**',
'Cargo.lock',
]
workflow_dispatch: # Pick branch manually
env:
CARGO_TERM_COLOR: always
SOLANA_VERSION: '1.16.14'
RUST_TOOLCHAIN: '1.69.0'
LOG_PROGRAM: '4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg'
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout submodules
run: git submodule update --init
- name: Set Rust version
run: rustup toolchain install ${{ env.RUST_TOOLCHAIN }} --component rustfmt
- name: Run fmt
run: cargo fmt -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout submodules
run: git submodule update --init
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Set Rust version
run: rustup toolchain install ${{ env.RUST_TOOLCHAIN }} --component clippy
- name: Run clippy
# The --allow args are due to clippy scanning anchor
run: cargo clippy --workspace --exclude anchor-\* --exclude fixed --exclude checked_math --features enable-gpl -- --no-deps --deny=warnings --allow=clippy::style --allow=clippy::complexity --allow=clippy::manual-retain --allow=clippy::crate-in-macro-def --allow=clippy::result-large-err --allow=clippy::derive_partial_eq_without_eq
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout submodules
run: git submodule update --init
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Set Rust version
run: rustup toolchain install ${{ env.RUST_TOOLCHAIN }}
- name: Install Solana
run: |
sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_VERSION }}/install)"
echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
solana --version
echo "Generating keypair..."
solana-keygen new -o "$HOME/.config/solana/id.json" --no-passphrase --silent
- name: Build all deps
run: |
cargo build-sbf --features enable-gpl || true
cargo +solana build-sbf --features enable-gpl
# Run sbf tests and output to runner and log
- name: Run sbf tests
run: cargo +solana test-sbf --features enable-gpl 2> >(tee raw-test-sbf.log >&2)
- name: Save raw log
uses: actions/upload-artifact@v3
with:
name: raw-test-sbf
path: raw-test-sbf.log
idl:
name: IDL Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
path: main
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Check
run: yarn ts-node ts/client/scripts/idl-compare.ts main/mango_v4.json mango_v4.json
sca:
name: Dependency Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# Fail the job on critical vulnerabiliies with fix available
- name: Fail on critical vulnerabilities
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: 'Cargo.lock'
ignore-unfixed: true
hide-progress: true
format: 'table'
severity: 'CRITICAL'
exit-code: '1'
# Download logs and process them
process-logs:
name: Process logs
runs-on: ubuntu-latest
needs: ['test']
steps:
- name: Download raw log
uses: actions/download-artifact@v3
with:
name: raw-test-sbf
- name: Install deps
run: |
sudo apt-get install ripgrep
curl -Lo xsv.tar.gz "https://github.com/BurntSushi/xsv/releases/latest/download/xsv-0.13.0-x86_64-unknown-linux-musl.tar.gz"
sudo tar xf xsv.tar.gz -C /usr/local/bin
- name: Setup date input
id: date
run: echo "::set-output name=today::$(date +'%Y-%m-%d')"
- name: Process raw log
run: |
rg -oNI "(Instruction: |Program ${{ env.LOG_PROGRAM }} consumed).*$" raw-test-sbf.log \
| rg -U 'Instruction:.*\nProgram ${{ env.LOG_PROGRAM }}.*' \
| awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }' \
| sort | uniq -u | sort > cu-per-ix.log
- name: Clean up log
run: |
rg -N 'Instruction: (\w+) .* consumed (\d+) .*' cu-per-ix.log -r '${{ steps.date.outputs.today }},$1,$2' \
| uniq | xsv sort -s 2 -N -R \
| sort -t ',' -k 2,3 -u \
| sort > cu-per-ix-clean.log
- name: Save clean log
uses: actions/upload-artifact@v3
with:
name: cu-per-ix-clean
path: cu-per-ix-clean.log