Skip to content

Commit dc38970

Browse files
authored
Workflows
1 parent 59b8e20 commit dc38970

File tree

2 files changed

+131
-8
lines changed

2 files changed

+131
-8
lines changed

.github/workflows/gemini-code-assistant.yml

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,70 @@ jobs:
163163
console.log('🤖 Initializing Gemini AI...');
164164
165165
const genAI = new GoogleGenerativeAI(apiKey);
166-
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
166+
167+
// Try different model names prioritizing quality first, then fallback on rate limits
168+
// Order: 2.5 models (highest quality) -> 2.0 models (higher RPM) -> legacy
169+
const modelNames = [
170+
"gemini-2.5-pro", // 5 RPM, 250K TPM - Highest quality
171+
"gemini-2.5-flash", // 10 RPM, 250K TPM - Best 2.5 balance
172+
"gemini-2.5-flash-preview", // 10 RPM, 250K TPM - Latest 2.5 features
173+
"gemini-2.5-flash-lite", // 15 RPM, 250K TPM - Faster 2.5
174+
"gemini-2.5-flash-lite-preview", // 15 RPM, 250K TPM - Latest 2.5 lite
175+
"gemini-2.0-flash", // 15 RPM, 1M TPM - Good 2.0 balance
176+
"gemini-2.0-flash-lite", // 30 RPM, 1M TPM - Highest RPM fallback
177+
"gemini-1.5-flash", // 15 RPM, 250K TPM - DEPRECATED fallback
178+
"gemini-pro" // Legacy final fallback
179+
];
180+
181+
let model = null;
182+
let modelUsed = null;
183+
184+
for (const modelName of modelNames) {
185+
try {
186+
console.log('🔧 Trying model:', modelName);
187+
model = genAI.getGenerativeModel({ model: modelName });
188+
189+
// Test the model with a small request to check availability/rate limits
190+
console.log('🧪 Testing model availability...');
191+
await model.generateContent("test");
192+
193+
modelUsed = modelName;
194+
console.log('✅ Successfully initialized and tested model:', modelName);
195+
break;
196+
} catch (modelError) {
197+
console.log('❌ Model', modelName, 'failed:', modelError.message);
198+
199+
// Check for rate limit errors specifically
200+
if (modelError.message && (
201+
modelError.message.includes('rate limit') ||
202+
modelError.message.includes('quota') ||
203+
modelError.message.includes('429') ||
204+
modelError.status === 429
205+
)) {
206+
console.log('⚠️ Rate limit detected, trying next model with higher RPM...');
207+
} else if (modelError.message && modelError.message.includes('404')) {
208+
console.log('⚠️ Model not found, trying next available model...');
209+
}
210+
continue;
211+
}
212+
}
213+
214+
if (!model) {
215+
throw new Error('No supported Gemini model could be initialized');
216+
}
167217
168218
const prompt = fs.readFileSync('analysis_prompt.txt', 'utf8');
169219
console.log('📝 Prompt loaded, size:', prompt.length, 'characters');
170220
171-
console.log('🚀 Generating analysis...');
221+
console.log('🚀 Generating analysis with model:', modelUsed);
172222
const result = await model.generateContent(prompt);
173223
const response = await result.response;
174224
const text = response.text();
175225
176226
fs.writeFileSync('ai_analysis_result.txt', text);
177227
console.log('✅ Analysis completed successfully');
178228
console.log('📄 Result size:', text.length, 'characters');
229+
console.log('🤖 Model used:', modelUsed);
179230
180231
} catch (error) {
181232
console.error('❌ Gemini analysis failed:', error.message);
@@ -279,4 +330,76 @@ jobs:
279330
fi
280331
281332
echo "============================================================"
282-
echo "✅ Analysis output complete"
333+
echo "✅ Analysis output complete"
334+
335+
- name: Create GitHub Annotations and Summary
336+
if: always()
337+
env:
338+
ANALYSIS_SUCCESS: ${{ steps.ai-analysis.outputs.analysis-success }}
339+
EVENT_NAME: ${{ github.event_name }}
340+
run: |
341+
echo "📝 Creating GitHub annotations and job summary..."
342+
343+
# Create job summary with analysis results
344+
echo "## 🤖 AI Code Analysis Results" >> $GITHUB_STEP_SUMMARY
345+
echo "" >> $GITHUB_STEP_SUMMARY
346+
echo "**Event:** $EVENT_NAME" >> $GITHUB_STEP_SUMMARY
347+
echo "**Status:** $([ "$ANALYSIS_SUCCESS" = "true" ] && echo "✅ Success" || echo "⚠️ Warning")" >> $GITHUB_STEP_SUMMARY
348+
echo "" >> $GITHUB_STEP_SUMMARY
349+
350+
if [ -f ai_analysis_result.txt ]; then
351+
# Add analysis results to job summary
352+
echo "### Analysis Details" >> $GITHUB_STEP_SUMMARY
353+
echo "" >> $GITHUB_STEP_SUMMARY
354+
echo '```' >> $GITHUB_STEP_SUMMARY
355+
cat ai_analysis_result.txt >> $GITHUB_STEP_SUMMARY
356+
echo '```' >> $GITHUB_STEP_SUMMARY
357+
358+
# Create GitHub annotations for key findings
359+
echo "🔍 Creating annotations for key findings..."
360+
361+
# Create notice annotation with summary
362+
echo "::notice title=AI Analysis Complete::Analysis completed for $EVENT_NAME event. Check job summary for detailed results."
363+
364+
# Parse analysis results for security issues and create annotations
365+
if grep -qi "security\|vulnerability\|exploit\|xss\|sql injection\|csrf" ai_analysis_result.txt 2>/dev/null; then
366+
echo "::warning title=Security Review Required::AI analysis detected potential security concerns. Please review the analysis details in the job summary."
367+
fi
368+
369+
# Check for coding standards issues
370+
if grep -qi "coding standard\|psr\|wordpress standard" ai_analysis_result.txt 2>/dev/null; then
371+
echo "::notice title=Coding Standards::AI analysis found coding standards recommendations. Check job summary for details."
372+
fi
373+
374+
# Check for performance issues
375+
if grep -qi "performance\|optimization\|slow\|inefficient" ai_analysis_result.txt 2>/dev/null; then
376+
echo "::notice title=Performance Recommendations::AI analysis found performance optimization opportunities. Check job summary for details."
377+
fi
378+
379+
# Extract specific line-by-line feedback if available
380+
if grep -E "line [0-9]+|:[0-9]+:" ai_analysis_result.txt 2>/dev/null; then
381+
echo "::notice title=Line-Specific Feedback::AI analysis provided line-specific recommendations. See job summary for details."
382+
fi
383+
384+
# Check analysis length and create appropriate annotation
385+
ANALYSIS_SIZE=$(wc -c < ai_analysis_result.txt)
386+
if [ "$ANALYSIS_SIZE" -gt 1000 ]; then
387+
echo "::notice title=Detailed Analysis Available::Comprehensive AI analysis completed ($ANALYSIS_SIZE characters). Full results available in job summary."
388+
else
389+
echo "::notice title=Quick Analysis Complete::AI analysis completed with brief feedback. See job summary for details."
390+
fi
391+
392+
else
393+
echo "### ❌ Analysis Failed" >> $GITHUB_STEP_SUMMARY
394+
echo "" >> $GITHUB_STEP_SUMMARY
395+
echo "The AI analysis could not be completed. This may be due to:" >> $GITHUB_STEP_SUMMARY
396+
echo "- API configuration issues" >> $GITHUB_STEP_SUMMARY
397+
echo "- Network connectivity problems" >> $GITHUB_STEP_SUMMARY
398+
echo "- Service availability" >> $GITHUB_STEP_SUMMARY
399+
echo "" >> $GITHUB_STEP_SUMMARY
400+
echo "Please conduct manual code review." >> $GITHUB_STEP_SUMMARY
401+
402+
echo "::error title=AI Analysis Failed::Unable to complete automated analysis. Manual review required."
403+
fi
404+
405+
echo "✅ GitHub annotations and summary created successfully"

.github/workflows/wp-compatibility-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
39+
php-version: ['7.4', '8.0', '8.3', '8.4']
4040

4141
steps:
4242
- name: Checkout code
@@ -387,7 +387,7 @@ jobs:
387387
runs-on: ubuntu-latest
388388
strategy:
389389
matrix:
390-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
390+
php-version: ['7.4', '8.0', '8.3', '8.4']
391391
fail-fast: false
392392

393393
steps:
@@ -457,7 +457,7 @@ jobs:
457457
runs-on: ubuntu-latest
458458
strategy:
459459
matrix:
460-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
460+
php-version: ['7.4', '8.0', '8.3', '8.4']
461461
fail-fast: false
462462

463463
steps:
@@ -548,7 +548,7 @@ jobs:
548548
runs-on: ubuntu-latest
549549
strategy:
550550
matrix:
551-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
551+
php-version: ['7.4', '8.0', '8.3', '8.4']
552552
wp-version: ['6.5', 'latest', 'nightly']
553553
fail-fast: false
554554

@@ -834,7 +834,7 @@ jobs:
834834
runs-on: ubuntu-latest
835835
strategy:
836836
matrix:
837-
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
837+
php-version: ['7.4', '8.0', '8.3', '8.4']
838838
fail-fast: false
839839

840840
steps:

0 commit comments

Comments
 (0)