Skip to content

Commit 23a7323

Browse files
committed
ci: security workflow improvements
1 parent 32cb0e2 commit 23a7323

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

.github/workflows/security.yml

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,46 @@ name: Security
55
on:
66
pull_request:
77
branches: [main]
8-
paths:
9-
- "Cargo.toml"
10-
- "Cargo.lock"
11-
- "**/Cargo.toml"
12-
- ".github/workflows/security.yml"
138

149
permissions:
1510
contents: read
1611
pull-requests: write
1712

1813
jobs:
14+
# Detect if security-relevant files changed
15+
detect-changes:
16+
name: Detect Changes
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
outputs:
21+
cargo: ${{ steps.filter.outputs.cargo }}
22+
steps:
23+
- name: Harden the runner (Audit all outbound calls)
24+
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
25+
with:
26+
egress-policy: audit
27+
28+
- name: Checkout code
29+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
30+
31+
- name: Check for dependency changes
32+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
33+
id: filter
34+
with:
35+
filters: |
36+
cargo:
37+
- 'Cargo.toml'
38+
- 'Cargo.lock'
39+
- '**/Cargo.toml'
40+
- '.github/workflows/security.yml'
41+
1942
dependency-review:
2043
name: Dependency Review
44+
needs: [detect-changes]
2145
runs-on: ubuntu-latest
22-
if: github.actor != 'dependabot[bot]'
46+
# Only run if Cargo files changed AND not triggered by dependabot
47+
if: needs.detect-changes.outputs.cargo == 'true' && github.actor != 'dependabot[bot]'
2348
permissions:
2449
contents: read
2550
pull-requests: write
@@ -39,9 +64,10 @@ jobs:
3964
comment-summary-in-pr: always
4065

4166
# Security scan summary - aggregates all security job results
67+
# This job ALWAYS runs to satisfy required status checks
4268
security-summary:
4369
name: Security Summary
44-
needs: [dependency-review]
70+
needs: [detect-changes, dependency-review]
4571
runs-on: ubuntu-latest
4672
if: always()
4773
permissions:
@@ -54,10 +80,20 @@ jobs:
5480

5581
- name: Check security scan results
5682
env:
83+
CARGO_CHANGES: ${{ needs.detect-changes.outputs.cargo }}
5784
DEPENDENCY_REVIEW_RESULT: ${{ needs.dependency-review.result }}
5885
run: |
5986
echo "## Security Scan Results"
6087
echo ""
88+
89+
# If no security-relevant files changed, report success immediately
90+
if [[ "$CARGO_CHANGES" != "true" ]]; then
91+
echo "No Cargo dependency changes detected - security scan not required."
92+
echo ""
93+
echo "✅ Security checks passed (no relevant changes)"
94+
exit 0
95+
fi
96+
6197
echo "| Scanner | Status |"
6298
echo "|---------|--------|"
6399
echo "| Dependency Review | $DEPENDENCY_REVIEW_RESULT |"

0 commit comments

Comments
 (0)