Skip to content

Commit 7352740

Browse files
authored
ci: Add pre-commit (#201)
* Add pre-commit infrastructure * Remove all steps in `rust.yml` which are now covered by `pre-commit` * Fix `trailing-whitespace` checks * Fix `end-of-file-fixer` checks * Fix `check-executables-have-shebangs` checks * Fix `check-shebang-scripts-are-executable` checks * Fix actionlint * Fix `typos` checks * Fix `clippy-workspace` checks * Fix `verify-ffi-docs` * Revert intentional typo fix for testing * Remove the redundant format/linting section in `CONTRIBUTING.md` * Change `id` from `clippy-workspace` to `clippy` * Fix `verify FFI` stage
1 parent 4e9ef04 commit 7352740

File tree

237 files changed

+3033
-3014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+3033
-3014
lines changed

.github/workflows/pre-commit.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Pre-commit Checks
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'v**-dev'
8+
pull_request:
9+
10+
jobs:
11+
pre-commit:
12+
name: Pre-commit (${{ matrix.os }})
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
# TODO: Windows excluded - rs-x11-hash requires POSIX headers (unistd.h)
18+
os: [ubuntu-latest, macos-latest]
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v5
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v6
25+
with:
26+
python-version: "3.x"
27+
28+
- name: Setup Rust toolchain
29+
uses: dtolnay/rust-toolchain@stable
30+
with:
31+
components: rustfmt, clippy
32+
33+
- name: Cache cargo dependencies
34+
uses: Swatinem/rust-cache@v2
35+
with:
36+
shared-key: "rust-cache-${{ matrix.os }}"
37+
38+
- name: Run pre-commit
39+
uses: pre-commit/[email protected]
40+
with:
41+
extra_args: --all-files --hook-stage push --verbose

.github/workflows/rust.yml

Lines changed: 1 addition & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
# Run test in isolation, single-threaded to improve determinism
7474
cargo test -p dash-spv --all-features -- --nocapture --test-threads=1 "$t" 2>&1 | tee -a segv_scan.log
7575
rc=${PIPESTATUS[0]}
76-
if [ $rc -ne 0 ]; then
76+
if [ "$rc" -ne 0 ]; then
7777
if tail -n 200 segv_scan.log | grep -qE 'SIGSEGV|signal: 11'; then
7878
FOUND_THIS_ATTEMPT+=("$t")
7979
SEGV_TESTS+=("$t")
@@ -176,139 +176,6 @@ jobs:
176176
- name: Run script-based tests
177177
run: ./contrib/test.sh
178178

179-
clippy:
180-
name: Clippy (Non-strict)
181-
runs-on: ubuntu-22.04-arm
182-
steps:
183-
- name: Checkout Crate
184-
uses: actions/checkout@v4
185-
- name: Setup Rust toolchain
186-
uses: dtolnay/rust-toolchain@stable
187-
with:
188-
components: clippy
189-
- name: Run clippy (excluding strict-checked crates)
190-
run: |
191-
# Auto-discover all workspace crates and exclude strict-checked ones
192-
STRICT_CRATES=("key-wallet" "key-wallet-manager" "key-wallet-ffi" "dashcore_hashes" "dashcore" "dash-spv" "dash-spv-ffi")
193-
mapfile -t ALL_CRATES < <(cargo metadata --no-deps --format-version=1 | jq -r '.packages[].name' | sort -u)
194-
for crate in "${ALL_CRATES[@]}"; do
195-
if printf '%s\n' "${STRICT_CRATES[@]}" | grep -qx "$crate"; then
196-
continue
197-
fi
198-
echo "Checking $crate (warnings allowed, errors will fail)..."
199-
cargo clippy -p "$crate" --all-features --all-targets -- -W warnings
200-
done
201-
202-
strict-checks:
203-
name: Strict Warnings and Clippy Checks
204-
runs-on: ubuntu-22.04-arm
205-
steps:
206-
- name: Checkout Crate
207-
uses: actions/checkout@v4
208-
- name: Setup Rust toolchain
209-
uses: dtolnay/rust-toolchain@stable
210-
with:
211-
components: clippy
212-
- name: Cache cargo dependencies
213-
uses: Swatinem/rust-cache@v2
214-
215-
# Check key-wallet with strict warnings
216-
- name: Check key-wallet (deny warnings)
217-
env:
218-
RUSTFLAGS: "-D warnings"
219-
run: |
220-
cargo check -p key-wallet --all-features --lib --bins --tests
221-
cargo build -p key-wallet --all-features --lib --bins
222-
cargo test -p key-wallet --all-features --lib --bins
223-
224-
- name: Clippy key-wallet (deny all warnings)
225-
run: cargo clippy -p key-wallet --all-features --lib --bins --tests -- -D warnings
226-
227-
# Check key-wallet-manager with strict warnings
228-
- name: Check key-wallet-manager (deny warnings)
229-
env:
230-
RUSTFLAGS: "-D warnings"
231-
run: |
232-
cargo check -p key-wallet-manager --all-features --lib --bins --tests
233-
cargo build -p key-wallet-manager --all-features --lib --bins
234-
cargo test -p key-wallet-manager --all-features --lib --bins
235-
236-
- name: Clippy key-wallet-manager (deny all warnings)
237-
run: cargo clippy -p key-wallet-manager --all-features --lib --bins --tests -- -D warnings
238-
239-
# Check key-wallet-ffi with strict warnings
240-
- name: Check key-wallet-ffi (deny warnings)
241-
env:
242-
RUSTFLAGS: "-D warnings"
243-
run: |
244-
cargo check -p key-wallet-ffi --all-features --lib --bins --tests
245-
cargo build -p key-wallet-ffi --all-features --lib --bins
246-
cargo test -p key-wallet-ffi --all-features --lib --bins
247-
248-
- name: Clippy key-wallet-ffi (deny all warnings)
249-
run: cargo clippy -p key-wallet-ffi --all-features --lib --bins --tests -- -D warnings
250-
251-
# Check dashcore with strict warnings
252-
- name: Check dashcore (deny warnings)
253-
env:
254-
RUSTFLAGS: "-D warnings"
255-
run: |
256-
cargo check -p dashcore --all-features --lib --bins --tests
257-
cargo build -p dashcore --all-features --lib --bins
258-
cargo test -p dashcore --all-features --lib --bins
259-
260-
- name: Clippy dashcore (deny all warnings)
261-
run: cargo clippy -p dashcore --all-features --lib --bins --tests -- -D warnings
262-
263-
# Check dashcore_hashes with strict warnings
264-
- name: Check dashcore_hashes (deny warnings)
265-
env:
266-
RUSTFLAGS: "-D warnings"
267-
run: |
268-
cargo check -p dashcore_hashes --all-features --lib --bins --tests
269-
cargo build -p dashcore_hashes --all-features --lib --bins
270-
cargo test -p dashcore_hashes --all-features --lib --bins
271-
272-
- name: Clippy dashcore_hashes (deny all warnings)
273-
run: cargo clippy -p dashcore_hashes --all-features --lib --bins --tests -- -D warnings
274-
275-
# Check dash-spv with strict warnings
276-
- name: Check dash-spv (deny warnings)
277-
env:
278-
RUSTFLAGS: "-D warnings"
279-
run: |
280-
cargo check -p dash-spv --all-features --lib --bins --tests
281-
cargo build -p dash-spv --all-features --lib --bins
282-
cargo test -p dash-spv --all-features --lib --bins
283-
284-
- name: Clippy dash-spv (deny all warnings)
285-
run: cargo clippy -p dash-spv --all-features --lib --bins --tests -- -D warnings
286-
287-
# Check dash-spv-ffi with strict warnings
288-
- name: Check dash-spv-ffi (deny warnings)
289-
env:
290-
RUSTFLAGS: "-D warnings"
291-
run: |
292-
cargo check -p dash-spv-ffi --all-features --lib --bins --tests
293-
cargo build -p dash-spv-ffi --all-features --lib --bins
294-
cargo test -p dash-spv-ffi --all-features --lib --bins
295-
296-
- name: Clippy dash-spv-ffi (deny all warnings)
297-
run: cargo clippy -p dash-spv-ffi --all-features --lib --bins --tests -- -D warnings
298-
299-
fmt:
300-
name: Format
301-
runs-on: ubuntu-22.04-arm
302-
steps:
303-
- name: Checkout Crate
304-
uses: actions/checkout@v4
305-
- name: Setup Rust toolchain
306-
uses: dtolnay/rust-toolchain@stable
307-
with:
308-
components: rustfmt
309-
- name: Check formatting
310-
run: cargo fmt --all -- --check
311-
312179
rpc_tests:
313180
name: RPC Tests
314181
runs-on: ubuntu-22.04-arm
@@ -344,16 +211,3 @@ jobs:
344211
env:
345212
DASHVERSION: ${{ matrix.dashversion }}
346213
run: ./contrib/test-rpc.sh
347-
348-
actionlint:
349-
name: Lint GitHub Actions
350-
runs-on: ubuntu-22.04-arm
351-
permissions:
352-
contents: read
353-
steps:
354-
- name: Checkout Crate
355-
uses: actions/checkout@v4
356-
- name: Run actionlint
357-
uses: reviewdog/action-actionlint@v1
358-
with:
359-
fail_on_error: true

.github/workflows/verify-ffi-docs.yml

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

0 commit comments

Comments
 (0)