1+ name : Gemini Code Report
2+
3+ on :
4+ push :
5+ branches :
6+ - " **"
7+ workflow_dispatch : # manual trigger
8+
9+ permissions :
10+ contents : write
11+
12+ jobs :
13+ gemini-report :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout repo
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0
21+
22+ - name : Setup Node
23+ uses : actions/setup-node@v4
24+ with :
25+ node-version : 20
26+
27+ - name : Install deps
28+ run : npm install @google/generative-ai simple-git
29+
30+ - name : Run Gemini analysis
31+ env :
32+ GEMINI_API_KEY : ${{ secrets.GEMINI_API_KEY }}
33+ run : |
34+ node <<'EOF'
35+ import { GoogleGenerativeAI } from "@google/generative-ai";
36+ import simpleGit from "simple-git";
37+ import fs from "fs";
38+
39+ const git = simpleGit();
40+ const diff = await git.diff(["HEAD~1"]);
41+
42+ const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
43+ const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro" });
44+
45+ const prompt = `
46+ Analyze the following git diff.
47+ List:
48+ - Issues found
49+ - Severity
50+ - Proposed fixes
51+
52+ Return clean markdown.
53+ Diff:
54+ ${diff}
55+ `;
56+
57+ const result = await model.generateContent(prompt);
58+ const report = result.response.text();
59+
60+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
61+ const reportName = `report-${timestamp}.html`;
62+
63+ const html = `
64+ <html>
65+ <head>
66+ <title>${reportName}</title>
67+ <style>
68+ body { font-family: sans-serif; padding: 2rem; }
69+ pre { white-space: pre-wrap; }
70+ </style>
71+ </head>
72+ <body>
73+ <h1>Gemini Code Report</h1>
74+ <p>${new Date().toUTCString()}</p>
75+ <pre>${report}</pre>
76+ </body>
77+ </html>
78+ `;
79+
80+ fs.writeFileSync(reportName, html);
81+
82+ let index = "";
83+ if (fs.existsSync("report.html")) {
84+ index = fs.readFileSync("report.html", "utf8");
85+ } else {
86+ index = `
87+ <html>
88+ <head>
89+ <title>Reports</title>
90+ </head>
91+ <body>
92+ <h1>Gemini Reports</h1>
93+ <div id="reports"></div>
94+ </body>
95+ </html>
96+ `;
97+ }
98+
99+ // Add new report link at the top of reports
100+ const button = `<p><a href="./${reportName}">${reportName}</a></p>`;
101+ index = index.replace(
102+ '<div id="reports">',
103+ `<div id="reports">\n${button}`
104+ );
105+
106+ fs.writeFileSync("report.html", index);
107+
108+ console.log("=== Gemini Conclusion ===");
109+ console.log(report);
110+ EOF
111+
112+ - name : Commit and push reports to GitHub Pages
113+ run : |
114+ git config user.name "gemini-bot"
115+ git config user.email "gemini@actions"
116+ git add report*.html report.html
117+ git commit -m "Add Gemini code report" || echo "No changes to commit"
118+
119+ # Add GitHub Pages repo as remote
120+ git remote add pages https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/Mod-Sauce/mod-sauce.github.io.git
121+
122+ # Push to main branch
123+ git push pages main
0 commit comments