Spaces:
Running
Running
Merge pull request #300 from saurabhhhcodes/ci/codeql-static-analysis-293
Browse files- .github/workflows/ci.yml +94 -2
.github/workflows/ci.yml
CHANGED
|
@@ -71,7 +71,99 @@ jobs:
|
|
| 71 |
CHROMA_PERSIST_DIR: /tmp/chroma
|
| 72 |
run: pytest backend/tests -v
|
| 73 |
|
| 74 |
-
# ββ 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
frontend-check:
|
| 76 |
name: βοΈ Frontend β TypeScript & Build
|
| 77 |
runs-on: ubuntu-latest
|
|
@@ -111,7 +203,7 @@ jobs:
|
|
| 111 |
env:
|
| 112 |
NEXT_PUBLIC_API_URL: http://localhost:8000
|
| 113 |
|
| 114 |
-
# ββ
|
| 115 |
pr-size-check:
|
| 116 |
name: π PR Size Check
|
| 117 |
runs-on: ubuntu-latest
|
|
|
|
| 71 |
CHROMA_PERSIST_DIR: /tmp/chroma
|
| 72 |
run: pytest backend/tests -v
|
| 73 |
|
| 74 |
+
# ββ 2. CodeQL Static Security Analysis ββββββββββββββββββ
|
| 75 |
+
codeql-analysis:
|
| 76 |
+
name: π CodeQL β Static Security Analysis (${{ matrix.language }})
|
| 77 |
+
runs-on: ubuntu-latest
|
| 78 |
+
|
| 79 |
+
permissions:
|
| 80 |
+
actions: read
|
| 81 |
+
contents: read
|
| 82 |
+
|
| 83 |
+
strategy:
|
| 84 |
+
fail-fast: false
|
| 85 |
+
matrix:
|
| 86 |
+
language: ["python", "javascript-typescript"]
|
| 87 |
+
|
| 88 |
+
steps:
|
| 89 |
+
- name: Checkout code
|
| 90 |
+
uses: actions/checkout@v4
|
| 91 |
+
|
| 92 |
+
- name: Initialize CodeQL
|
| 93 |
+
uses: github/codeql-action/init@v4
|
| 94 |
+
with:
|
| 95 |
+
languages: ${{ matrix.language }}
|
| 96 |
+
queries: +security-extended,security-and-quality
|
| 97 |
+
|
| 98 |
+
- name: Perform CodeQL analysis
|
| 99 |
+
uses: github/codeql-action/analyze@v4
|
| 100 |
+
with:
|
| 101 |
+
category: "/language:${{ matrix.language }}"
|
| 102 |
+
output: ${{ runner.temp }}/codeql-results/${{ matrix.language }}
|
| 103 |
+
upload: false
|
| 104 |
+
|
| 105 |
+
- name: Fail on critical security findings
|
| 106 |
+
env:
|
| 107 |
+
SARIF_DIR: ${{ runner.temp }}/codeql-results/${{ matrix.language }}
|
| 108 |
+
run: |
|
| 109 |
+
python - <<'PY'
|
| 110 |
+
import json
|
| 111 |
+
import os
|
| 112 |
+
import pathlib
|
| 113 |
+
import sys
|
| 114 |
+
|
| 115 |
+
sarif_dir = pathlib.Path(os.environ["SARIF_DIR"])
|
| 116 |
+
critical_findings = []
|
| 117 |
+
|
| 118 |
+
for sarif_path in sarif_dir.rglob("*.sarif"):
|
| 119 |
+
with sarif_path.open(encoding="utf-8") as handle:
|
| 120 |
+
sarif = json.load(handle)
|
| 121 |
+
|
| 122 |
+
for run in sarif.get("runs", []):
|
| 123 |
+
rule_severity = {
|
| 124 |
+
rule.get("id"): float(
|
| 125 |
+
rule.get("properties", {}).get(
|
| 126 |
+
"security-severity",
|
| 127 |
+
"0",
|
| 128 |
+
)
|
| 129 |
+
)
|
| 130 |
+
for rule in run.get("tool", {})
|
| 131 |
+
.get("driver", {})
|
| 132 |
+
.get("rules", [])
|
| 133 |
+
if rule.get("id")
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
for result in run.get("results", []):
|
| 137 |
+
rule_id = result.get("ruleId")
|
| 138 |
+
severity = rule_severity.get(rule_id, 0.0)
|
| 139 |
+
if severity < 9.0:
|
| 140 |
+
continue
|
| 141 |
+
|
| 142 |
+
location = result.get("locations", [{}])[0].get(
|
| 143 |
+
"physicalLocation",
|
| 144 |
+
{},
|
| 145 |
+
)
|
| 146 |
+
artifact = location.get("artifactLocation", {}).get(
|
| 147 |
+
"uri",
|
| 148 |
+
"unknown file",
|
| 149 |
+
)
|
| 150 |
+
region = location.get("region", {})
|
| 151 |
+
line = region.get("startLine", "?")
|
| 152 |
+
message = result.get("message", {}).get("text", "")
|
| 153 |
+
critical_findings.append(
|
| 154 |
+
f"{rule_id} ({severity}) at {artifact}:{line} β {message}"
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
if critical_findings:
|
| 158 |
+
print("Critical CodeQL security findings detected:")
|
| 159 |
+
for finding in critical_findings:
|
| 160 |
+
print(f"- {finding}")
|
| 161 |
+
sys.exit(1)
|
| 162 |
+
|
| 163 |
+
print("No critical CodeQL security findings detected.")
|
| 164 |
+
PY
|
| 165 |
+
|
| 166 |
+
# ββ 3. Frontend Build Check βββββββββββββββββββββββββββββ
|
| 167 |
frontend-check:
|
| 168 |
name: βοΈ Frontend β TypeScript & Build
|
| 169 |
runs-on: ubuntu-latest
|
|
|
|
| 203 |
env:
|
| 204 |
NEXT_PUBLIC_API_URL: http://localhost:8000
|
| 205 |
|
| 206 |
+
# ββ 4. PR Size Gate βββββββββββββββββββββββββββββββββββββ
|
| 207 |
pr-size-check:
|
| 208 |
name: π PR Size Check
|
| 209 |
runs-on: ubuntu-latest
|