Advanced Test Analysis #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Advanced Test Analysis | |
| on: | |
| workflow_run: | |
| workflows: ["Advanced CI"] | |
| types: [completed] | |
| jobs: | |
| analyze: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Download test results | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: test-results | |
| path: test-results | |
| - name: Download test reports | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: test-reports | |
| path: test-reports | |
| - name: Install analysis tools | |
| run: | | |
| pip install pandas matplotlib seaborn jinja2 | |
| - name: Generate comprehensive analysis | |
| run: | | |
| python -c """ | |
| import json | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| from datetime import datetime | |
| import os | |
| # テスト結果の読み込み | |
| results = [] | |
| for file in os.listdir('test-results'): | |
| if file.endswith('.json'): | |
| with open(f'test-results/{file}') as f: | |
| results.append(json.load(f)) | |
| # データフレームの作成 | |
| df = pd.DataFrame(results) | |
| # データの分析 | |
| analysis = { | |
| 'total_tests': len(df), | |
| 'passed_tests': len(df[df['status'] == 'passed']), | |
| 'failed_tests': len(df[df['status'] == 'failed']), | |
| 'test_coverage': df['coverage'].mean(), | |
| 'execution_time': df['execution_time'].sum(), | |
| 'generation_date': datetime.now().isoformat() | |
| } | |
| # グラフの生成 | |
| plt.figure(figsize=(12, 6)) | |
| sns.barplot(x='test_type', y='execution_time', data=df) | |
| plt.title('Test Execution Time by Type') | |
| plt.savefig('analysis/execution_time.png') | |
| # 品質指標の分析 | |
| quality_metrics = { | |
| 'coverage_trend': df['coverage'].rolling(window=5).mean().tolist(), | |
| 'failure_rate': (df['status'] == 'failed').mean(), | |
| 'test_density': len(df) / df['execution_time'].sum() | |
| } | |
| # パフォーマンス指標の分析 | |
| performance_metrics = { | |
| 'avg_response_time': df['response_time'].mean(), | |
| 'max_response_time': df['response_time'].max(), | |
| '95th_percentile': df['response_time'].quantile(0.95) | |
| } | |
| # 統計データの保存 | |
| with open('analysis/metrics.json', 'w') as f: | |
| json.dump({ | |
| 'analysis': analysis, | |
| 'quality_metrics': quality_metrics, | |
| 'performance_metrics': performance_metrics | |
| }, f, indent=2) | |
| """ | |
| - name: Generate quality report | |
| run: | | |
| python -c """ | |
| import json | |
| from datetime import datetime | |
| # 品質レポートの生成 | |
| with open('analysis/metrics.json') as f: | |
| metrics = json.load(f) | |
| with open('quality-report.md', 'w') as f: | |
| f.write("# Quality Report\n\n") | |
| f.write(f"Generated on: {datetime.now().isoformat()}\n\n") | |
| f.write("## Quality Metrics\n\n") | |
| for metric, value in metrics['quality_metrics'].items(): | |
| f.write(f"- {metric}: {value}\n") | |
| """ | |
| - name: Generate performance report | |
| run: | | |
| python -c """ | |
| import json | |
| from datetime import datetime | |
| # パフォーマンスレポートの生成 | |
| with open('analysis/metrics.json') as f: | |
| metrics = json.load(f) | |
| with open('performance-report.md', 'w') as f: | |
| f.write("# Performance Report\n\n") | |
| f.write(f"Generated on: {datetime.now().isoformat()}\n\n") | |
| f.write("## Performance Metrics\n\n") | |
| for metric, value in metrics['performance_metrics'].items(): | |
| f.write(f"- {metric}: {value}\n") | |
| """ | |
| - name: Generate trend analysis | |
| run: | | |
| python -c """ | |
| import json | |
| from datetime import datetime | |
| # トレンド分析の生成 | |
| with open('analysis/metrics.json') as f: | |
| metrics = json.load(f) | |
| with open('trend-analysis.md', 'w') as f: | |
| f.write("# Trend Analysis\n\n") | |
| f.write(f"Generated on: {datetime.now().isoformat()}\n\n") | |
| f.write("## Coverage Trend\n\n") | |
| f.write("\n") | |
| """ | |
| - name: Create GitHub PR comment | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const qualityReport = fs.readFileSync('quality-report.md', 'utf8'); | |
| const performanceReport = fs.readFileSync('performance-report.md', 'utf8'); | |
| const trendAnalysis = fs.readFileSync('trend-analysis.md', 'utf8'); | |
| const prNumber = context.payload.pull_request?.number; | |
| if (prNumber) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: `# Test Analysis Summary\n\n${qualityReport}\n\n## Performance Metrics\n\n${performanceReport}\n\n## Trend Analysis\n\n${trendAnalysis}` | |
| }); | |
| } |