Skip to content

Commit

Permalink
fix error logging and summary generation
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Feb 12, 2024
1 parent 78f122c commit b7eb433
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-sandboxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ jobs:
with:
args: |
The generation of some or all sandboxes on the **next** branch has failed.
[See the job summary for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }})
[See the job summary for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
45 changes: 24 additions & 21 deletions scripts/sandbox/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ import {
LOCAL_REGISTRY_URL,
} from '../utils/constants';
import * as ghActions from '@actions/core';
import dedent from 'ts-dedent';

const isCI = process.env.GITHUB_ACTIONS === 'true';

const logError = isCI ? ghActions.error : console.error;

class BeforeScriptExecutionError extends Error {}
class StorybookInitError extends Error {}

Expand Down Expand Up @@ -164,7 +163,7 @@ const runGenerators = async (
limit(async () => {
try {
if (isCI) {
ghActions.startGroup(`Generating sandbox for ${name}`);
ghActions.startGroup(`${name} (${dirName})`);
}

let flags: string[] = [];
Expand Down Expand Up @@ -208,10 +207,12 @@ const runGenerators = async (
await runCommand(script, { cwd: createBeforeDir, timeout: SCRIPT_TIMEOUT }, debug);
}
} catch (error) {
const message = `❌ Failed to execute before-script for template: ${name}`;
logError(message);
logError(error);
logError((error as any).stack);
const message = `❌ Failed to execute before-script for template: ${name} (${dirName})`;
if (isCI) {
ghActions.error(dedent`${message}
${(error as any).stack}`);
}
console.error(error);
throw new BeforeScriptExecutionError(message, { cause: error });
}

Expand All @@ -229,10 +230,12 @@ const runGenerators = async (
}
await addStorybook({ baseDir, localRegistry, flags, debug, env });
} catch (error) {
const message = `❌ Failed to initialize Storybook in template: ${name}`;
logError(message);
logError(error);
logError((error as any).stack);
const message = `❌ Failed to initialize Storybook in template: ${name} (${dirName})`;
if (isCI) {
ghActions.error(dedent`${message}
${(error as any).stack}`);
}
console.error(error);
throw new StorybookInitError(message, {
cause: error,
});
Expand Down Expand Up @@ -277,25 +280,25 @@ const runGenerators = async (

if (isCI) {
await ghActions.summary
.addRaw('Some sandboxes failed, see the action log for details')
.addRaw('Some sandboxes failed, see the job log for detailed errors')
.addTable([
[
{ data: 'Template', header: true },
{ data: 'Name', header: true },
{ data: 'Key', header: true },
{ data: 'Result', header: true },
],
...generationResults.map((result, index) => {
const template = generators[index].name;
const { name, dirName } = generators[index];
if (result.status === 'fulfilled') {
return [template, '🟢 Pass'];
return [name, dirName, '🟢 Pass'];
}
const generationError = (result as PromiseRejectedResult).reason as Error;
const errorCause = generationError.cause;
if (errorCause instanceof BeforeScriptExecutionError) {
return [template, '🔴 Failed to execute before script'];
} else if (errorCause instanceof StorybookInitError) {
return [template, '🔴 Failed to initialize Storybook'];
if (generationError instanceof BeforeScriptExecutionError) {
return [name, dirName, '🔴 Failed to execute before script'];
} else if (generationError instanceof StorybookInitError) {
return [name, dirName, '🔴 Failed to initialize Storybook'];
} else {
return [template, '🔴 Failed with unknown error'];
return [name, dirName, '🔴 Failed with unknown error'];
}
}),
])
Expand Down

0 comments on commit b7eb433

Please sign in to comment.