Debian Codegraph @

.github/workflows/code-quality.yml

raw
1 name: Code Quality
2
3 # spell-checker:ignore (people) juliangruber pell reactivecircus taiki-e taplo
4 # spell-checker:ignore (misc) TERMUX noaudio pkill swiftshader esac sccache pcoreutils shopt subshell dequote libsystemd wasi wasip
5
6 on:
7 pull_request:
8 push:
9 branches:
10 - '*'
11
12 env:
13 CARGO_INCREMENTAL: "0"
14 # * style job configuration
15 STYLE_FAIL_ON_FAULT: true ## (bool) fail the build if a style job contains a fault (error or warning); may be overridden on a per-job basis
16
17 permissions:
18 contents: read # to fetch code (actions/checkout)
19
20 # End the current execution if there is a new changeset in the PR.
21 concurrency:
22 group: ${{ github.workflow }}-${{ github.ref }}
23 cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
24
25 jobs:
26
27 style_format:
28 name: Style/format
29 runs-on: ${{ matrix.job.os }}
30 strategy:
31 fail-fast: false
32 matrix:
33 job:
34 - { os: ubuntu-latest , features: feat_os_unix }
35 steps:
36 - uses: actions/[email protected]
37 with:
38 persist-credentials: false
39 - name: Initialize workflow variables
40 id: vars
41 shell: bash
42 run: |
43 ## VARs setup
44 outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
45 # failure mode
46 unset FAIL_ON_FAULT ; case "$STYLE_FAIL_ON_FAULT" in
47 ''|0|f|false|n|no|off) FAULT_TYPE=warning ;;
48 *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
49 esac;
50 outputs FAIL_ON_FAULT FAULT_TYPE
51 - name: "`cargo fmt` testing"
52 shell: bash
53 run: |
54 ## `cargo fmt` testing
55 unset fault
56 fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
57 fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
58 # * convert any errors/warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
59 S=$(cargo fmt -- --check) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s\n" "$S" | sed -E -n -e "s/^Diff[[:space:]]+in[[:space:]]+${PWD//\//\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*$/::${fault_type} file=\1,line=\2::${fault_prefix}: \`cargo fmt\`: style violation (file:'\1', line:\2; use \`cargo fmt -- \"\1\"\`)/p" ; fault=true ; }
60 if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
61 - name: "cargo fmt on fuzz dir"
62 shell: bash
63 run: |
64 cd fuzz
65 cargo fmt --check
66
67 style_lint:
68 name: Style/lint
69 runs-on: ${{ matrix.job.os }}
70 strategy:
71 fail-fast: false
72 matrix:
73 job:
74 - { os: ubuntu-latest , features: all , workspace: true }
75 - { os: macos-latest , features: all , workspace: true }
76 - { os: windows-latest , features: feat_os_windows }
77 - { os: ubuntu-latest , features: feat_wasm , target: wasm32-wasip1 }
78 - { os: ubuntu-latest , features: feat_wasm , target: wasm32-wasip2 }
79 steps:
80 - uses: actions/[email protected]
81 with:
82 persist-credentials: false
83 - uses: dtolnay/rust-toolchain@master
84 with:
85 toolchain: stable
86 components: clippy
87 targets: ${{ matrix.job.target || '' }}
88 - uses: Swatinem/rust-cache@v2
89 - name: Run sccache-cache
90 id: sccache-setup
91 uses: mozilla-actions/[email protected]
92 continue-on-error: true
93 - name: Export sccache
94 if: steps.sccache-setup.outcome == 'success'
95 run: |
96 echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
97 echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
98 - name: Initialize workflow variables
99 id: vars
100 shell: bash
101 run: |
102 ## VARs setup
103 outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
104 # failure mode
105 unset FAIL_ON_FAULT ; case "$STYLE_FAIL_ON_FAULT" in
106 ''|0|f|false|n|no|off) FAULT_TYPE=warning ;;
107 *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
108 esac;
109 outputs FAIL_ON_FAULT FAULT_TYPE
110 - name: Install/setup prerequisites
111 if: ${{ ! matrix.job.target }}
112 shell: bash
113 run: |
114 ## Install/setup prerequisites
115 case '${{ matrix.job.os }}' in
116 ubuntu-*)
117 sudo apt-get -y update
118 # selinux and systemd headers needed to enable all features
119 sudo apt-get -y install libselinux1-dev libsystemd-dev
120 ;;
121 esac
122 - name: "`cargo clippy` lint testing"
123 uses: nick-fields/retry@v4
124 with:
125 max_attempts: 3
126 retry_on: error
127 timeout_minutes: 90
128 shell: bash
129 command: |
130 ## `cargo clippy` lint testing
131 ARGS="--features ${{ matrix.job.features }}"
132 ARGS="${ARGS} --fault-type ${{ steps.vars.outputs.FAULT_TYPE }}"
133 if [[ "${{ matrix.job.workspace }}" =~ ^(1|t|true|y|yes)$ ]]; then
134 ARGS="${ARGS} --workspace"
135 fi
136 if [[ -n "${{ matrix.job.target }}" ]]; then
137 ARGS="${ARGS} --target ${{ matrix.job.target }}"
138 fi
139 if [[ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ]]; then
140 ARGS="${ARGS} --fail-on-fault"
141 fi
142 python3 util/run-clippy.py ${ARGS}
143 - name: "cargo clippy on fuzz dir"
144 if: runner.os != 'Windows' && !matrix.job.target
145 shell: bash
146 run: |
147 cd fuzz
148 cargo clippy --workspace --all-targets --all-features -- -D warnings
149
150 style_spellcheck:
151 name: Style/spelling
152 runs-on: ${{ matrix.job.os }}
153 env:
154 # Spelling is enforced locally by the cspell pre-commit hook, where it is
155 # cheap to fix. Here it is advisory: unknown words show up as annotations
156 # on the diff instead of blocking the merge.
157 STYLE_FAIL_ON_FAULT: false
158 strategy:
159 matrix:
160 job:
161 - { os: ubuntu-latest , features: feat_os_unix }
162 steps:
163 - uses: actions/[email protected]
164 with:
165 persist-credentials: false
166 - name: Initialize workflow variables
167 id: vars
168 shell: bash
169 run: |
170 ## VARs setup
171 outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; }
172 # failure mode
173 unset FAIL_ON_FAULT ; case "$STYLE_FAIL_ON_FAULT" in
174 ''|0|f|false|n|no|off) FAULT_TYPE=warning ;;
175 *) FAIL_ON_FAULT=true ; FAULT_TYPE=error ;;
176 esac;
177 outputs FAIL_ON_FAULT FAULT_TYPE
178 - name: Install/setup prerequisites
179 shell: bash
180 run: |
181 sudo npm install cspell -g ;
182 - name: Run `cspell`
183 shell: bash
184 run: |
185 ## Run `cspell`
186 unset fault
187 fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
188 fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
189 # * find cspell configuration ; note: avoid quotes around ${cfg_file} b/c `cspell` (v4) doesn't correctly dequote the config argument (or perhaps a subshell expansion issue?)
190 cfg_files=($(shopt -s nullglob ; echo {.vscode,.}/{,.}c[sS]pell{.json,.config{.js,.cjs,.json,.yaml,.yml},.yaml,.yml} ;))
191 cfg_file=${cfg_files[0]}
192 unset CSPELL_CFG_OPTION ; if [ -n "$cfg_file" ]; then CSPELL_CFG_OPTION="--config $cfg_file" ; fi
193 S=$(cspell ${CSPELL_CFG_OPTION} --no-summary --no-progress .) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n "s/^(.*):([0-9]+):([0-9]+) - Unknown word \(([^)]+)\).*$/::${fault_type} file=\1,line=\2,col=\3::${fault_type^^}: \`cspell\`: Unknown word '\4' (file:'\1', line:\2)/p" ; fault=true ; true ; }
194 if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
195
196 style_empty_assertions:
197 name: Style/Empty assertions check
198 runs-on: ubuntu-latest
199 steps:
200 - name: Checkout repository
201 uses: actions/[email protected]
202 with:
203 persist-credentials: false
204 - name: Fail if empty stdout/stderr assertions are found
205 shell: bash
206 run: |
207 if grep -rnE '(stdout_is|stderr_is)\(""\)' tests/; then
208 echo "::error::Found empty stdout/stderr assertions (use specific checks instead of \"\") in tests/"
209 exit 1
210 fi
211
212 python:
213 name: Style/Python
214 runs-on: ubuntu-latest
215 steps:
216 - name: Clone repository
217 uses: actions/[email protected]
218 with:
219 persist-credentials: false
220
221 - name: ruff
222 uses: astral-sh/[email protected]
223 with:
224 src: "./util"
225
226 - name: ruff - format
227 uses: astral-sh/[email protected]
228 with:
229 src: "./util"
230 args: format --check
231 - name: Run Python unit tests
232 shell: bash
233 run: |
234 python3 -m unittest util/test_compare_test_results.py util/test_compare_size_results.py
235
236 pre_commit:
237 name: Pre-commit hooks
238 runs-on: ubuntu-latest
239 steps:
240 - name: Checkout repository
241 uses: actions/[email protected]
242 with:
243 persist-credentials: false
244
245 - name: Cache Rust dependencies
246 uses: Swatinem/rust-cache@v2
247
248 - name: Install pre-commit
249 run: pip install pre-commit
250
251 - name: Cache pre-commit environments
252 uses: actions/cache@v6
253 with:
254 path: ~/.cache/pre-commit
255 key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
256 restore-keys: |
257 pre-commit-${{ runner.os }}-
258
259 - name: Run pre-commit
260 env:
261 # cspell is enforced locally and reported by Style/spelling; the rust
262 # hooks are already covered by the Style/format and Style/lint jobs.
263 SKIP: cspell,rust-linting,rust-clippy,cargo-lock-check
264 run: pre-commit run --all-files --show-diff-on-failure