Skip to content

Commit a9c66ad

Browse files
committed
Enhance Semgrep CI workflow to conditionally run scans based on SEMGREP_APP_TOKEN presence. This update improves error handling and ensures appropriate scanning configurations are applied, enhancing the overall reliability of the CI process.
1 parent 434e344 commit a9c66ad

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

.github/workflows/semgrep.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,22 @@ jobs:
3030
- name: Semgrep CI (Docker)
3131
run: |
3232
mkdir -p reports
33-
docker run --rm \
34-
-e SEMGREP_APP_TOKEN \
35-
-v "$PWD:/src" \
36-
-w /src \
37-
semgrep/semgrep:latest \
38-
semgrep ci --sarif --sarif-output=reports/semgrep.sarif
33+
if [ -n "${SEMGREP_APP_TOKEN:-}" ]; then
34+
echo "Running semgrep ci with Semgrep AppSec Platform token"
35+
docker run --rm \
36+
-e SEMGREP_APP_TOKEN \
37+
-v "$PWD:/src" \
38+
-w /src \
39+
semgrep/semgrep:latest \
40+
semgrep ci --sarif --sarif-output=reports/semgrep.sarif --no-suppress-errors
41+
else
42+
echo "SEMGREP_APP_TOKEN not set; running semgrep scan with p/ci rules"
43+
docker run --rm \
44+
-v "$PWD:/src" \
45+
-w /src \
46+
semgrep/semgrep:latest \
47+
semgrep scan --config p/ci --sarif --sarif-output=reports/semgrep.sarif --error
48+
fi
3949
env:
4050
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
4151

0 commit comments

Comments
 (0)