fix(ci): require OpenGrep SARIF artifacts

This commit is contained in:
Vincent Koc
2026-06-23 14:08:20 +08:00
committed by GitHub
parent a13e2b92b3
commit 0fed6402be
6 changed files with 111 additions and 3 deletions

View File

@@ -61,11 +61,13 @@ PATHS_PASSED=0
SAW_DOUBLE_DASH=0
CHANGED_ONLY=0
FAIL_ON_FINDINGS=0
SARIF_OUTPUT=""
while (( $# > 0 )); do
case "$1" in
--sarif)
mkdir -p "$REPO_ROOT/.opengrep-out"
EXTRA_ARGS+=( "--sarif-output=$REPO_ROOT/.opengrep-out/$BUCKET.sarif" )
SARIF_OUTPUT="$REPO_ROOT/.opengrep-out/$BUCKET.sarif"
EXTRA_ARGS+=( "--sarif-output=$SARIF_OUTPUT" )
shift
;;
--json)
@@ -102,6 +104,31 @@ while (( $# > 0 )); do
esac
done
write_empty_sarif() {
local output="$1"
mkdir -p "$(dirname "$output")"
cat > "$output" <<'JSON'
{
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Opengrep OSS",
"informationUri": "https://opengrep.dev",
"semanticVersion": "1.22.0",
"rules": []
}
},
"results": []
}
]
}
JSON
}
cd "$REPO_ROOT"
if (( CHANGED_ONLY && PATHS_PASSED )); then
@@ -181,6 +208,9 @@ if (( PATHS_PASSED == 0 )); then
fi
if (( ${#SCAN_PATHS[@]} == 0 )); then
echo "→ No changed first-party paths for opengrep." >&2
if [[ -n "$SARIF_OUTPUT" ]]; then
write_empty_sarif "$SARIF_OUTPUT"
fi
exit 0
fi
else