Files
ThordekkCore/.github/workflows/playerbot-ci.yml
T
2026-01-20 21:25:30 -03:00

581 lines
19 KiB
YAML

name: Playerbot CI/CD Pipeline
on:
push:
branches: [playerbot-dev, feature/playerbot-*]
paths:
- 'src/modules/Playerbot/**'
- 'sql/custom/playerbot/**'
- '.github/workflows/playerbot-ci.yml'
- 'CMakeLists.txt'
pull_request:
branches: [playerbot-dev, master]
paths:
- 'src/modules/Playerbot/**'
- 'sql/custom/playerbot/**'
schedule:
- cron: '0 */6 * * *' # Every 6 hours
workflow_dispatch:
inputs:
review_mode:
description: 'Review mode (quick/standard/deep)'
required: false
default: 'standard'
auto_fix:
description: 'Enable auto-fix for critical issues'
required: false
default: 'true'
env:
CMAKE_BUILD_TYPE: RelWithDebInfo
MYSQL_ROOT_DIR: C:/Program Files/MySQL/MySQL Server 8.0
OPENSSL_ROOT_DIR: C:/libs/openssl
jobs:
# ============================================================================
# Job 1: Quick Validation & Static Analysis
# ============================================================================
quick-validation:
name: Quick Validation
runs-on: windows-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0 # Full history for better analysis
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
if (Test-Path .claude\scripts\requirements.txt) {
pip install -r .claude\scripts\requirements.txt
}
- name: Code Format Check
run: |
Write-Host "Running format check..."
if (Test-Path .claude\scripts\run_daily_checks.bat) {
.claude\scripts\run_daily_checks.bat --type morning
}
continue-on-error: true
- name: Static Analysis
run: |
Write-Host "Running quick static analysis..."
if (Test-Path .claude\scripts\master_review.py) {
python .claude\scripts\master_review.py --mode quick
}
- name: Lock Ordering Check
run: |
Write-Host "Checking lock ordering to prevent deadlocks..."
python scripts/analyze_lock_order.py --verbose
continue-on-error: false
- name: Cache validation results
uses: actions/cache@v4
with:
path: .claude/reports
key: validation-${{ github.sha }}
- name: Upload validation report
if: always()
uses: actions/upload-artifact@v4
with:
name: validation-report
path: .claude/reports/
retention-days: 7
# ============================================================================
# Job 2: Security Scan
# ============================================================================
security-scan:
name: Security Scan
runs-on: windows-latest
needs: quick-validation
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade pip
if (Test-Path .claude\scripts\requirements.txt) {
pip install -r .claude\scripts\requirements.txt
}
- name: Dependency Vulnerability Scan
run: |
Write-Host "Scanning for dependency vulnerabilities..."
if (Test-Path .claude\scripts\dependency_scanner.py) {
python .claude\scripts\dependency_scanner.py --severity critical
}
continue-on-error: true
- name: Security Audit
run: |
Write-Host "Running security audit..."
if (Test-Path .claude\scripts\master_review.py) {
python .claude\scripts\master_review.py --agents security-auditor
}
continue-on-error: true
- name: Check for secrets in code
run: |
Write-Host "Checking for exposed secrets..."
git grep -n -i -E "password|api_key|secret|token" -- "*.cpp" "*.h" "*.hpp" || echo "No secrets found"
- name: Upload security report
if: always()
uses: actions/upload-artifact@v4
with:
name: security-report
path: .claude/reports/security_*.json
retention-days: 30
- name: Create security issue if vulnerabilities found
if: failure()
uses: actions/github-script@v7
with:
script: |
const title = '🔒 Security vulnerabilities detected in Playerbot';
const body = `
## Security Scan Results
Security vulnerabilities were detected in the latest commit.
**Commit**: ${{ github.sha }}
**Branch**: ${{ github.ref }}
**Triggered by**: ${{ github.actor }}
Please review the security report artifact for details.
🔗 [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
`;
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['security', 'playerbot', 'critical']
});
# ============================================================================
# Job 3: Build
# ============================================================================
build:
name: Build Playerbot
runs-on: windows-latest
needs: quick-validation
timeout-minutes: 90
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Get current OpenSSL version
id: openssl-info
run: |
$VersionsUrl = "https://api.github.com/repos/slproweb/opensslhashes/contents/win32_openssl_hashes.json"
$Headers = @{
Accept="application/vnd.github.raw+json"
Authorization="Bearer ${{ secrets.GITHUB_TOKEN }}"
}
$openSSL = (Invoke-RestMethod $VersionsUrl -Headers $Headers).files.PSObject.Properties |
Select-Object -ExpandProperty Value |
Where-Object { $_.arch -eq 'INTEL' } |
Where-Object { $_.bits -eq '64' } |
Where-Object { $_.light -eq $false } |
Where-Object { $_.installer -eq 'exe' } |
Sort-Object -Descending @{ Expression = { [version]$_.basever } } |
Select-Object -First 1
[System.String]::Format("cache-key=openssl-{0}-win-{1}-{2}", $openSSL.basever, $openSSL.arch, $openSSL.bits) >> $env:GITHUB_OUTPUT
[System.String]::Format("url={0}", $openSSL.url) >> $env:GITHUB_OUTPUT
- name: Cache OpenSSL
id: cache-openssl
uses: actions/cache@v4
with:
path: ${{ env.OPENSSL_ROOT_DIR }}
key: ${{ steps.openssl-info.outputs.cache-key }}
- name: Download and install OpenSSL
if: steps.cache-openssl.outputs.cache-hit != 'true'
run: |
(New-Object System.Net.WebClient).DownloadFile("${{ steps.openssl-info.outputs.url }}", "${{ env.TEMP }}\openssl.exe")
Start-Process -Wait -FilePath "${{ env.TEMP }}\openssl.exe" "/SILENT","/SP-","/SUPPRESSMSGBOXES",/DIR=${{ env.OPENSSL_ROOT_DIR }}
& ${{ env.OPENSSL_ROOT_DIR }}/bin/openssl.exe version
- name: Download and install Boost
uses: MarkusJx/install-boost@v2
id: install-boost
with:
boost_version: 1.84.0
link: static
platform_version: 2022
toolset: msvc
- name: Initialize Visual Studio Environment
uses: egor-tensin/vs-shell@v2
with:
arch: x64
- name: Cache CMake configuration
uses: actions/cache@v4
with:
path: |
build
!build/bin
key: cmake-${{ hashFiles('**/CMakeLists.txt') }}
- name: Configure CMake
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
run: |
cmake -GNinja -S . -B build `
-DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} `
-DWITH_WARNINGS_AS_ERRORS=ON `
-DTOOLS=ON
- name: Build with timing
run: |
$startTime = Get-Date
cmake --build build --config ${{ env.CMAKE_BUILD_TYPE }} -j 8
$endTime = Get-Date
$duration = $endTime - $startTime
Write-Host "Build completed in $($duration.TotalMinutes) minutes"
- name: Copy Dependencies
run: |
cd build/bin/${{ env.CMAKE_BUILD_TYPE }}
copy "${{ env.MYSQL_ROOT_DIR }}/lib/libmysql.dll" libmysql.dll
copy "${{ env.OPENSSL_ROOT_DIR }}/bin/libssl-3-x64.dll" libssl-3-x64.dll
copy "${{ env.OPENSSL_ROOT_DIR }}/bin/libcrypto-3-x64.dll" libcrypto-3-x64.dll
copy "${{ env.OPENSSL_ROOT_DIR }}/bin/legacy.dll" legacy.dll
- name: Verify binaries
run: |
cd build/bin/${{ env.CMAKE_BUILD_TYPE }}
./bnetserver --version
./worldserver --version
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: playerbot-build-${{ github.sha }}
path: build/bin/${{ env.CMAKE_BUILD_TYPE }}
retention-days: 7
# ============================================================================
# Job 4: Automated Testing
# ============================================================================
test:
name: Run Tests
runs-on: windows-latest
needs: build
timeout-minutes: 45
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: playerbot-build-${{ github.sha }}
path: build/bin/RelWithDebInfo
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install test dependencies
run: |
pip install --upgrade pip
if (Test-Path .claude\scripts\requirements.txt) {
pip install -r .claude\scripts\requirements.txt
}
- name: Run unit tests
run: |
cd build/bin/RelWithDebInfo
# Add your test commands here when tests are implemented
# ./playerbot-tests --gtest_output=xml:test_results.xml
Write-Host "Unit tests placeholder"
continue-on-error: true
- name: Performance tests
run: |
Write-Host "Running performance analysis..."
if (Test-Path .claude\scripts\master_review.py) {
python .claude\scripts\master_review.py --agents performance-analyzer
}
continue-on-error: true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
build/bin/RelWithDebInfo/test_results.xml
.claude/reports/test_*.xml
retention-days: 30
# ============================================================================
# Job 5: Comprehensive Code Review
# ============================================================================
code-review:
name: Code Review
runs-on: windows-latest
needs: [security-scan, build]
timeout-minutes: 120
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade pip
if (Test-Path .claude\scripts\requirements.txt) {
pip install -r .claude\scripts\requirements.txt
}
- name: Full code review
run: |
$mode = "${{ github.event.inputs.review_mode }}"
if ([string]::IsNullOrEmpty($mode)) { $mode = "standard" }
Write-Host "Running $mode code review..."
if (Test-Path .claude\scripts\master_review.py) {
python .claude\scripts\master_review.py --mode $mode
}
- name: Trinity integration check
run: |
Write-Host "Checking TrinityCore integration..."
if (Test-Path .claude\scripts\master_review.py) {
python .claude\scripts\master_review.py --agents trinity-integration-tester
}
continue-on-error: true
- name: Generate report
run: |
Write-Host "Generating comprehensive report..."
if (Test-Path .claude\scripts\master_review.py) {
python .claude\scripts\master_review.py --agents daily-report-generator
}
- name: Upload review report
uses: actions/upload-artifact@v4
with:
name: code-review-report
path: .claude/reports/
retention-days: 90
- name: Comment on PR with review summary
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = '.claude/reports/daily_report_latest.json';
if (!fs.existsSync(path)) {
console.log('No report file found');
return;
}
const report = JSON.parse(fs.readFileSync(path, 'utf8'));
const body = `
## 🤖 Automated Code Review Results
**Quality Score**: ${report.quality_score || 'N/A'}/100
**Security Score**: ${report.security_score || 'N/A'}/100
**Performance Score**: ${report.performance_score || 'N/A'}/100
### Issues Found
- 🔴 Critical: ${report.critical_issues || 0}
- 🟠 High: ${report.high_issues || 0}
- 🟡 Medium: ${report.medium_issues || 0}
- 🟢 Low: ${report.low_issues || 0}
### Recommendations
${report.recommendations || 'No recommendations'}
[View full report](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
# ============================================================================
# Job 6: Auto-Fix Critical Issues
# ============================================================================
auto-fix:
name: Auto-Fix Issues
runs-on: windows-latest
needs: code-review
if: github.event.inputs.auto_fix == 'true' || github.event_name != 'workflow_dispatch'
timeout-minutes: 30
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade pip
if (Test-Path .claude\scripts\requirements.txt) {
pip install -r .claude\scripts\requirements.txt
}
- name: Apply auto-fixes
run: |
Write-Host "Applying automatic fixes for critical issues..."
if (Test-Path .claude\scripts\daily_automation.ps1) {
.claude\scripts\daily_automation.ps1 -CheckType critical -AutoFix
}
- name: Check for changes
id: check-changes
run: |
$changes = git status --porcelain
if ($changes) {
echo "has_changes=true" >> $env:GITHUB_OUTPUT
} else {
echo "has_changes=false" >> $env:GITHUB_OUTPUT
}
- name: Commit fixes
if: steps.check-changes.outputs.has_changes == 'true'
run: |
git config user.name "PlayerBot CI"
git config user.email "[email protected]"
git add .
git commit -m "[AUTO-FIX] Resolve critical issues from CI pipeline`n`n🤖 Generated with Claude Code`nCo-Authored-By: Claude <[email protected]>"
git push
- name: Comment on PR about fixes
if: github.event_name == 'pull_request' && steps.check-changes.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🤖 **Auto-Fix Applied**: Critical issues have been automatically resolved. Please review the changes in the latest commit.'
});
# ============================================================================
# Job 7: Deployment (Production branch only)
# ============================================================================
deploy:
name: Deploy
runs-on: windows-latest
needs: [test, code-review]
if: github.ref == 'refs/heads/playerbot-dev' && github.event_name == 'push'
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: playerbot-build-${{ github.sha }}
path: build/bin/RelWithDebInfo
- name: Create release tag
run: |
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$tag = "playerbot-$timestamp"
git tag $tag
git push origin $tag
Write-Host "Created tag: $tag"
- name: Create release notes
run: |
$notes = @"
# Playerbot Build ${{ github.sha }}
**Branch**: ${{ github.ref }}
**Commit**: ${{ github.sha }}
**Timestamp**: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
## Changes
$(git log --oneline -10)
## Build Info
- Build Type: ${{ env.CMAKE_BUILD_TYPE }}
- Platform: Windows x64
- Compiler: MSVC 2022
🤖 Generated with Claude Code
"@
$notes | Out-File -FilePath release_notes.md
- name: Notify deployment success
run: |
Write-Host "✅ Playerbot deployment completed successfully!"
Write-Host "Tag: $(git describe --tags)"
# ==============================================================================
# Summary
# ==============================================================================
# This comprehensive CI/CD pipeline provides:
# - Quick validation and static analysis
# - Security scanning with automatic issue creation
# - Full build with caching and timing
# - Automated testing (placeholder for future tests)
# - Comprehensive code review with PR comments
# - Automatic fixing of critical issues with commits
# - Deployment with tagged releases
#
# Execution time: ~2-3 hours for full pipeline (deep review mode)
# Execution time: ~45-60 minutes for standard pipeline
# Execution time: ~15-20 minutes for quick validation only
# ==============================================================================