Skip to content

Commit

Permalink
combine-ui-test-results as its own script
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Dec 2, 2024
1 parent be5f5a8 commit 2adc472
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
33 changes: 1 addition & 32 deletions .github/workflows/test-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,7 @@ jobs:

- name: Combine test results for comparison
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# Note: iterator is hardcoded to 4 to match matrix partitions
run: |
node -e "
const fs = require('fs');
const results = [];
let duration = 0;
let aggregateSummary = { total: 0, passed: 0, failed: 0 };
for (let i = 1; i <= 4; i++) {
try {
const data = JSON.parse(fs.readFileSync('../test-results/test-results-' + i + '/test-results.json'));
results.push(...data.tests);
duration += data.duration;
aggregateSummary.total += data.summary.total;
aggregateSummary.passed += data.summary.passed;
aggregateSummary.failed += data.summary.failed;
} catch (err) {
console.error('Error reading partition ' + i + ':', err);
}
}
fs.writeFileSync('combined-test-results.json', JSON.stringify({
timestamp: new Date().toISOString(),
sha: process.env.GITHUB_SHA,
summary: {
total: aggregateSummary.total,
passed: aggregateSummary.passed,
failed: aggregateSummary.failed
},
duration,
tests: results
}, null, 2));
"
run: node ../scripts/combine-ui-test-results.js
- name: Upload combined results for comparison
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
51 changes: 51 additions & 0 deletions scripts/combine-ui-test-results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

'use strict';
const fs = require('fs');

const NUM_PARTITIONS = 4;

function combineResults() {
const results = [];
let duration = 0;
let aggregateSummary = { total: 0, passed: 0, failed: 0 };

for (let i = 1; i <= NUM_PARTITIONS; i++) {
try {
const data = JSON.parse(
fs.readFileSync(`../test-results/test-results-${i}/test-results.json`).toString()
);
results.push(...data.tests);
duration += data.duration;
aggregateSummary.total += data.summary.total;
aggregateSummary.passed += data.summary.passed;
aggregateSummary.failed += data.summary.failed;
} catch (err) {
console.error(`Error reading partition ${i}:`, err);
}
}

const output = {
timestamp: new Date().toISOString(),
sha: process.env.GITHUB_SHA,
summary: {
total: aggregateSummary.total,
passed: aggregateSummary.passed,
failed: aggregateSummary.failed
},
duration,
tests: results
};

fs.writeFileSync('../ui/combined-test-results.json', JSON.stringify(output, null, 2));
}

if (require.main === module) {
combineResults();
}

module.exports = combineResults;

0 comments on commit 2adc472

Please sign in to comment.