From ca0d489beb47a165d259b395bfd37da76082b7ac Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Mon, 28 Jul 2025 09:06:15 -0500 Subject: [PATCH] Save artifacts on test-electron failures Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com> --- ts/scripts/test-electron.ts | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ts/scripts/test-electron.ts b/ts/scripts/test-electron.ts index f94b473da2..70d1d9957f 100644 --- a/ts/scripts/test-electron.ts +++ b/ts/scripts/test-electron.ts @@ -2,10 +2,11 @@ // SPDX-License-Identifier: AGPL-3.0-only import { spawn } from 'node:child_process'; -import { join } from 'node:path'; +import path, { join } from 'node:path'; import { pipeline } from 'node:stream/promises'; import { cpus, tmpdir } from 'node:os'; -import { mkdtemp, rm } from 'node:fs/promises'; +import { mkdir, mkdtemp, rename, rm } from 'node:fs/promises'; +import crypto from 'node:crypto'; import z from 'zod'; import split2 from 'split2'; import logSymbols from 'log-symbols'; @@ -183,6 +184,18 @@ async function launchElectron( throw error; } finally { try { + if (failures.length) { + const artifactsDir = await makeArtifactsDir(); + if (artifactsDir) { + await rename( + path.join(storagePath, 'logs'), + path.join(artifactsDir, 'logs') + ); + console.log('\n'); + console.log(`Saving logs to ${artifactsDir}`); + } + } + await rm(storagePath, { recursive: true }); } catch { // Ignore @@ -236,3 +249,18 @@ main().catch(error => { console.error(error); process.exit(1); }); + +async function makeArtifactsDir(): Promise { + const { ARTIFACTS_DIR } = process.env; + if (!ARTIFACTS_DIR) { + console.log('\nTo save artifacts, please set ARTIFACTS_DIR env variable\n'); + return undefined; + } + + const normalizedPath = crypto.randomBytes(8).toString('hex'); + + const outDir = path.join(ARTIFACTS_DIR, normalizedPath); + await mkdir(outDir, { recursive: true }); + + return outDir; +}