1+ name : " Advanced CodeQL + AI Security Analysis"
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+ pull_request :
7+ branches : [ "main" ]
8+ schedule :
9+ - cron : ' 17 17 * * 5'
10+
11+ jobs :
12+ codeql-analysis :
13+ name : CodeQL Analysis
14+ runs-on : ubuntu-latest
15+ permissions :
16+ security-events : write
17+ actions : read
18+ contents : read
19+ packages : read
20+
21+ strategy :
22+ fail-fast : false
23+ matrix :
24+ include :
25+ - language : python
26+ build-mode : none
27+ - language : javascript-typescript
28+ build-mode : none
29+ - language : cpp
30+ build-mode : manual
31+
32+ steps :
33+ - name : Checkout repository
34+ uses : actions/checkout@v4
35+ with :
36+ fetch-depth : 2
37+
38+ - name : Initialize CodeQL
39+ uses : github/codeql-action/init@v3
40+ with :
41+ languages : ${{ matrix.language }}
42+ build-mode : ${{ matrix.build-mode }}
43+ queries : security-extended,security-and-quality
44+
45+ - name : Perform CodeQL Analysis
46+ uses : github/codeql-action/analyze@v3
47+ with :
48+ category : " language:${{ matrix.language }}"
49+
50+ ai-security-scan :
51+ name : AI-Powered Security Scan
52+ runs-on : ubuntu-latest
53+ needs : codeql-analysis
54+ permissions :
55+ security-events : write
56+ contents : read
57+
58+ steps :
59+ - name : Checkout repository
60+ uses : actions/checkout@v4
61+
62+ - name : Setup Python
63+ uses : actions/setup-python@v4
64+ with :
65+ python-version : ' 3.10'
66+
67+ - name : Install dependencies
68+ env :
69+ GEMINI_API_KEY : ${{ secrets.GEMINI_API_KEY }}
70+ run : |
71+ python -m pip install --upgrade pip
72+ pip install -r requirements.txt
73+ pip install httpx_ntlm beautifulsoup4
74+ echo "GEMINI_API_KEY=$GEMINI_API_KEY" >> $GITHUB_ENV
75+ if [ -n "${{ secrets.OPENAI_API_KEY }}" ]; then
76+ echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> $GITHUB_ENV
77+ else
78+ echo "Warning: OPENAI_API_KEY secret is not set." >&2
79+ fi
80+
81+ - name : Run AI-powered security scan
82+ run : |
83+ bughunter-cli ai scan-repo . \
84+ --gemini \
85+ --chatgpt \
86+ --output ai-report.json
87+
88+ # Generate human-readable report
89+ bughunter-cli ai generate-report ai-report.json --format markdown > ai-security-report.md
90+
91+ - name : Upload AI security report
92+ uses : actions/upload-artifact@v4
93+ with :
94+ name : ai-security-report
95+ path : ai-security-report.md
96+
97+ - name : Upload SARIF for GitHub Security
98+ run : |
99+ # Convert AI findings to SARIF format
100+ bughunter-cli utils ai-to-sarif ai-report.json -o ai-scan.sarif
101+ if : always()
102+
103+ - name : Upload SARIF results
104+ uses : github/codeql-action/upload-sarif@v3
105+ with :
106+ sarif_file : ai-scan.sarif
107+ if : always()
108+
109+ ai-vulnerability-analysis :
110+ name : AI Vulnerability Analysis
111+ runs-on : ubuntu-latest
112+ needs : [codeql-analysis, ai-security-scan]
113+ steps :
114+ - name : Download CodeQL results
115+ uses : actions/download-artifact@v3
116+ with :
117+ name : codeql-sarif
118+ path : codeql-results
119+
120+ - name : Download AI results
121+ uses : actions/download-artifact@v3
122+ with :
123+ name : ai-security-report
124+ path : ai-results
125+
126+ - name : Combine and analyze results
127+ run : |
128+ pip install jq
129+
130+ # Combine CodeQL and AI results
131+ jq -s '.[0].runs + .[1].runs' \
132+ codeql-results/codeql.sarif \
133+ ai-results/ai-scan.sarif > combined.sarif
134+
135+ # AI-powered triage and prioritization
136+ bughunter-cli ai triage combined.sarif \
137+ --gemini \
138+ --output prioritized-findings.json
139+
140+ # Generate executive report
141+ bughunter-cli ai generate-report prioritized-findings.json \
142+ --format markdown > executive-report.md
143+
144+ - name : Upload Executive Report
145+ uses : actions/upload-artifact@v4
146+ with :
147+ name : security-executive-report
148+ path : executive-report.md
149+
150+ - name : Create Security Summary
151+ uses : actions/github-script@v6
152+ with :
153+ script : |
154+ const fs = require('fs');
155+ const report = fs.readFileSync('executive-report.md', 'utf8');
156+
157+ await github.rest.issues.createComment({
158+ issue_number: context.issue.number,
159+ owner: context.repo.owner,
160+ repo: context.repo.repo,
161+ body: `## AI Security Analysis Summary\n\n${report}`
162+ });
163+ if : github.event_name == 'pull_request'
164+
165+ container-scan :
166+ name : Container Security Scan
167+ runs-on : ubuntu-latest
168+ needs : codeql-analysis
169+ steps :
170+ - name : Checkout repository
171+ uses : actions/checkout@v4
172+
173+ - name : Set up Docker Buildx
174+ uses : docker/setup-buildx-action@v2
175+
176+ - name : Build Docker image
177+ run : docker build -t app-image .
178+
179+ - name : Scan container with AI
180+ run : |
181+ docker save app-image -o app.tar
182+ bughunter-cli ai scan-container app.tar \
183+ --gemini \
184+ --output container-scan.json
185+
186+ bughunter-cli ai generate-report container-scan.json \
187+ --format markdown > container-report.md
188+
189+ - name : Upload Container Report
190+ uses : actions/upload-artifact@v4
191+ with :
192+ name : container-security-report
193+ path : container-report.md
194+
195+ dependency-scan :
196+ name : Dependency Vulnerability Scan
197+ runs-on : ubuntu-latest
198+ steps :
199+ - name : Checkout repository
200+ uses : actions/checkout@v4
201+
202+ - name : Set up Python
203+ uses : actions/setup-python@v4
204+ with :
205+ python-version : ' 3.10'
206+
207+ - name : Install dependencies
208+ run : pip install safety
209+
210+ - name : Scan Python dependencies
211+ run : safety check --json > dependency-scan.json
212+
213+ - name : Upload results
214+ uses : actions/upload-artifact@v4
215+ with :
216+ name : dependency-scan-results
217+ path : dependency-scan.json
0 commit comments