🔄 Transform Results #302
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: 🔄 Transform Results | |
| on: | |
| workflow_run: | |
| workflows: ["📈 Benchmark"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| actions: read | |
| env: | |
| NODE_VERSION: '20' | |
| PYTHON_VERSION: '3.11' | |
| jobs: | |
| transform-results: | |
| name: Transform & Commit Results | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: 📥 Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 1 | |
| - name: 🐍 Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| cache: 'pip' | |
| - name: 📦 Install Python Dependencies | |
| run: | | |
| pip install -r scripts/requirements.txt | |
| - name: 📥 Download Benchmark Results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| pattern: benchmark-results-* | |
| path: ./downloaded-artifacts | |
| - name: 🔍 Verify Downloaded Artifacts | |
| run: | | |
| echo "📂 Downloaded artifacts structure:" | |
| find ./downloaded-artifacts -type f -name "*.json" | head -20 || echo "No JSON files found" | |
| if [ ! -d "./downloaded-artifacts" ] || [ -z "$(find ./downloaded-artifacts -name "*.json" -type f)" ]; then | |
| echo "❌ No benchmark results found in artifacts" | |
| exit 1 | |
| fi | |
| echo "✅ Found benchmark results" | |
| - name: 🗂️ Prepare Benchmark Results Directory | |
| run: | | |
| # Create benchmark-results directory structure | |
| mkdir -p benchmark-results | |
| # Find and copy the benchmark results from artifacts | |
| artifact_dir=$(find ./downloaded-artifacts -name "benchmark-results-*" -type d | head -1) | |
| if [ -n "$artifact_dir" ]; then | |
| echo "📂 Copying results from: $artifact_dir" | |
| # Check if there's a nested benchmark-results directory | |
| if [ -d "$artifact_dir/benchmark-results" ]; then | |
| cp -r "$artifact_dir/benchmark-results"/* benchmark-results/ 2>/dev/null || true | |
| else | |
| cp -r "$artifact_dir"/* benchmark-results/ 2>/dev/null || true | |
| fi | |
| # Try alternative structure if nothing was copied | |
| if [ -z "$(find benchmark-results -name "*.json" -type f 2>/dev/null)" ]; then | |
| find "$artifact_dir" -name "*.json" -exec cp {} benchmark-results/ \; 2>/dev/null || true | |
| fi | |
| else | |
| echo "❌ Could not find benchmark results in artifacts" | |
| exit 1 | |
| fi | |
| # Read workflow context to determine if we should skip main branch commit | |
| context_file="" | |
| if [ -f "benchmark-results/workflow-context.json" ]; then | |
| context_file="benchmark-results/workflow-context.json" | |
| elif [ -f "$artifact_dir/workflow-context.json" ]; then | |
| context_file="$artifact_dir/workflow-context.json" | |
| fi | |
| if [ -n "$context_file" ]; then | |
| COMMIT_TO_MAIN=$(python3 -c "import json; print(json.load(open('$context_file')).get('commit_to_main', 'false'))" 2>/dev/null || echo "false") | |
| echo "COMMIT_TO_MAIN=$COMMIT_TO_MAIN" >> $GITHUB_ENV | |
| echo "📋 Workflow context: commit_to_main=$COMMIT_TO_MAIN" | |
| rm "$context_file" 2>/dev/null || true # Clean up | |
| else | |
| echo "COMMIT_TO_MAIN=false" >> $GITHUB_ENV | |
| echo "📋 No workflow context found, defaulting to skip main branch commit" | |
| fi | |
| echo "📊 Final benchmark-results structure:" | |
| find benchmark-results -type f -name "*.json" | head -10 | |
| - name: 🔄 Transform Results | |
| run: | | |
| echo "🔄 Transforming benchmark results..." | |
| # Ensure results directory exists | |
| mkdir -p results | |
| # Set PYTHONPATH for our transform scripts | |
| export PYTHONPATH="$PWD:$PWD/scripts" | |
| # Transform results with averaging (since benchmarks might run multiple executions) | |
| python scripts/transform/benchmark_results.py \ | |
| --format both \ | |
| --average \ | |
| --results-dir benchmark-results \ | |
| --output-dir results | |
| echo "📊 Generated files:" | |
| ls -la results/ | |
| - name: 📊 Generate Chart Configurations | |
| run: | | |
| echo "📊 Generating Chart.js configurations..." | |
| python scripts/transform/build_charts.py | |
| echo "✅ Chart configurations and README charts generated" | |
| - name: 📊 Generate Framework Stats | |
| run: | | |
| echo "📊 Generating framework stats..." | |
| python scripts/transform/fetch_framework_stats.py || echo "⚠️ Framework stats generation failed" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 📊 Generate Results Summary | |
| run: | | |
| echo "## 🔄 Benchmark Results Transformation" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: ✅ Success" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Timestamp**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Source**: Workflow run #${{ github.event.workflow_run.run_number }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Main Branch Commit**: $([ "$COMMIT_TO_MAIN" = "true" ] && echo "✅ Enabled" || echo "⏭️ Skipped")" >> $GITHUB_STEP_SUMMARY | |
| - name: 📝 Commit to Results Branch | |
| run: | | |
| set -e | |
| TIMESTAMP=$(date -u '+%Y%m%d_%H%M%S') | |
| git config user.name "liss-bot" | |
| git config user.email "alicia-gh-bot@mail.as93.net" | |
| # Store current files in a temporary location | |
| mkdir -p /tmp/results-data | |
| [ -d "benchmark-results" ] && cp -r benchmark-results /tmp/results-data/ 2>/dev/null || true | |
| [ -d "results" ] && cp -r results /tmp/results-data/ 2>/dev/null || true | |
| [ -d "website/static/charts" ] && cp -r website/static/charts /tmp/results-data/ 2>/dev/null || true | |
| # Switch to results branch | |
| git fetch origin results 2>/dev/null || echo "Results branch doesn't exist yet" | |
| # Aggressively clean working directory to avoid checkout conflicts | |
| git add -A | |
| git reset --hard HEAD | |
| git clean -fdx | |
| # Handle results branch carefully to avoid main branch contamination | |
| if git show-ref --verify --quiet refs/remotes/origin/results; then | |
| # Remote results branch exists - check if it's clean (results-only) | |
| git checkout --orphan temp-check | |
| git rm -rf . 2>/dev/null || true | |
| git fetch origin results:temp-results | |
| git checkout temp-results | |
| # Check if this branch has main branch files (contamination check) | |
| if [ -f ".github/README.md" ] || [ -f "package.json" ]; then | |
| echo "🧹 Results branch appears contaminated with main branch files, creating clean branch" | |
| git checkout --orphan results | |
| git rm -rf . 2>/dev/null || true | |
| else | |
| echo "✅ Results branch looks clean, using existing branch" | |
| git branch -D results 2>/dev/null || true | |
| git branch -m temp-results results | |
| fi | |
| git branch -D temp-check 2>/dev/null || true | |
| else | |
| # No remote results branch exists, create new orphan branch | |
| echo "🆕 Creating new results branch" | |
| git checkout --orphan results | |
| git rm -rf . 2>/dev/null || true | |
| fi | |
| # Set up directory structure | |
| mkdir -p raw summary charts stats | |
| # Copy files from temporary location to organized structure | |
| [ -d "/tmp/results-data/benchmark-results" ] && cp -r /tmp/results-data/benchmark-results/* raw/ 2>/dev/null || true | |
| [ -f "/tmp/results-data/results/summary.json" ] && cp /tmp/results-data/results/summary.json summary/summary-${TIMESTAMP}.json 2>/dev/null || true | |
| [ -f "/tmp/results-data/results/summary.tsv" ] && cp /tmp/results-data/results/summary.tsv summary/summary-${TIMESTAMP}.tsv 2>/dev/null || true | |
| [ -f "/tmp/results-data/results/summary.json" ] && cp /tmp/results-data/results/summary.json summary/summary.json 2>/dev/null || true | |
| [ -f "/tmp/results-data/results/summary.tsv" ] && cp /tmp/results-data/results/summary.tsv summary/summary.tsv 2>/dev/null || true | |
| [ -d "/tmp/results-data/charts" ] && cp -r /tmp/results-data/charts/* charts/ 2>/dev/null || true | |
| [ -f "/tmp/results-data/results/framework-stats.json" ] && cp /tmp/results-data/results/framework-stats.json stats/stats-${TIMESTAMP}.json 2>/dev/null || true | |
| [ -f "/tmp/results-data/results/framework-stats.json" ] && cp /tmp/results-data/results/framework-stats.json stats/framework-stats.json 2>/dev/null || true | |
| # Commit and push results branch | |
| if git add raw/ summary/ charts/ stats/ && ! git diff --staged --quiet; then | |
| git commit -m "chore: update results from run #${{ github.event.workflow_run.run_number }} [${TIMESTAMP}]" | |
| if git push --force-with-lease origin results; then | |
| echo "✅ Results committed to results branch" | |
| else | |
| echo "⚠️ Failed to push results branch updates" | |
| fi | |
| else | |
| echo "ℹ️ No changes to commit to results branch" | |
| fi | |
| - name: 📝 Commit to Main Branch | |
| run: | | |
| git config user.name "liss-bot" | |
| git config user.email "alicia-gh-bot@mail.as93.net" | |
| # Switch back to main branch | |
| git checkout main | |
| if [ "$COMMIT_TO_MAIN" = "true" ]; then | |
| git add results/ website/static/chart*.json website/static/charts/ .github/README.md || true | |
| if ! git diff --cached --quiet; then | |
| git commit -m "chore(results): update benchmark summaries from run #${{ github.event.workflow_run.run_number }}" | |
| git push | |
| echo "✅ Main branch updated" | |
| else | |
| echo "ℹ️ No changes to commit to main branch" | |
| fi | |
| else | |
| echo "⏭️ Skipping main branch commit (commit_to_main=false)" | |
| fi | |
| - name: 🧹 Cleanup | |
| if: always() | |
| run: | | |
| echo "🧹 Cleaning up temporary files..." | |
| rm -rf ./downloaded-artifacts benchmark-results /tmp/results-branch | |
| echo "✅ Cleanup complete" |