Save artifacts on preload cache build failure

This commit is contained in:
Fedor Indutny 2024-09-09 10:41:32 -07:00 committed by GitHub
parent 3dba3a07f0
commit 1922864a49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 25 deletions

View file

@ -109,6 +109,7 @@ jobs:
env: env:
DISABLE_INSPECT_FUSE: on DISABLE_INSPECT_FUSE: on
SIGN_MACOS_SCRIPT: noop.sh SIGN_MACOS_SCRIPT: noop.sh
ARTIFACTS_DIR: artifacts/macos
- name: Upload installer size - name: Upload installer size
if: ${{ github.repository == 'signalapp/Signal-Desktop-Private' && github.ref == 'refs/heads/main' }} if: ${{ github.repository == 'signalapp/Signal-Desktop-Private' && github.ref == 'refs/heads/main' }}
run: | run: |
@ -167,6 +168,8 @@ jobs:
run: npm run build:esbuild:prod run: npm run build:esbuild:prod
- name: Create preload cache - name: Create preload cache
run: xvfb-run --auto-servernum npm run build:preload-cache run: xvfb-run --auto-servernum npm run build:preload-cache
env:
ARTIFACTS_DIR: artifacts/linux
- name: Build with packaging .deb file - name: Build with packaging .deb file
run: npm run build:release -- --publish=never run: npm run build:release -- --publish=never
@ -253,6 +256,8 @@ jobs:
run: npm run build:esbuild:prod run: npm run build:esbuild:prod
- name: Create preload cache - name: Create preload cache
run: npm run build:preload-cache run: npm run build:preload-cache
env:
ARTIFACTS_DIR: artifacts/win
- name: Build with NSIS - name: Build with NSIS
run: npm run build:release run: npm run build:release
@ -365,6 +370,8 @@ jobs:
run: npm run build:esbuild:prod run: npm run build:esbuild:prod
- name: Create preload cache - name: Create preload cache
run: xvfb-run --auto-servernum npm run build:preload-cache run: xvfb-run --auto-servernum npm run build:preload-cache
env:
ARTIFACTS_DIR: artifacts/linux
- name: Run mock server tests - name: Run mock server tests
run: | run: |

View file

@ -1,10 +1,14 @@
// Copyright 2024 Signal Messenger, LLC // Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import { spawnSync } from 'node:child_process'; import { spawn } from 'node:child_process';
import { join } from 'node:path'; import { join } from 'node:path';
import { tmpdir } from 'node:os'; import { tmpdir } from 'node:os';
import { mkdtemp, rm } from 'node:fs/promises'; import { mkdir, mkdtemp, rm, rename } from 'node:fs/promises';
import pTimeout from 'p-timeout';
import { MINUTE } from '../util/durations';
import { explodePromise } from '../util/explodePromise';
const ROOT_DIR = join(__dirname, '..', '..'); const ROOT_DIR = join(__dirname, '..', '..');
@ -18,30 +22,55 @@ const ELECTRON = join(
async function main(): Promise<void> { async function main(): Promise<void> {
const storagePath = await mkdtemp(join(tmpdir(), 'signal-preload-cache-')); const storagePath = await mkdtemp(join(tmpdir(), 'signal-preload-cache-'));
let status: number | null; const proc = spawn(
try { ELECTRON,
({ status } = spawnSync( ['--js-args="--predictable --random-seed 1"', 'ci.js'],
ELECTRON, {
['--js-args="--predictable --random-seed 1"', 'ci.js'], cwd: ROOT_DIR,
{ env: {
cwd: ROOT_DIR, ...process.env,
env: { GENERATE_PRELOAD_CACHE: 'on',
...process.env, SIGNAL_CI_CONFIG: JSON.stringify({
GENERATE_PRELOAD_CACHE: 'on', storagePath,
SIGNAL_CI_CONFIG: JSON.stringify({ }),
storagePath, },
}), // Since we run `.cmd` file on Windows - use shell
}, shell: process.platform === 'win32',
// Since we run `.cmd` file on Windows - use shell }
shell: process.platform === 'win32', );
}
));
} finally {
await rm(storagePath, { recursive: true });
}
if (status !== 0) { try {
throw new Error(`Exit code: ${status}`); const { promise, resolve, reject } = explodePromise<number | null>();
proc.on('exit', status => resolve(status));
proc.on('error', error => reject(error));
const status = await pTimeout(promise, 5 * MINUTE);
if (status !== 0) {
throw new Error(`Exit code: ${status}`);
}
} catch (error) {
const { ARTIFACTS_DIR } = process.env;
if (!ARTIFACTS_DIR) {
console.error(
'Not saving artifacts. Please set ARTIFACTS_DIR env variable'
);
} else {
console.error(`Saving logs to ${ARTIFACTS_DIR}`);
await mkdir(ARTIFACTS_DIR, { recursive: true });
const logsDir = join(storagePath, 'logs');
await rename(logsDir, join(ARTIFACTS_DIR, 'logs'));
}
throw error;
} finally {
try {
proc.kill();
} catch {
// Ignore
}
await rm(storagePath, { recursive: true });
} }
} }