From 2adc472178db04159d5e5b250e5a925cbf43597f Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Mon, 2 Dec 2024 14:46:56 -0500 Subject: [PATCH] combine-ui-test-results as its own script --- .github/workflows/test-ui.yml | 33 +------------------ scripts/combine-ui-test-results.js | 51 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 scripts/combine-ui-test-results.js diff --git a/.github/workflows/test-ui.yml b/.github/workflows/test-ui.yml index e9294f9d0a7..5478460877c 100644 --- a/.github/workflows/test-ui.yml +++ b/.github/workflows/test-ui.yml @@ -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 diff --git a/scripts/combine-ui-test-results.js b/scripts/combine-ui-test-results.js new file mode 100644 index 00000000000..8d78f423cce --- /dev/null +++ b/scripts/combine-ui-test-results.js @@ -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;