diff --git a/.github/workflows/generate-repros.yml b/.github/workflows/generate-sandboxes-main.yml similarity index 80% rename from .github/workflows/generate-repros.yml rename to .github/workflows/generate-sandboxes-main.yml index 352128e157a..4cd05e1368d 100644 --- a/.github/workflows/generate-repros.yml +++ b/.github/workflows/generate-sandboxes-main.yml @@ -1,13 +1,9 @@ -name: Generate and push repros to Github +name: Generate and push sandboxes (main) on: schedule: - cron: '2 2 */1 * *' workflow_dispatch: - # To remove when the branch will be merged - push: - branches: - - vite-frameworks-xyz jobs: generate: @@ -20,6 +16,8 @@ jobs: with: node-version: 16 - uses: actions/checkout@v3 + with: + ref: main - name: Setup git user run: | git config --global user.name "Storybook Bot" @@ -29,14 +27,14 @@ jobs: - name: Compile Storybook libraries run: yarn task --task publish --start-from=auto --no-link - name: Running local registry - run: yarn local-registry --open & + run: yarn local-registry --publish --open & working-directory: ./code - name: Wait for registry run: yarn wait-on http://localhost:6001 working-directory: ./code - - name: Generate repros + - name: Generate run: yarn generate-sandboxes --local-registry working-directory: ./code - - name: Publish sandboxes to GitHub - run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push + - name: Publish + run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push --branch=main working-directory: ./code diff --git a/.github/workflows/generate-sandboxes-next.yml b/.github/workflows/generate-sandboxes-next.yml new file mode 100644 index 00000000000..564ecfe303c --- /dev/null +++ b/.github/workflows/generate-sandboxes-next.yml @@ -0,0 +1,40 @@ +name: Generate and push sandboxes (next) + +on: + schedule: + - cron: '2 2 */1 * *' + workflow_dispatch: + +jobs: + generate: + runs-on: ubuntu-latest + env: + YARN_ENABLE_IMMUTABLE_INSTALLS: false + CLEANUP_SANDBOX_NODE_MODULES: true + steps: + - uses: actions/setup-node@v3 + with: + node-version: 16 + - uses: actions/checkout@v3 + with: + ref: next + - name: Setup git user + run: | + git config --global user.name "Storybook Bot" + git config --global user.email "bot@storybook.js.org" + - name: Install dependencies + run: node ./scripts/check-dependencies.js + - name: Compile Storybook libraries + run: yarn task --task publish --start-from=auto --no-link + - name: Running local registry + run: yarn local-registry --publish --open & + working-directory: ./code + - name: Wait for registry + run: yarn wait-on http://localhost:6001 + working-directory: ./code + - name: Generate + run: yarn generate-sandboxes --local-registry + working-directory: ./code + - name: Publish + run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push --branch=next + working-directory: ./code diff --git a/code/lib/cli/src/generate.ts b/code/lib/cli/src/generate.ts index 6af425adab8..c6cd389a422 100644 --- a/code/lib/cli/src/generate.ts +++ b/code/lib/cli/src/generate.ts @@ -134,10 +134,10 @@ command('extract [location] [output]') ); command('sandbox [filterValue]') - .alias('repro') // for retrocompatibility purposes + .alias('repro') // for backwards compatibility .description('Create a sandbox from a set of possible templates') .option('-o --output ', 'Define an output directory') - .option('-b --branch ', 'Define the branch to download from', 'next') + .option('-b --branch ', 'Define the branch to download from', 'main') .option('--no-init', 'Whether to download a template without an initialized Storybook', false) .action((filterValue, options) => sandbox({ filterValue, ...options }).catch((e) => { diff --git a/code/package.json b/code/package.json index f9371e1a91a..0f062c0538f 100644 --- a/code/package.json +++ b/code/package.json @@ -29,7 +29,7 @@ "check": "NODE_ENV=production node ../scripts/check-package.js", "ci-tests": "yarn task --task check --no-link --start-from=install && yarn lint && yarn test && cd ../scripts && yarn test", "danger": "danger", - "generate-sandboxes": "ts-node --swc ../scripts/sandbox-generators/generate-sandboxes.ts", + "generate-sandboxes": "ts-node --swc ../scripts/sandbox/generate.ts", "github-release": "github-release-from-changelog", "linear-export": "ts-node --swc --project=../scripts/tsconfig.json ../scripts/linear-export.ts", "lint": "yarn lint:js && yarn lint:md", @@ -40,7 +40,7 @@ "lint:other": "prettier --write '**/*.{css,html,json,md,yml}'", "lint:package": "sort-package-json", "local-registry": "ts-node --swc --project=../scripts/tsconfig.json ../scripts/run-registry.ts", - "publish-sandboxes": "ts-node --swc ../scripts/sandbox-generators/publish.ts", + "publish-sandboxes": "ts-node --swc ../scripts/sandbox/publish.ts", "publish:debug": "npm run publish:latest -- --npm-tag=debug --no-push", "publish:latest": "lerna publish --exact --concurrency 1 --force-publish", "publish:next": "npm run publish:latest -- --npm-tag=next", diff --git a/generate-sandboxes.sh b/generate-sandboxes.sh deleted file mode 100755 index a75eb446955..00000000000 --- a/generate-sandboxes.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -./scripts/node_modules/.bin/ts-node ./scripts/sandbox-generators/generate-sandboxes.ts \ No newline at end of file diff --git a/scripts/get-report-message.ts b/scripts/get-report-message.ts index bae3aac17e5..47b24cfba47 100644 --- a/scripts/get-report-message.ts +++ b/scripts/get-report-message.ts @@ -1,6 +1,7 @@ /* eslint-disable no-console */ import { readJson } from 'fs-extra'; import { join } from 'path'; +import { CODE_DIRECTORY } from './utils/constants'; import { execaCommand } from './utils/exec'; type Branch = 'main' | 'next' | 'alpha' | 'next-release' | 'latest-release'; @@ -13,7 +14,7 @@ const getFooter = async (branch: Branch, workflow: Workflow, job: string) => { // The CI workflows can run on release branches and we should display the version number if (branch === 'next-release' || branch === 'latest-release') { - const packageJson = await readJson(join(__dirname, '..', 'code', 'package.json')); + const packageJson = await readJson(join(CODE_DIRECTORY, 'package.json')); // running in alpha branch we should just show the version which failed return `\n**Version: ${packageJson.version}**`; diff --git a/scripts/get-template.ts b/scripts/get-template.ts index c61ba369840..57f832fe6ec 100644 --- a/scripts/get-template.ts +++ b/scripts/get-template.ts @@ -1,6 +1,5 @@ import { readdir } from 'fs/promises'; import { pathExists } from 'fs-extra'; -import { resolve } from 'path'; import { allTemplates, templatesByCadence, @@ -8,8 +7,9 @@ import { type Template as TTemplate, type SkippableTask, } from '../code/lib/cli/src/sandbox-templates'; +import { SANDBOX_DIRECTORY } from './utils/constants'; -const sandboxDir = process.env.SANDBOX_ROOT || resolve(__dirname, '../sandbox'); +const sandboxDir = process.env.SANDBOX_ROOT || SANDBOX_DIRECTORY; type Template = Pick; export type TemplateKey = keyof typeof allTemplates; diff --git a/scripts/run-registry.ts b/scripts/run-registry.ts index a9f20bbffb8..fd55b720496 100755 --- a/scripts/run-registry.ts +++ b/scripts/run-registry.ts @@ -29,6 +29,7 @@ const startVerdaccio = async () => { self_path: cache, }; + // @ts-expect-error (verdaccio's interface is wrong) runServer(config).then((app: Server) => { app.listen(6001, () => { resolved = true; diff --git a/scripts/sandbox-generators/generate-sandboxes.ts b/scripts/sandbox/generate.ts similarity index 95% rename from scripts/sandbox-generators/generate-sandboxes.ts rename to scripts/sandbox/generate.ts index a684e7c7d02..1d0135e13a2 100755 --- a/scripts/sandbox-generators/generate-sandboxes.ts +++ b/scripts/sandbox/generate.ts @@ -21,11 +21,13 @@ import { localizeYarnConfigFiles, setupYarn } from './utils/yarn'; import type { GeneratorConfig } from './utils/types'; import { getStackblitzUrl, renderTemplate } from './utils/template'; import type { JsPackageManager } from '../../code/lib/cli/src/js-package-manager'; - -const OUTPUT_DIRECTORY = join(__dirname, '..', '..', 'repros'); -const BEFORE_DIR_NAME = 'before-storybook'; -const AFTER_DIR_NAME = 'after-storybook'; -const SCRIPT_TIMEOUT = 5 * 60 * 1000; +import { + BEFORE_DIR_NAME, + AFTER_DIR_NAME, + SCRIPT_TIMEOUT, + REPROS_DIRECTORY, + LOCAL_REGISTRY_URL, +} from '../utils/constants'; const sbInit = async (cwd: string, flags?: string[], debug?: boolean) => { const sbCliBinaryPath = join(__dirname, `../../code/lib/cli/bin/index.js`); @@ -35,7 +37,6 @@ const sbInit = async (cwd: string, flags?: string[], debug?: boolean) => { await runCommand(`${sbCliBinaryPath} init ${fullFlags.join(' ')}`, { cwd, env }, debug); }; -const LOCAL_REGISTRY_URL = 'http://localhost:6001'; const withLocalRegistry = async (packageManager: JsPackageManager, action: () => Promise) => { const prevUrl = packageManager.getRegistryURL(); let error; @@ -89,7 +90,7 @@ const addStorybook = async ({ await rename(tmpDir, afterDir); }; -export const runCommand = async (script: string, options: ExecaOptions, debug: boolean) => { +export const runCommand = async (script: string, options: ExecaOptions, debug = false) => { if (debug) { console.log(`Running command: ${script}`); } @@ -136,7 +137,7 @@ const runGenerators = async ( const time = process.hrtime(); console.log(`🧬 generating ${name}`); - const baseDir = join(OUTPUT_DIRECTORY, dirName); + const baseDir = join(REPROS_DIRECTORY, dirName); const beforeDir = join(baseDir, BEFORE_DIR_NAME); await emptyDir(baseDir); @@ -239,7 +240,7 @@ export const generate = async ({ if (require.main === module) { program - .description('Create a reproduction from a set of possible templates') + .description('Generate sandboxes from a set of possible templates') .option('--template