Repository navigation
99 lines (83 loc) · 2.92 KB
/
Copy pathsecurity.yml
File metadata and controls
99 lines (83 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Security Analysis
on:
push:
branches:
- main
- master
pull_request:
workflow_dispatch:
schedule:
- cron: "21 3 * * 1"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
SEMGREP_VERSION: "1.163.0"
permissions:
actions: read
contents: read
security-events: write
jobs:
semgrep:
name: Semgrep CE
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
contents: read
pull-requests: read
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v7 # v5
- name: Cache Semgrep pip packages
uses: actions/cache@v6 # v4
with:
path: ~/.cache/pip
key: semgrep-pip-${{ runner.os }}-${{ env.SEMGREP_VERSION }}
- name: Install Semgrep
run: python -m pip install "semgrep==${SEMGREP_VERSION}"
- name: Run Semgrep
run: semgrep scan --config=auto --sarif --output=semgrep.sarif .
- name: Validate Semgrep SARIF
run: |
python - <<'PY'
import json
from pathlib import Path
path = Path("semgrep.sarif")
if not path.is_file() or path.stat().st_size == 0:
raise SystemExit("semgrep.sarif was not created or is empty")
with path.open(encoding="utf-8") as handle:
payload = json.load(handle)
if payload.get("version") != "2.1.0" or not isinstance(payload.get("runs"), list):
raise SystemExit("semgrep.sarif is not a valid SARIF 2.1.0 payload")
PY
- name: Setup reviewdog
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
uses: reviewdog/action-setup@v1 # v1.5.0
with:
reviewdog_version: v0.21.0
- name: Review Semgrep diagnostics
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat semgrep.sarif | reviewdog \
-name=semgrep \
-f=sarif \
-reporter=github-pr-check \
-filter-mode=diff_context \
-level=warning || echo "reviewdog semgrep report failed" >&2
- name: Upload Semgrep SARIF artifact
uses: actions/upload-artifact@v7 # v7
with:
name: semgrep-sarif
path: semgrep.sarif
if-no-files-found: error
- name: Upload Semgrep SARIF to code scanning
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: github/codeql-action/upload-sarif@v4 # v4
with:
sarif_file: semgrep.sarif
category: semgrep
continue-on-error: true