Skip to content

Commit 05e09f2

Browse files
authored
Workflows
1 parent 7a12aa7 commit 05e09f2

File tree

2 files changed

+143
-15
lines changed

2 files changed

+143
-15
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: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow performs comprehensive WordPress plugin compatibility and quality checks.
22
# It runs multiple validation processes including:
33
# - WordPress Plugin Check for WordPress.org compatibility
4-
# - PHP compatibility testing across multiple PHP versions (7.4, 8.0, 8.1, 8.2, 8.3, 8.4)
4+
# - PHP compatibility testing across multiple PHP versions (7.4, 8.0, 8.3, 8.4)
55
# - WordPress compatibility testing across multiple WP versions (6.5, latest, nightly)
66
# - PHPStan static analysis for WordPress-specific code quality
77
# - WordPress security vulnerability scanning using pattern analysis
@@ -134,13 +134,13 @@ jobs:
134134
run: |
135135
# Install PHPCS and WordPress Coding Standards using the dealerdirect installer
136136
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
137-
composer global require --dev squizlabs/php_codesniffer:"^3.7.2"
138-
composer global require --dev wp-coding-standards/wpcs:"^3.1.0"
139-
composer global require --dev phpcompatibility/php-compatibility:"^9.3.5"
140-
composer global require --dev phpcompatibility/phpcompatibility-wp:"^2.1.7"
141-
composer global require --dev automattic/vipwpcs:"^3.0.1"
137+
composer global require --dev squizlabs/php_codesniffer:"^3.7"
138+
composer global require --dev wp-coding-standards/wpcs:"^3.1"
139+
composer global require --dev phpcompatibility/php-compatibility:"^9.3"
140+
composer global require --dev phpcompatibility/phpcompatibility-wp:"^2.1"
141+
composer global require --dev automattic/vipwpcs:"^3.0"
142142
composer global require --dev dealerdirect/phpcodesniffer-composer-installer:"^1.1.1"
143-
143+
144144
# Add composer bin to PATH
145145
echo "$HOME/.composer/vendor/bin" >> $GITHUB_PATH
146146
@@ -197,7 +197,7 @@ jobs:
197197
composer global require --dev squizlabs/php_codesniffer:"^3.7"
198198
composer global require --dev wp-coding-standards/wpcs:"^3.0"
199199
composer global require --dev automattic/vipwpcs:"^3.0"
200-
composer global require --dev dealerdirect/phpcodesniffer-composer-installer:"^1.0"
200+
composer global require --dev dealerdirect/phpcodesniffer-composer-installer:"^1.1.1"
201201
202202
# Add composer bin to PATH
203203
echo "$HOME/.composer/vendor/bin" >> $GITHUB_PATH
@@ -554,14 +554,13 @@ jobs:
554554

555555
services:
556556
mysql:
557-
image: mysql:5.7
557+
image: mysql:8.4
558558
env:
559-
MYSQL_ALLOW_EMPTY_PASSWORD: false
560559
MYSQL_ROOT_PASSWORD: root
561560
MYSQL_DATABASE: wordpress_test
562561
ports:
563562
- 3306:3306
564-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
563+
options: --health-cmd="mysqladmin ping -proot --silent" --health-interval=10s --health-timeout=5s --health-retries=3
565564

566565
steps:
567566
- name: Checkout code
@@ -811,6 +810,12 @@ jobs:
811810
echo "❌ Tests failed on PHP ${{ matrix.php-version }} with WordPress ${{ matrix.wp-version }}"
812811
fi
813812
813+
- name: Ensure repository files available after failure
814+
if: ${{ failure() }}
815+
uses: actions/checkout@v5
816+
with:
817+
fetch-depth: 0
818+
814819
- name: Create issue on test failure
815820
if: ${{ failure() }}
816821
uses: JasonEtco/create-an-issue@v2
@@ -879,4 +884,4 @@ jobs:
879884
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
880885
with:
881886
filename: .github/ISSUE_TEMPLATE/phpstan-failure.md
882-
update_existing: false
887+
update_existing: false

0 commit comments

Comments
 (0)