Skip to content

Commit 448f979

Browse files
committed
bandit: generate SARIF
1 parent 2234707 commit 448f979

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

.github/workflows/security.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
permissions:
1414
contents: read
15-
security-events: write # needed for SARIF upload
15+
security-events: write
1616
steps:
1717
- uses: actions/checkout@v4
1818

@@ -21,25 +21,22 @@ jobs:
2121
python-version: '3.11'
2222

2323
- name: Install Bandit
24-
run: python -m pip install --upgrade pip bandit
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install --upgrade bandit
2527
26-
# Full report for triage (non-blocking), goes to the Security tab
28+
# Non-blocking SARIF for the Security tab
2729
- name: Bandit SARIF (non-blocking)
2830
run: |
29-
bandit -r . \
31+
bandit -q -r . \
3032
-x tests,venv,.venv,build,dist,__pycache__,.github \
31-
-f sarif -o bandit.sarif
33+
-f sarif -o bandit.sarif || true
34+
# If bandit didn't produce valid output, delete the file so we skip upload
35+
[ -s bandit.sarif ] || rm -f bandit.sarif
3236
continue-on-error: true
3337

34-
- name: Check SARIF file exists
35-
run: |
36-
if [ ! -f bandit.sarif ]; then
37-
echo "bandit.sarif not found!"
38-
echo "{}" > bandit.sarif
39-
fi
40-
4138
- name: Upload SARIF to code scanning
42-
if: always()
39+
if: always() && hashFiles('bandit.sarif') != ''
4340
uses: github/codeql-action/upload-sarif@v3
4441
with:
4542
sarif_file: bandit.sarif

0 commit comments

Comments
 (0)