From 5adc5b6ef5490db9e015a4cb01d8805162704373 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 4 Dec 2024 10:57:40 -0500 Subject: [PATCH] Debugging run --- .github/workflows/test-ui.yml | 135 ++++++++++++++++++++++++++++--- scripts/analyze-ui-test-times.js | 8 +- 2 files changed, 129 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-ui.yml b/.github/workflows/test-ui.yml index a52c0e7b61c..82c5cb3dc6f 100644 --- a/.github/workflows/test-ui.yml +++ b/.github/workflows/test-ui.yml @@ -143,25 +143,140 @@ jobs: run: yarn percy build:finalize analyze-times: - needs: [tests, finalize] + # TODO: temporary comment-out with hardcoded sha + # needs: [tests, finalize] if: github.event_name == 'pull_request' runs-on: ubuntu-latest + defaults: + run: + working-directory: ui + steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + + # Debug step to show environment + - name: Debug environment + run: | + echo "GITHUB_SHA: ${{ github.sha }}" + echo "GITHUB_EVENT_NAME: ${{ github.event_name }}" + echo "GITHUB_REF: ${{ github.ref }}" + echo "RUN_ID: ${{ github.run_id }}" + + # Try to list available artifacts first + - name: List artifacts + uses: actions/github-script@v7 with: - name: test-results-${{ github.sha }} + script: | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + // run_id: context.runId + run_id: 12163157778 + }); + console.log('Available artifacts:'); + console.log(JSON.stringify(artifacts.data, null, 2)); + + - name: Download current PR results + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + # name: test-results-${{ github.sha }} + name: pr-test-results-fe7ca11e9afc42bc98d79fe521155a37634bd232 # TODO: temporary hardcoded sha from previous run path: ui - + run-id: 12163157778 + github-token: ${{ secrets.GITHUB_TOKEN }} + + # - name: Download historical results + # uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + # with: + # pattern: test-results-* + # path: historical-results + # merge-multiple: true + + # Download historical results from previous main branch runs - name: Download historical results - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + uses: actions/github-script@v7 with: - pattern: test-results-* - path: historical-results - merge-multiple: true - + script: | + const fs = require('fs'); + const path = require('path'); + const https = require('https'); + + // Create directory + const historicalDir = path.join('ui', 'historical-results'); + fs.mkdirSync(historicalDir, { recursive: true }); + + // Helper function to download file + async function downloadFile(url, outputPath) { + return new Promise((resolve, reject) => { + const file = fs.createWriteStream(outputPath); + https.get(url, { + headers: { + 'Authorization': `token ${process.env.GITHUB_TOKEN}`, + 'Accept': 'application/vnd.github.v3.raw' + } + }, response => { + response.pipe(file); + file.on('finish', () => { + file.close(); + resolve(); + }); + }).on('error', reject); + }); + } + + // Get the last 10 workflow runs on main + const runs = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'test-ui.yml', + branch: 'main', + per_page: 10 + }); + + // Download artifacts from each run + for (const run of runs.data.workflow_runs) { + console.log(`Checking run ${run.id} from ${run.created_at}`); + + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: run.id + }); + + for (const artifact of artifacts.data.artifacts) { + if (artifact.name.startsWith('test-results-')) { + console.log(`Downloading ${artifact.name} from run ${run.id}`); + + // Get download URL + const download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: artifact.id, + archive_format: 'json' // Request JSON directly instead of ZIP + }); + + // Save the JSON file + fs.writeFileSync( + path.join(historicalDir, `${artifact.name}.json`), + JSON.stringify(download.data, null, 2) + ); + } + } + } + + console.log('Contents of historical-results:'); + console.log(fs.readdirSync(historicalDir)); + + # Debug what we got + - name: Debug directories + run: | + echo "Current directory structure:" + ls -la + printf "\nHistorical results directory:\n" + ls -la historical-results || echo "historical-results directory not found" + - name: Analyze test times - run: node scripts/analyze-test-times.js + run: node ../scripts/analyze-ui-test-times.js - name: Comment PR uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 diff --git a/scripts/analyze-ui-test-times.js b/scripts/analyze-ui-test-times.js index bad4c738372..6c1bc60927e 100644 --- a/scripts/analyze-ui-test-times.js +++ b/scripts/analyze-ui-test-times.js @@ -9,7 +9,7 @@ const fs = require('fs'); async function analyzeTestTimes() { const currentResults = JSON.parse( - fs.readFileSync('../ui/combined-test-results.json') + fs.readFileSync('combined-test-results.json') ); // Create a map of test names to their durations @@ -25,11 +25,11 @@ async function analyzeTestTimes() { // Read each historical result file console.log('[analyze-test-times] Reading historical results directory...\n'); - const historicalFiles = fs.readdirSync('../historical-results'); + const historicalFiles = fs.readdirSync('historical-results'); historicalFiles.forEach((file, index) => { console.log(`[analyze-test-times] Reading ${file} (${index + 1} of ${historicalFiles.length})...`); const historical = JSON.parse( - fs.readFileSync(`../historical-results/${file}`) + fs.readFileSync(`historical-results/${file}`) ); if (historical.summary.failed === 0) { @@ -86,7 +86,7 @@ async function analyzeTestTimes() { // Write analysis results fs.writeFileSync( - '../ui/test-time-analysis.json', + 'test-time-analysis.json', JSON.stringify(analysis, null, 2) );