Skip to content

Commit 9282a87

Browse files
authored
Unify lint CI job (#7505)
* use `prek` for unified linting * Fix actionlint error * Generate metadata when specific files change * `check_redundant_patches.py` to accept glob path * Test * revert defective changes * use `rustfmt` over `cargo fmt` for individual files * debug reviewdog * rustfmt * Move comment to correct location * defevtive fmt test * Fail with reviewdog * fix reviewdog perms * Try to use present token * without checks oerms * put normal perms * fmt
1 parent 7a6dbd6 commit 9282a87

File tree

6 files changed

+174
-151
lines changed

6 files changed

+174
-151
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,9 @@ updates:
159159
semver-major-days: 30
160160
semver-minor-days: 7
161161
semver-patch-days: 3
162+
- package-ecosystem: pre-commit
163+
directory: /
164+
schedule:
165+
interval: weekly
166+
cooldown:
167+
default-days: 7

.github/workflows/ci.yaml

Lines changed: 47 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ jobs:
6666
- name: check compilation without threading
6767
run: cargo check ${{ env.CARGO_ARGS }}
6868

69+
- run: cargo doc --locked
70+
if: runner.os == 'Linux'
71+
6972
- name: check compilation without host_env (sandbox mode)
7073
run: |
7174
cargo check -p rustpython-vm --no-default-features --features compiler
@@ -326,8 +329,13 @@ jobs:
326329
run: python -I scripts/whats_left.py ${{ env.CARGO_ARGS }} --features jit
327330

328331
lint:
329-
name: Lint Rust & Python code
332+
name: Lint
330333
runs-on: ubuntu-latest
334+
permissions:
335+
contents: read
336+
checks: write
337+
pull-requests: write
338+
security-events: write # for zizmor
331339
steps:
332340
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
333341
with:
@@ -337,53 +345,52 @@ jobs:
337345
with:
338346
python-version: ${{ env.PYTHON_VERSION }}
339347

340-
- name: Check for redundant test patches
341-
run: python scripts/check_redundant_patches.py
342-
343348
- uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9
344349
with:
345-
components: clippy
346350
toolchain: stable
351+
components: rustfmt
347352

348-
- name: run clippy on wasm
349-
run: cargo clippy --manifest-path=crates/wasm/Cargo.toml -- -Dwarnings
350-
351-
- name: Ensure docs generate no warnings
352-
run: cargo doc --locked
353+
- uses: cargo-bins/cargo-binstall@113a77a4ce971c41332f2129c3d995df993cf746 # v1.17.8
353354

354-
- name: Ensure Lib/_opcode_metadata is updated
355+
- name: cargo shear
355356
run: |
356-
python scripts/generate_opcode_metadata.py
357-
if [ -n "$(git status --porcelain)" ]; then
358-
exit 1
359-
fi
357+
cargo binstall --no-confirm cargo-shear
358+
cargo shear
360359
361-
- name: Install ruff
362-
uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3.6.1
363-
with:
364-
version: "0.15.5"
365-
args: "--version"
360+
- name: actionlint
361+
uses: reviewdog/action-actionlint@0d952c597ef8459f634d7145b0b044a9699e5e43 # v1.71.0
366362

367-
- run: ruff check --diff
363+
- name: zizmor
364+
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
368365

369-
- run: ruff format --check
366+
- name: restore prek cache
367+
if: ${{ github.ref != 'refs/heads/main' }} # never restore on main
368+
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
369+
with:
370+
key: prek-${{ hashFiles('.pre-commit-config.yaml') }}
371+
path: ~/.cache/prek
370372

371-
- name: install prettier
372-
run: |
373-
yarn global add prettier
374-
yarn global bin >> "$GITHUB_PATH"
373+
- name: prek
374+
id: prek
375+
uses: j178/prek-action@79f765515bd648eb4d6bb1b17277b7cb22cb6468 # v2.0.0
376+
with:
377+
cache: false
378+
show-verbose-logs: false
379+
continue-on-error: true
375380

376-
- name: check wasm code with prettier
377-
# prettier doesn't handle ignore files very well: https://github.com/prettier/prettier/issues/8506
378-
run: cd wasm && git ls-files -z | xargs -0 prettier --check -u
379-
# Keep cspell check as the last step. This is optional test.
380-
- name: install extra dictionaries
381-
run: npm install @cspell/dict-en_us @cspell/dict-cpp @cspell/dict-python @cspell/dict-rust @cspell/dict-win32 @cspell/dict-shell
382-
- name: spell checker
383-
uses: streetsidesoftware/cspell-action@v8
381+
- name: save prek cache
382+
if: ${{ github.ref == 'refs/heads/main' }} # only save on main
383+
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
384384
with:
385-
files: "**/*.rs"
386-
incremental_files_only: true
385+
key: prek-${{ hashFiles('.pre-commit-config.yaml') }}
386+
path: ~/.cache/prek
387+
388+
- name: reviewdog
389+
uses: reviewdog/action-suggester@aa38384ceb608d00f84b4690cacc83a5aba307ff # 1.24.0
390+
with:
391+
level: warning
392+
fail_level: error
393+
cleanup: false
387394

388395
miri:
389396
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
@@ -425,12 +432,16 @@ jobs:
425432

426433
- uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9
427434
with:
435+
components: clippy
428436
toolchain: stable
429437

430438
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
431439
with:
432440
save-if: ${{ github.ref == 'refs/heads/main' }}
433441

442+
- name: cargo clippy
443+
run: cargo clippy --manifest-path=crates/wasm/Cargo.toml -- -Dwarnings
444+
434445
- name: install wasm-pack
435446
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
436447
- name: install geckodriver
@@ -520,29 +531,3 @@ jobs:
520531
run: wasmer run --dir "$(pwd)" target/wasm32-wasip1/release/rustpython.wasm -- "$(pwd)/extra_tests/snippets/stdlib_random.py"
521532
- name: run cpython unittest
522533
run: wasmer run --dir "$(pwd)" target/wasm32-wasip1/release/rustpython.wasm -- "$(pwd)/Lib/test/test_int.py"
523-
524-
cargo-shear:
525-
name: cargo shear
526-
runs-on: ubuntu-latest
527-
steps:
528-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
529-
with:
530-
persist-credentials: false
531-
532-
- uses: cargo-bins/cargo-binstall@113a77a4ce971c41332f2129c3d995df993cf746 # v1.17.8
533-
534-
- run: cargo binstall --no-confirm cargo-shear
535-
536-
- run: cargo shear
537-
538-
security-lint:
539-
runs-on: ubuntu-latest
540-
permissions:
541-
security-events: write
542-
steps:
543-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
544-
with:
545-
persist-credentials: false
546-
547-
- name: Run zizmor
548-
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2

.github/workflows/pr-format.yaml

Lines changed: 0 additions & 74 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# NOTE: Reason for not using `prek.toml` is dependabot supports `pre-commit` as an ecosystem
2+
# See: https://github.blog/changelog/2026-03-10-dependabot-now-supports-pre-commit-hooks/
3+
4+
fail_fast: false
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v6.0.0
8+
hooks:
9+
- id: check-merge-conflict
10+
priority: 0
11+
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.15.7
14+
hooks:
15+
- id: ruff-format
16+
priority: 0
17+
18+
- id: ruff-check
19+
args: [--select, I, --fix, --exit-non-zero-on-fix]
20+
types_or: [python]
21+
require_serial: true
22+
priority: 1
23+
24+
- repo: local
25+
hooks:
26+
- id: redundant-test-patches
27+
name: check redundant test patches
28+
entry: scripts/check_redundant_patches.py
29+
files: '^Lib/test/.*\.py$'
30+
language: script
31+
types: [python]
32+
priority: 0
33+
34+
- repo: local
35+
hooks:
36+
- id: rustfmt
37+
name: rustfmt
38+
entry: rustfmt
39+
language: system
40+
types: [rust]
41+
priority: 0
42+
43+
- id: generate-opcode-metadata
44+
name: generate opcode metadata
45+
entry: python scripts/generate_opcode_metadata.py
46+
files: '^(crates/compiler-core/src/bytecode/instruction\.rs|scripts/generate_opcode_metadata\.py)$'
47+
pass_filenames: false
48+
language: system
49+
require_serial: true
50+
priority: 1 # so rustfmt runs first
51+
52+
- repo: https://github.com/streetsidesoftware/cspell-cli
53+
rev: v9.7.0
54+
hooks:
55+
- id: cspell
56+
types: [rust]
57+
additional_dependencies:
58+
- '@cspell/dict-en_us'
59+
- '@cspell/dict-cpp'
60+
- '@cspell/dict-python'
61+
- '@cspell/dict-rust'
62+
- '@cspell/dict-win32'
63+
- '@cspell/dict-shell'
64+
priority: 0
65+
66+
- repo: https://github.com/rbubley/mirrors-prettier
67+
rev: v3.8.1
68+
hooks:
69+
- id: prettier
70+
files: '^wasm/.*$'
71+
priority: 0

example_projects/wasm32_without_js/rustpython-without-js/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustpython_vm::{Interpreter};
1+
use rustpython_vm::Interpreter;
22

33
unsafe extern "C" {
44
fn kv_get(kp: i32, kl: i32, vp: i32, vl: i32) -> i32;
@@ -37,12 +37,7 @@ pub unsafe extern "C" fn eval(s: *const u8, l: usize) -> i32 {
3737

3838
let msg = format!("eval result: {result}");
3939

40-
unsafe {
41-
print(
42-
msg.as_str().as_ptr() as usize as i32,
43-
msg.len() as i32,
44-
)
45-
};
40+
unsafe { print(msg.as_str().as_ptr() as usize as i32, msg.len() as i32) };
4641

4742
0
4843
}

0 commit comments

Comments
 (0)