Skip to content

Commit

Permalink
Debugging run
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Dec 4, 2024
1 parent 65fe72a commit 146b222
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 14 deletions.
121 changes: 111 additions & 10 deletions .github/workflows/test-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,126 @@ 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

Check warning

Code scanning / GitHub Actions Scanner

Missing pinned commit hash for GitHub Actions configuration Warning test

found external action "actions/github-script@v7" without pinned version hash
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

Check warning

Code scanning / GitHub Actions Scanner

Missing pinned commit hash for GitHub Actions configuration Warning test

found external action "actions/github-script@v7" without pinned version hash
with:
pattern: test-results-*
path: historical-results
merge-multiple: true

script: |
const fs = require('fs');
const path = require('path');
const stream = require('stream');
const { promisify } = require('util');
const pipeline = promisify(stream.pipeline);
// Create directory
const historicalDir = path.join('ui', 'historical-results');
fs.mkdirSync(historicalDir, { recursive: true });
// 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
});
// Process each run
for (const run of runs.data.workflow_runs) {
console.log(`Checking run ${run.id} from ${run.created_at}`);
try {
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(`Found ${artifact.name} from run ${run.id}`);
// Use the download-artifact action for each artifact
await exec.exec('gh', [
'run',
'download',
'-n',
artifact.name,
'--repo',
`${context.repo.owner}/${context.repo.repo}`,
'--dir',
historicalDir,
run.id.toString()
]);
}
}
} catch (error) {
console.log(`Error processing run ${run.id}:`, error.message);
}
}
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
Expand Down
8 changes: 4 additions & 4 deletions scripts/analyze-ui-test-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
);

Expand Down

0 comments on commit 146b222

Please sign in to comment.