1
1
name : PR CI and Merge Restrictions
2
-
3
2
on :
4
3
pull_request :
5
- branches :
6
- - main
4
+ branches : [main]
5
+ # Add paths-ignore to skip CI for docs-only changes
6
+ paths-ignore :
7
+ - ' **.md'
8
+ - ' docs/**'
9
+ - ' LICENSE'
10
+
11
+ # Add concurrency to cancel outdated runs
12
+ concurrency :
13
+ group : ${{ github.workflow }}-${{ github.ref }}
14
+ cancel-in-progress : true
7
15
8
16
jobs :
9
17
pr_ci_checks :
10
18
name : PR Checks
11
19
runs-on : ubuntu-latest
12
-
13
20
steps :
14
- # Step 1: Checkout Code
15
21
- name : Checkout Code
16
22
uses : actions/checkout@v4
23
+ with :
24
+ fetch-depth : 0 # Needed for proper commit linting
17
25
18
- # Step 2: Restrict Source Branch
19
26
- name : Check Source Branch
20
27
if : " !startsWith(github.head_ref, 'feature/') && !startsWith(github.head_ref, 'release-please--')"
21
28
run : |
22
29
echo "❌ Pull requests to main must come from feature/* or release-please-- branches."
23
30
exit 1
24
31
25
- # Step 3: Lint Commit Messages
26
32
- name : Lint Commit Messages
27
33
uses : wagoid/commitlint-github-action@v6
28
34
29
- # Step 4: Cache Cargo Dependencies
30
- - name : Cache Cargo Registry
35
+ # Combine both cache steps into one for better efficiency
36
+ - name : Cache Rust Dependencies
31
37
uses : actions/cache@v3
32
38
with :
33
- path : ~/.cargo/registry
34
- key : ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
39
+ path : |
40
+ ~/.cargo/registry
41
+ ~/.cargo/git
42
+ target
43
+ key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
35
44
restore-keys : |
36
- ${{ runner.os }}-cargo-registry-
45
+ ${{ runner.os }}-cargo-
37
46
38
- - name : Cache Cargo Build
39
- uses : actions/cache@v3
40
- with :
41
- path : target
42
- key : ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
43
- restore-keys : |
44
- ${{ runner.os }}-cargo-build-
45
-
46
- # Step 5: Set up Rust Toolchain
47
47
- name : Set up Rust
48
48
uses : dtolnay/rust-toolchain@stable
49
+ with :
50
+ components : clippy, rustfmt
49
51
50
- # Step 6: Run Clippy
51
- - name : Run Clippy
52
+ # Combine security tools installation
53
+ - name : Install Security Tools
52
54
run : |
55
+ cargo install cargo-audit cargo-deny --locked
56
+
57
+ # Group formatting and linting checks
58
+ - name : Code Quality Checks
59
+ run : |
60
+ cargo fmt -- --check
53
61
cargo clippy --all-targets --all-features -- -D warnings
54
62
55
- # Step 7: Run Tests
63
+ # Run tests with coverage
56
64
- name : Run Tests
57
- run : cargo test --all-features
58
-
59
- # Step 8: Check Formatting
60
- - name : Check Formatting
61
- run : cargo fmt -- --check
62
-
63
- # Step 9: Run Cargo Audit (Security Checks)
64
- - name : Run Cargo Audit
65
65
run : |
66
- cargo install cargo-audit
67
- cargo audit
66
+ cargo install cargo-tarpaulin
67
+ cargo tarpaulin --out Xml
68
68
69
- # Step 10: Run Cargo Deny (Dependency Checks)
70
- - name : Run Cargo Deny
69
+ # Add test coverage reporting
70
+ - name : Upload Coverage
71
+ uses : codecov/codecov-action@v3
72
+ if : always() # Run even if tests fail
73
+
74
+ # Group security checks
75
+ - name : Security Audit
71
76
run : |
72
- cargo install cargo-deny
77
+ cargo audit --stale
73
78
cargo deny check
79
+
80
+ # Add caching for installed tools
81
+ - name : Cache Tools
82
+ uses : actions/cache@v3
83
+ with :
84
+ path : |
85
+ ~/.cargo/bin/cargo-audit
86
+ ~/.cargo/bin/cargo-deny
87
+ ~/.cargo/bin/cargo-tarpaulin
88
+ key : ${{ runner.os }}-cargo-tools-${{ hashFiles('**/Cargo.lock') }}
0 commit comments