Skip to content

Commit

Permalink
Continue with publishing even if some sandboxes fail
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Feb 9, 2024
1 parent 02f6241 commit f184601
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/generate-sandboxes.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Generate and push sandboxes
name: Generate and publish sandboxes

on:
schedule:
Expand Down Expand Up @@ -56,15 +56,24 @@ jobs:
run: yarn wait-on tcp:127.0.0.1:6001

- name: Generate
id: generate
run: yarn generate-sandboxes --local-registry

- name: Publish
# publish sandboxes even if the generation fails, as some sandboxes might have been generated successfully
if: !cancelled()
run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT }}@github.com/storybookjs/sandboxes.git --push --branch=next

- name: The job has failed
if: ${{ failure() || cancelled() }}
- name: Report failure to Discord
if: failure()
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }}
uses: Ilshidur/action-discord@master
with:
args: "The generation of sandboxes on the **next** branch has failed. [View Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
args: |
The generation of some or all sandboxes on the **next** branch has failed.
[View Job](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }})
${{ steps.generate.outputs.failed-before-script-templates && format('The following templates failed to execute the before script:\n- {0}', steps.generate.outputs.failed-before-script-templates) || '' }}
${{ steps.generate.outputs.failed-before-script-templates && format('The following templates failed to initialize Storybook:\n- {0}', steps.generate.outputs.failed-init-templates) || '' }}
57 changes: 42 additions & 15 deletions scripts/sandbox/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
REPROS_DIRECTORY,
LOCAL_REGISTRY_URL,
} from '../utils/constants';
import { setOutput } from '@actions/core';

const sbInit = async (
cwd: string,
Expand Down Expand Up @@ -148,7 +149,10 @@ const runGenerators = async (

const limit = pLimit(1);

await Promise.all(
const failedBeforeScriptTemplates: string[] = [];
const failedInitTemplates: string[] = [];

await Promise.allSettled(
generators.map(({ dirName, name, script, expected, env }) =>
limit(async () => {
let flags: string[] = [];
Expand All @@ -173,19 +177,26 @@ const runGenerators = async (
// Some tools refuse to run inside an existing directory and replace the contents,
// where as others are very picky about what directories can be called. So we need to
// handle different modes of operation.
if (script.includes('{{beforeDir}}')) {
const scriptWithBeforeDir = script.replaceAll('{{beforeDir}}', BEFORE_DIR_NAME);
await runCommand(
scriptWithBeforeDir,
{
cwd: createBaseDir,
timeout: SCRIPT_TIMEOUT,
},
debug
);
} else {
await ensureDir(createBeforeDir);
await runCommand(script, { cwd: createBeforeDir, timeout: SCRIPT_TIMEOUT }, debug);
try {
if (script.includes('{{beforeDir}}')) {
const scriptWithBeforeDir = script.replaceAll('{{beforeDir}}', BEFORE_DIR_NAME);
await runCommand(
scriptWithBeforeDir,
{
cwd: createBaseDir,
timeout: SCRIPT_TIMEOUT,
},
debug
);
} else {
await ensureDir(createBeforeDir);
await runCommand(script, { cwd: createBeforeDir, timeout: SCRIPT_TIMEOUT }, debug);
}
} catch (error) {
console.error(`❌ Failed to execute before-script for template: ${name}`);
console.error(error);
failedBeforeScriptTemplates.push(name);
return;
}

await localizeYarnConfigFiles(createBaseDir, createBeforeDir);
Expand All @@ -196,7 +207,14 @@ const runGenerators = async (
// Make sure there are no git projects in the folder
await remove(join(beforeDir, '.git'));

await addStorybook({ baseDir, localRegistry, flags, debug, env });
try {
await addStorybook({ baseDir, localRegistry, flags, debug, env });
} catch (error) {
console.error(`❌ Failed to add Storybook to template: ${name}`);
console.error(error);
failedInitTemplates.push(name);
return;
}

await addDocumentation(baseDir, { name, dirName });

Expand All @@ -218,6 +236,15 @@ const runGenerators = async (
})
)
);

if (process.env.GITHUB_ACTIONS === 'true') {
if (failedBeforeScriptTemplates.length > 0) {
setOutput('failed-before-script-templates', failedBeforeScriptTemplates.join('\n- '));
}
if (failedInitTemplates.length > 0) {
setOutput('failed-init-templates', failedInitTemplates.join('\n- '));
}
}
};

export const options = createOptions({
Expand Down

0 comments on commit f184601

Please sign in to comment.