From e27173d27e6fbba44016ce5bef3c8cd224dce906 Mon Sep 17 00:00:00 2001 From: CactusBlue Date: Mon, 27 Jan 2025 16:48:38 -0800 Subject: [PATCH] Automated testing for setup instructions in README.md (#399) * add setup tests * continue, even on error * add build:packages * add automated branch for setup testing * add delay * combine commands * rollback * update README * use action to run in background * try running in foreground for testing * set shell * check if running codegen before works * fix quetzal file missing * swap the order * use background action * fix * try this instead * modify readme * add sleep * raise the timeout * run on faster machine * use jarvus instead * Update packages/stack/scripts/merge-quetzal-translations.ts Co-authored-by: Konsti Wohlwend * Update README.md Co-authored-by: Konsti Wohlwend * fix run on all branches * Update .github/workflows/setup-tests.yaml Co-authored-by: Konsti Wohlwend --------- Co-authored-by: root Co-authored-by: Konsti Wohlwend --- .github/workflows/setup-tests.yaml | 51 +++++++++++++++++++ README.md | 13 ++--- package.json | 1 + .../scripts/merge-quetzal-translations.ts | 14 +++-- 4 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/setup-tests.yaml diff --git a/.github/workflows/setup-tests.yaml b/.github/workflows/setup-tests.yaml new file mode 100644 index 000000000..a760590ae --- /dev/null +++ b/.github/workflows/setup-tests.yaml @@ -0,0 +1,51 @@ +name: "Run setup tests" + + +on: + push: + branches: + - dev + - main + pull_request: + branches: + - dev + - main + +env: + SHELL: /usr/bin/bash + +jobs: + test: + runs-on: ubicloud-standard-8 + timeout-minutes: 20 + steps: + - uses: actions/checkout@v3 + + - name: Setup Node.js v20 + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: 9.1.2 + + - name: Install packages + run: pnpm install + + - run: pnpm run build:packages + - run: pnpm run codegen + - run: pnpm run start-deps + + - uses: JarvusInnovations/background-action@v1.0.7 + with: + run: pnpm run dev & + wait-on: | + http://localhost:8102 + tail: true + wait-for: 120s + log-output-if: true + # - run: pnpm run dev & sleep 120 + - run: pnpm test + diff --git a/README.md b/README.md index a53b33bd9..be7b4b197 100644 --- a/README.md +++ b/README.md @@ -122,21 +122,22 @@ In a new terminal: ```sh pnpm install -# Run build to build everything once -pnpm run build:dev +# Build the packages and generate code. We only need to do this once, as `pnpm dev` will do this from now on +pnpm build:packages +pnpm codegen -# reset & start the dependencies (DB, Inbucket, etc.) as Docker containers, seeding the DB with the Prisma schema -pnpm run start-deps +# Reset & start the dependencies (DB, Inbucket, etc.) as Docker containers, seeding the DB with the Prisma schema +pnpm start-deps # pnpm run restart-deps # pnpm run stop-deps # Start the dev server -pnpm run dev +pnpm dev # For systems with limited resources, you can run a minimal development setup with just the backend and dashboard # pnpm run dev:basic # In a different terminal, run tests in watch mode -pnpm run test +pnpm test ``` You can now open the dev launchpad at [http://localhost:8100](http://localhost:8100). From there, you can navigate to the dashboard at [http://localhost:8101](http://localhost:8101), API on port 8102, demo on port 8103, docs on port 8104, Inbucket (e-mails) on port 8105, and Prisma Studio on port 8106. See the dev launchpad for a list of all running services. diff --git a/package.json b/package.json index 51a5c10d8..241661ba3 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "build:backend": "only-allow pnpm && turbo run build --filter=@stackframe/stack-backend...", "build:dashboard": "only-allow pnpm && turbo run build --filter=@stackframe/stack-dashboard...", "build:demo": "only-allow pnpm && turbo run build --filter=demo-app...", + "build:packages": "only-allow pnpm && turbo run build --filter=./packages/*", "clean": "only-allow pnpm && turbo run clean && rimraf --glob **/.next && rimraf --glob **/.turbo && rimraf .turbo && rimraf --glob **/node_modules", "codegen": "only-allow pnpm && turbo run codegen", "deps-compose": "docker compose -f dependencies.compose.yaml", diff --git a/packages/stack/scripts/merge-quetzal-translations.ts b/packages/stack/scripts/merge-quetzal-translations.ts index 8a7ab50b4..d7aacae2e 100644 --- a/packages/stack/scripts/merge-quetzal-translations.ts +++ b/packages/stack/scripts/merge-quetzal-translations.ts @@ -1,12 +1,20 @@ import { deindent, stringCompare } from "@stackframe/stack-shared/dist/utils/strings"; import * as fs from "fs"; -import quetzalKeys from "../quetzal-translations/keystore.json"; -import supportedLocales from "../quetzal-translations/supported-locales.json"; +import * as path from "path"; async function main() { + let quetzalKeys, supportedLocales + try { + quetzalKeys = JSON.parse(fs.readFileSync(path.join(__dirname, "../quetzal-translations/keystore.json"), 'utf-8')); + supportedLocales = JSON.parse(fs.readFileSync(path.join(__dirname, "../quetzal-translations/supported-locales.json"), 'utf-8')); + } catch (e: unknown) { + console.warn('Quetzal translation files not found, assuming Quetzal failed. The translations will not be updated.'); + process.exit(0); + } + const locales = Object.fromEntries(await Promise.all(supportedLocales.map(async (locale) => [ locale, - (await import(`../quetzal-translations/${locale}.json`)).default + JSON.parse(fs.readFileSync(path.join(__dirname, `../quetzal-translations/${locale}.json`), 'utf-8')) ] as const))); // replace Quetzal's auto-generated IDs (like k-0, k-1, etc.) with our own