From 541de936e35afadba877423d17d8a14a56e70eb1 Mon Sep 17 00:00:00 2001 From: Mehul Kar Date: Fri, 12 May 2023 23:12:35 -0700 Subject: [PATCH] ci: make every examples test a workspace This setup will allow turbo to parallelize and cache execution of these tests. It also reduces the number of Github Workflow runs that are triggered when an example changes, greatly reducing the amount of computing power required to run the tests. This commit does not change the fact that all examples tests are run when any of the examples change. We may be able to wire up dependencies more carefully in the future, but this is not feasible at the moment because each example itself is not a workspace. --- .github/workflows/test.yml | 56 ++------- .../examples => examples-tests}/README.md | 0 examples-tests/helpers/package.json | 6 + examples-tests/helpers/setup_prysk.sh | 14 +++ examples-tests/helpers/turbo.json | 9 ++ examples-tests/npm-non-monorepo/package.json | 11 ++ examples-tests/npm-non-monorepo/test.t | 20 ++++ examples-tests/npm-with-npm/package.json | 11 ++ examples-tests/npm-with-npm/test.t | 30 +++++ examples-tests/npm-with-yarn/package.json | 11 ++ examples-tests/npm-with-yarn/test.t | 30 +++++ examples-tests/pnpm-basic/package.json | 11 ++ examples-tests/pnpm-basic/test.t | 30 +++++ examples-tests/pnpm-kitchen-sink/package.json | 11 ++ examples-tests/pnpm-kitchen-sink/test.t | 30 +++++ examples-tests/pnpm-with-svelte/package.json | 11 ++ examples-tests/pnpm-with-svelte/test.t | 30 +++++ .../tests => examples-tests}/setup.sh | 30 ++++- examples-tests/yarn-non-monorepo/package.json | 11 ++ examples-tests/yarn-non-monorepo/test.t | 29 +++++ examples-tests/yarn-with-npm/package.json | 11 ++ examples-tests/yarn-with-npm/test.t | 31 +++++ examples-tests/yarn-with-yarn/package.json | 11 ++ examples-tests/yarn-with-yarn/test.t | 31 +++++ pnpm-lock.yaml | 111 ++++++++++++++++-- pnpm-workspace.yaml | 1 + turbo.json | 13 ++ turborepo-tests/examples/package.json | 10 -- turborepo-tests/examples/run-example.sh | 19 --- .../examples/tests/npm-non-monorepo.t | 5 - turborepo-tests/examples/tests/npm-with-npm.t | 5 - .../examples/tests/npm-with-yarn.t | 5 - turborepo-tests/examples/tests/pnpm-basic.t | 5 - turborepo-tests/examples/tests/pnpm-gatsby.t | 5 - .../examples/tests/pnpm-kitchen-sink.t | 5 - .../examples/tests/pnpm-with-svelte.t | 5 - .../examples/tests/yarn-non-monorepo.t | 5 - .../examples/tests/yarn-with-npm.t | 5 - .../examples/tests/yarn-with-yarn.t | 5 - turborepo-tests/examples/turbo.json | 14 --- turborepo-tests/helpers/setup_git.sh | 10 +- 41 files changed, 549 insertions(+), 154 deletions(-) rename {turborepo-tests/examples => examples-tests}/README.md (100%) create mode 100644 examples-tests/helpers/package.json create mode 100755 examples-tests/helpers/setup_prysk.sh create mode 100644 examples-tests/helpers/turbo.json create mode 100644 examples-tests/npm-non-monorepo/package.json create mode 100644 examples-tests/npm-non-monorepo/test.t create mode 100644 examples-tests/npm-with-npm/package.json create mode 100644 examples-tests/npm-with-npm/test.t create mode 100644 examples-tests/npm-with-yarn/package.json create mode 100644 examples-tests/npm-with-yarn/test.t create mode 100644 examples-tests/pnpm-basic/package.json create mode 100644 examples-tests/pnpm-basic/test.t create mode 100644 examples-tests/pnpm-kitchen-sink/package.json create mode 100644 examples-tests/pnpm-kitchen-sink/test.t create mode 100644 examples-tests/pnpm-with-svelte/package.json create mode 100644 examples-tests/pnpm-with-svelte/test.t rename {turborepo-tests/examples/tests => examples-tests}/setup.sh (59%) create mode 100644 examples-tests/yarn-non-monorepo/package.json create mode 100644 examples-tests/yarn-non-monorepo/test.t create mode 100644 examples-tests/yarn-with-npm/package.json create mode 100644 examples-tests/yarn-with-npm/test.t create mode 100644 examples-tests/yarn-with-yarn/package.json create mode 100644 examples-tests/yarn-with-yarn/test.t delete mode 100644 turborepo-tests/examples/package.json delete mode 100755 turborepo-tests/examples/run-example.sh delete mode 100644 turborepo-tests/examples/tests/npm-non-monorepo.t delete mode 100644 turborepo-tests/examples/tests/npm-with-npm.t delete mode 100644 turborepo-tests/examples/tests/npm-with-yarn.t delete mode 100644 turborepo-tests/examples/tests/pnpm-basic.t delete mode 100644 turborepo-tests/examples/tests/pnpm-gatsby.t delete mode 100644 turborepo-tests/examples/tests/pnpm-kitchen-sink.t delete mode 100644 turborepo-tests/examples/tests/pnpm-with-svelte.t delete mode 100644 turborepo-tests/examples/tests/yarn-non-monorepo.t delete mode 100644 turborepo-tests/examples/tests/yarn-with-npm.t delete mode 100644 turborepo-tests/examples/tests/yarn-with-yarn.t delete mode 100644 turborepo-tests/examples/turbo.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24894f4ff5c8b3..62eb2c138067e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -149,7 +149,7 @@ jobs: with: PATTERNS: | examples/** - turborepo-tests/examples/** + examples-tests/** !**.md !**.mdx @@ -298,8 +298,8 @@ jobs: - name: E2E Tests run: turbo run test --filter=turborepo-tests-e2e - go_examples: - name: Go Cli Examples + turborepo_examples: + name: Turborepo Examples needs: determine_jobs if: needs.determine_jobs.outputs.examples == 'true' timeout-minutes: 30 @@ -312,43 +312,9 @@ jobs: runner: ubuntu-latest - name: macos runner: macos-latest - manager: [yarn, npm] - example: [with-yarn, with-npm, non-monorepo] - include: - - os: - name: ubuntu - runner: ubuntu-latest - manager: pnpm - example: basic - - os: - name: macos - runner: macos-latest - manager: pnpm - example: basic - - os: - name: ubuntu - runner: ubuntu-latest - manager: pnpm - example: kitchen-sink - - os: - name: macos - runner: macos-latest - manager: pnpm - example: kitchen-sink - - os: - name: ubuntu - runner: ubuntu-latest - manager: pnpm - example: with-svelte - - os: - name: macos - runner: macos-latest - manager: pnpm - example: with-svelte - runs-on: ${{ matrix.os.runner }} steps: - # Used by scripts/check-examples.sh + # Used by examples-tests/setup.sh - name: Install Sponge shell: bash run: | @@ -364,7 +330,6 @@ jobs: - name: "Setup Node" uses: ./.github/actions/setup-node with: - enable-corepack: "false" package-install: "false" enable-pnpm-cache: "true" @@ -372,14 +337,13 @@ jobs: shell: bash run: npm i -g turbo@canary - - name: Check \"${{ matrix.example }}\" example with \"${{ matrix.manager }}\" + - name: Check examples shell: bash env: - FORCE_COLOR: true TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} TURBO_REMOTE_ONLY: true - run: turbo run test --filter="turborepo-tests-examples" -- "${{ matrix.example }}" "${{ matrix.manager }}" + run: turbo run example-test --filter="@turborepo-examples-tests/*" --continue js_packages: name: JS Package Tests @@ -1149,7 +1113,7 @@ jobs: - determine_jobs - go_lint - go_unit - - go_examples + - turborepo_examples - go_e2e - go_integration - js_packages @@ -1186,7 +1150,7 @@ jobs: subjob ${{needs.determine_jobs.result}} "Determining jobs" subjob ${{needs.go_lint.result}} "Go lints" subjob ${{needs.go_unit.result}} "Go unit tests" - subjob ${{needs.go_examples.result}} "Go examples" + subjob ${{needs.turborepo_examples.result}} "Turborepo examples" subjob ${{needs.go_e2e.result}} "Go e2e tests" subjob ${{needs.go_integration.result}} "Go integration tests" subjob ${{needs.js_packages.result}} "JS Package tests" @@ -1264,7 +1228,7 @@ jobs: - determine_jobs - go_lint - go_unit - - go_examples + - turborepo_examples - go_e2e - go_integration - rust_prepare @@ -1304,7 +1268,7 @@ jobs: subjob ${{needs.determine_jobs.result}} "Determining jobs" subjob ${{needs.go_lint.result}} "Go lints" subjob ${{needs.go_unit.result}} "Go unit tests" - subjob ${{needs.go_examples.result}} "Go examples" + subjob ${{needs.turborepo_examples.result}} "Turborepo examples" subjob ${{needs.go_e2e.result}} "Go e2e tests" subjob ${{needs.go_integration.result}} "Go integration tests" subjob ${{needs.rust_prepare.result}} "Rust prepare" diff --git a/turborepo-tests/examples/README.md b/examples-tests/README.md similarity index 100% rename from turborepo-tests/examples/README.md rename to examples-tests/README.md diff --git a/examples-tests/helpers/package.json b/examples-tests/helpers/package.json new file mode 100644 index 00000000000000..2d2a49ec53ab55 --- /dev/null +++ b/examples-tests/helpers/package.json @@ -0,0 +1,6 @@ +{ + "name": "@turborepo-examples-tests/helpers", + "scripts": { + "setup": "./setup_prysk.sh" + } +} diff --git a/examples-tests/helpers/setup_prysk.sh b/examples-tests/helpers/setup_prysk.sh new file mode 100755 index 00000000000000..54a2d04437a1a1 --- /dev/null +++ b/examples-tests/helpers/setup_prysk.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e +BASE_DIR="$PWD/.." + +echo "basedir: $BASE_DIR" + +if [ -f "$BASE_DIR/.cram_env/bin/prysk" ]; then + echo "Skipping prysk setup, prysk and venv already exists" +else + python3 -m venv "$BASE_DIR/.cram_env" + "$BASE_DIR/.cram_env/bin/python3" -m pip install --quiet --upgrade pip + "$BASE_DIR/.cram_env/bin/pip" install "prysk==0.15.0" +fi diff --git a/examples-tests/helpers/turbo.json b/examples-tests/helpers/turbo.json new file mode 100644 index 00000000000000..fc6e5b4b0ac091 --- /dev/null +++ b/examples-tests/helpers/turbo.json @@ -0,0 +1,9 @@ +{ + "extends": ["//"], + "pipeline": { + "setup": { + "cache": false + }, + "topo": {} + } +} diff --git a/examples-tests/npm-non-monorepo/package.json b/examples-tests/npm-non-monorepo/package.json new file mode 100644 index 00000000000000..157b12e1cf2515 --- /dev/null +++ b/examples-tests/npm-non-monorepo/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/npm-non-monorepo", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/npm-non-monorepo/test.t b/examples-tests/npm-non-monorepo/test.t new file mode 100644 index 00000000000000..ec32e4148780c2 --- /dev/null +++ b/examples-tests/npm-non-monorepo/test.t @@ -0,0 +1,20 @@ + $ . ${TESTDIR}/../setup.sh non-monorepo npm + 8\.\d+\.\d (re) +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false npx turbo build lint --output-logs=none + \xe2\x80\xa2 Running build, lint (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 2 successful, 2 total + Cached: 0 cached, 2 total + Time:\s*[\.0-9ms]+ (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false npx turbo build lint --output-logs=none + \xe2\x80\xa2 Running build, lint (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 2 successful, 2 total + Cached: 2 cached, 2 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + $ git diff diff --git a/examples-tests/npm-with-npm/package.json b/examples-tests/npm-with-npm/package.json new file mode 100644 index 00000000000000..aa032f82ad3c03 --- /dev/null +++ b/examples-tests/npm-with-npm/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/npm-with-npm", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/npm-with-npm/test.t b/examples-tests/npm-with-npm/test.t new file mode 100644 index 00000000000000..b98c1dd3a670be --- /dev/null +++ b/examples-tests/npm-with-npm/test.t @@ -0,0 +1,30 @@ + $ . ${TESTDIR}/../setup.sh with-npm npm + 8\.\d+\.\d (re) +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false npm run build lint -- --output-logs=none + + \> build (re) + \> turbo run build lint --output-logs=none (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 0 cached, 5 total + Time:\s*[\.0-9ms]+ (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false npm run build lint -- --output-logs=none + + \> build (re) + \> turbo run build lint --output-logs=none (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 5 cached, 5 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + $ git diff diff --git a/examples-tests/npm-with-yarn/package.json b/examples-tests/npm-with-yarn/package.json new file mode 100644 index 00000000000000..5d50a51b64b382 --- /dev/null +++ b/examples-tests/npm-with-yarn/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/npm-with-yarn", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/npm-with-yarn/test.t b/examples-tests/npm-with-yarn/test.t new file mode 100644 index 00000000000000..26cde7b55acc97 --- /dev/null +++ b/examples-tests/npm-with-yarn/test.t @@ -0,0 +1,30 @@ + $ . ${TESTDIR}/../setup.sh with-yarn npm + 8\.\d+\.\d (re) +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false npm run build lint -- --output-logs=none + + \> build (re) + \> turbo build lint --output-logs=none (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 0 cached, 5 total + Time:\s*[\.0-9ms]+ (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false npm run build lint -- --output-logs=none + + \> build (re) + \> turbo build lint --output-logs=none (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 5 cached, 5 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + $ git diff diff --git a/examples-tests/pnpm-basic/package.json b/examples-tests/pnpm-basic/package.json new file mode 100644 index 00000000000000..6001e0978e76ff --- /dev/null +++ b/examples-tests/pnpm-basic/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/pnpm-basic", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/pnpm-basic/test.t b/examples-tests/pnpm-basic/test.t new file mode 100644 index 00000000000000..75cb80cd9612ec --- /dev/null +++ b/examples-tests/pnpm-basic/test.t @@ -0,0 +1,30 @@ + $ . ${TESTDIR}/../setup.sh basic pnpm + 6.26.1 +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false pnpm run build lint -- --output-logs=none + + \> @ build (.*)/test.t (re) + \> turbo run build "lint" "--output-logs=none" (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 0 cached, 5 total + Time:\s*[\.0-9ms]+ (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false pnpm run build lint -- --output-logs=none + + \> @ build (.*)/test.t (re) + \> turbo run build "lint" "--output-logs=none" (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 5 cached, 5 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + $ git diff diff --git a/examples-tests/pnpm-kitchen-sink/package.json b/examples-tests/pnpm-kitchen-sink/package.json new file mode 100644 index 00000000000000..56938119ce3e20 --- /dev/null +++ b/examples-tests/pnpm-kitchen-sink/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/pnpm-kitchen-sink", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/pnpm-kitchen-sink/test.t b/examples-tests/pnpm-kitchen-sink/test.t new file mode 100644 index 00000000000000..87f1808b79157f --- /dev/null +++ b/examples-tests/pnpm-kitchen-sink/test.t @@ -0,0 +1,30 @@ + $ . ${TESTDIR}/../setup.sh kitchen-sink pnpm + 6.26.1 +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false pnpm run build lint -- --output-logs=none + + \> @ build (.*)/test.t (re) + \> turbo build "lint" "--output-logs=none" (re) + + \xe2\x80\xa2 Packages in scope: admin, api, blog, eslint-config-custom, eslint-config-custom-server, jest-presets, logger, storefront, tsconfig, ui (esc) + \xe2\x80\xa2 Running build, lint in 10 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 11 successful, 11 total + Cached: 0 cached, 11 total + Time:\s*[\.0-9ms]+ (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false pnpm run build lint -- --output-logs=none + + \> @ build (.*)/test.t (re) + \> turbo build "lint" "--output-logs=none" (re) + + \xe2\x80\xa2 Packages in scope: admin, api, blog, eslint-config-custom, eslint-config-custom-server, jest-presets, logger, storefront, tsconfig, ui (esc) + \xe2\x80\xa2 Running build, lint in 10 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 11 successful, 11 total + Cached: 11 cached, 11 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + $ git diff diff --git a/examples-tests/pnpm-with-svelte/package.json b/examples-tests/pnpm-with-svelte/package.json new file mode 100644 index 00000000000000..76c1152da5508b --- /dev/null +++ b/examples-tests/pnpm-with-svelte/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/pnpm-with-svelte", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/pnpm-with-svelte/test.t b/examples-tests/pnpm-with-svelte/test.t new file mode 100644 index 00000000000000..e362720bd9eeb9 --- /dev/null +++ b/examples-tests/pnpm-with-svelte/test.t @@ -0,0 +1,30 @@ + $ . ${TESTDIR}/../setup.sh with-svelte pnpm + 6.26.1 +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false pnpm run build lint -- --output-logs=none + + \> @ build (.*)/test.t (re) + \> turbo run build "lint" "--output-logs=none" (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 4 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 0 cached, 5 total + Time:\s*[\.0-9ms]+ (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false pnpm run build lint -- --output-logs=none + + \> @ build (.*)/test.t (re) + \> turbo run build "lint" "--output-logs=none" (re) + + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 4 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 5 cached, 5 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + $ git diff diff --git a/turborepo-tests/examples/tests/setup.sh b/examples-tests/setup.sh similarity index 59% rename from turborepo-tests/examples/tests/setup.sh rename to examples-tests/setup.sh index f5c1a31c979e0f..d85e4cada9a6df 100644 --- a/turborepo-tests/examples/tests/setup.sh +++ b/examples-tests/setup.sh @@ -1,12 +1,15 @@ #!/bin/bash -set -e + +# This script is called from within a prysk test, so pwd is already in the prysk tmp directory. + +set -eo pipefail exampleName=$1 pkgManager=$2 # Copy the example dir over to the test dir that prysk puts you in SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") -MONOREPO_ROOT_DIR="$SCRIPT_DIR/../../.." +MONOREPO_ROOT_DIR="$SCRIPT_DIR/.." EXAMPLE_DIR="$MONOREPO_ROOT_DIR/examples/$exampleName" TARGET_DIR="$(pwd)" @@ -34,18 +37,33 @@ function set_package_manager() { NPM_PACKAGE_MANAGER_VALUE="npm@8.1.2" PNPM_PACKAGE_MANAGER_VALUE="pnpm@6.26.1" YARN_PACKAGE_MANAGER_VALUE="yarn@1.22.17" + if [ "$pkgManager" == "npm" ]; then + # Note! We will packageManager for npm, but it doesn't actually change the version + # We are effectively just removing any packageManager that's already set. + # https://nodejs.org/api/corepack.html#how-does-corepack-interact-with-npm + # > "While npm is a valid option in the "packageManager" property, the lack of shim will cause the global npm to be used." set_package_manager "$NPM_PACKAGE_MANAGER_VALUE" - npm install > /dev/null + + npm --version + npm install > /dev/null 2>&1 elif [ "$pkgManager" == "pnpm" ]; then set_package_manager "$PNPM_PACKAGE_MANAGER_VALUE" - pnpm install > /dev/null + pnpm --version + pnpm install > /dev/null 2>&1 elif [ "$pkgManager" == "yarn" ]; then set_package_manager "$YARN_PACKAGE_MANAGER_VALUE" - yarn install > /dev/null + yarn --version + # Pass a --cache-folder here because yarn seems to have trouble + # running multiple yarn installs at the same time and we are running + # examples tests in parallel. https://github.com/yarnpkg/yarn/issues/1275 + yarn install --cache-folder="$PWD/.yarn-cache" > /dev/null 2>&1 + + # And ignore this new cache folder from the new git repo we're about to create. + echo ".yarn-cache" >> .gitignore fi # Delete .git directory if it's there, we'll set up a new git repo [ ! -d .git ] || rm -rf .git -"$MONOREPO_ROOT_DIR/turborepo-tests/helpers/setup_git.sh" "${TARGET_DIR}" +"$MONOREPO_ROOT_DIR/turborepo-tests/helpers/setup_git.sh" "${TARGET_DIR}" "false" diff --git a/examples-tests/yarn-non-monorepo/package.json b/examples-tests/yarn-non-monorepo/package.json new file mode 100644 index 00000000000000..cbc34ab4ee5ee4 --- /dev/null +++ b/examples-tests/yarn-non-monorepo/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/yarn-non-monorepo", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/yarn-non-monorepo/test.t b/examples-tests/yarn-non-monorepo/test.t new file mode 100644 index 00000000000000..c76826fde9b975 --- /dev/null +++ b/examples-tests/yarn-non-monorepo/test.t @@ -0,0 +1,29 @@ + $ . ${TESTDIR}/../setup.sh non-monorepo yarn + 1.22.17 + +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false yarn turbo build lint --output-logs=none + yarn run v1.22.17 + \$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re) + \xe2\x80\xa2 Running build, lint (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 2 successful, 2 total + Cached: 0 cached, 2 total + Time:\s*[\.0-9ms]+ (re) + + Done in [\.0-9]+m?s\. (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false yarn turbo build lint --output-logs=none + yarn run v1.22.17 + \$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re) + \xe2\x80\xa2 Running build, lint (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 2 successful, 2 total + Cached: 2 cached, 2 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + Done in [\.0-9]+m?s\. (re) + + $ git diff diff --git a/examples-tests/yarn-with-npm/package.json b/examples-tests/yarn-with-npm/package.json new file mode 100644 index 00000000000000..79bb6a8b269537 --- /dev/null +++ b/examples-tests/yarn-with-npm/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-examples-tests/yarn-with-npm", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/yarn-with-npm/test.t b/examples-tests/yarn-with-npm/test.t new file mode 100644 index 00000000000000..da25cfd01f2687 --- /dev/null +++ b/examples-tests/yarn-with-npm/test.t @@ -0,0 +1,31 @@ + $ . ${TESTDIR}/../setup.sh with-npm yarn + 1.22.17 + +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false yarn turbo build lint --output-logs=none + yarn run v1.22.17 + \$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re) + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 0 cached, 5 total + Time:\s*[\.0-9ms]+ (re) + + Done in [\.0-9]+m?s\. (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false yarn turbo build lint --output-logs=none + yarn run v1.22.17 + \$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re) + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 5 cached, 5 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + Done in [\.0-9]+m?s\. (re) + + $ git diff diff --git a/examples-tests/yarn-with-yarn/package.json b/examples-tests/yarn-with-yarn/package.json new file mode 100644 index 00000000000000..cf9bfb5e19bfd3 --- /dev/null +++ b/examples-tests/yarn-with-yarn/package.json @@ -0,0 +1,11 @@ +{ + "name": "@turborepo-tests-examples/yarn-with-yarn", + "scripts": { + "example-test": "../.cram_env/bin/prysk --shell=`which bash` test.t" + }, + "dependencies": { + "turborepo-tests-helpers": "workspace:*", + "@turborepo-examples-tests/helpers": "workspace:*", + "turborepo-examples": "workspace:*" + } +} diff --git a/examples-tests/yarn-with-yarn/test.t b/examples-tests/yarn-with-yarn/test.t new file mode 100644 index 00000000000000..77893b7507a6ba --- /dev/null +++ b/examples-tests/yarn-with-yarn/test.t @@ -0,0 +1,31 @@ + $ . ${TESTDIR}/../setup.sh with-yarn yarn + 1.22.17 + +# run twice and make sure it works + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false yarn turbo build lint --output-logs=none + yarn run v1.22.17 + \$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re) + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 0 cached, 5 total + Time:\s*[\.0-9ms]+ (re) + + Done in [\.0-9]+m?s\. (re) + + $ TURBO_TEAM="" TURBO_REMOTE_ONLY=false yarn turbo build lint --output-logs=none + yarn run v1.22.17 + \$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re) + \xe2\x80\xa2 Packages in scope: docs, eslint-config-custom, tsconfig, ui, web (esc) + \xe2\x80\xa2 Running build, lint in 5 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + + Tasks: 5 successful, 5 total + Cached: 5 cached, 5 total + Time:\s*[\.0-9ms]+ >>> FULL TURBO (re) + + Done in [\.0-9]+m?s\. (re) + + $ git diff diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fa05b97dd27ada..c79137ff27b77e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -218,6 +218,109 @@ importers: examples: specifiers: {} + examples-tests/helpers: + specifiers: {} + + examples-tests/npm-non-monorepo: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/npm-with-npm: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/npm-with-yarn: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/pnpm-basic: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/pnpm-gatsby: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/pnpm-kitchen-sink: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/pnpm-with-svelte: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/yarn-non-monorepo: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/yarn-with-npm: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + + examples-tests/yarn-with-yarn: + specifiers: + '@turborepo-examples-tests/helpers': workspace:* + turborepo-examples: workspace:* + turborepo-tests-helpers: workspace:* + dependencies: + '@turborepo-examples-tests/helpers': link:../helpers + turborepo-examples: link:../../examples + turborepo-tests-helpers: link:../../turborepo-tests/helpers + packages/create-turbo: specifiers: '@turbo/test-utils': workspace:* @@ -691,14 +794,6 @@ importers: uvu: 0.5.6 zstd-codec: 0.1.4 - turborepo-tests/examples: - specifiers: - turborepo-examples: workspace:* - turborepo-tests-helpers: workspace:* - dependencies: - turborepo-examples: link:../../examples - turborepo-tests-helpers: link:../helpers - turborepo-tests/helpers: specifiers: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 1a0aa0941d4da1..0d28384e803d90 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,6 +5,7 @@ packages: - "packages/*" - "benchmark" - "turborepo-tests/*" + - "examples-tests/*" # Intentionally exclude the `npm` `turbo` package from the workspaces. - "!packages/turbo" - "packages/turbo-tracing-next-plugin/test/with-mongodb-mongoose" diff --git a/turbo.json b/turbo.json index 494a1595a90a9e..136822c3e9387f 100644 --- a/turbo.json +++ b/turbo.json @@ -27,6 +27,19 @@ "build": { "outputs": ["dist/**/*", ".next/**/*"], "dependsOn": ["^build"] + }, + // This is a synthetic tasks that lets us pull in other workspaces as dependencies + // So changes in internal workspaces that we depend on, will trigger this task. + "topo": { + "dependsOn": ["^topo"] + }, + + // example-tesst is in the root turbo.json so we don't have to redefine in each workspace + // Since they also has a unique set of dependencies, we don't model example tests with the + // test task, or we'd have to override the dependenies in each workspace. + "example-test": { + "dependsOn": ["topo", "@turborepo-examples-tests/helpers#setup"], + "inputs": ["*.t", "../setup.sh"] } }, "experimentalSpaces": { diff --git a/turborepo-tests/examples/package.json b/turborepo-tests/examples/package.json deleted file mode 100644 index c8a245da4b7569..00000000000000 --- a/turborepo-tests/examples/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "turborepo-tests-examples", - "scripts": { - "test": "./run-example.sh" - }, - "dependencies": { - "turborepo-tests-helpers": "workspace:*", - "turborepo-examples": "workspace:*" - } -} diff --git a/turborepo-tests/examples/run-example.sh b/turborepo-tests/examples/run-example.sh deleted file mode 100755 index 9bbcd99cf2c908..00000000000000 --- a/turborepo-tests/examples/run-example.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e - -python3 -m venv .cram_env -.cram_env/bin/pip install prysk - -export folder=$1 -export pkgManager=$2 - -TEST_FILE="tests/$2-$1.t" - -if [ -f "$TEST_FILE" ]; then - echo "Running $TEST_FILE" - .cram_env/bin/prysk --shell="$(which bash)" "$TEST_FILE" -else - echo "Could not find $TEST_FILE" - exit 1 -fi diff --git a/turborepo-tests/examples/tests/npm-non-monorepo.t b/turborepo-tests/examples/tests/npm-non-monorepo.t deleted file mode 100644 index f7aff1aa10461a..00000000000000 --- a/turborepo-tests/examples/tests/npm-non-monorepo.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh non-monorepo npm -# run twice and make sure it works - $ npx turbo build lint > /dev/null 2>&1 - $ npx turbo build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/npm-with-npm.t b/turborepo-tests/examples/tests/npm-with-npm.t deleted file mode 100644 index ad598fc92f70e9..00000000000000 --- a/turborepo-tests/examples/tests/npm-with-npm.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh with-npm npm -# run twice and make sure it works - $ npm run build lint > /dev/null 2>&1 - $ npm run build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/npm-with-yarn.t b/turborepo-tests/examples/tests/npm-with-yarn.t deleted file mode 100644 index 0959af72cc8829..00000000000000 --- a/turborepo-tests/examples/tests/npm-with-yarn.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh with-yarn npm -# run twice and make sure it works - $ npm run build lint > /dev/null 2>&1 - $ npm run build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/pnpm-basic.t b/turborepo-tests/examples/tests/pnpm-basic.t deleted file mode 100644 index 860204f6634df8..00000000000000 --- a/turborepo-tests/examples/tests/pnpm-basic.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh basic pnpm -# run twice and make sure it works - $ pnpm run build lint > /dev/null 2>&1 - $ pnpm run build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/pnpm-gatsby.t b/turborepo-tests/examples/tests/pnpm-gatsby.t deleted file mode 100644 index 2a7c7e3df73e9b..00000000000000 --- a/turborepo-tests/examples/tests/pnpm-gatsby.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh with-gatsby pnpm -# run twice and make sure it works - $ pnpm run build lint > /dev/null 2>&1 - $ pnpm run build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/pnpm-kitchen-sink.t b/turborepo-tests/examples/tests/pnpm-kitchen-sink.t deleted file mode 100644 index 8ad910e223a69e..00000000000000 --- a/turborepo-tests/examples/tests/pnpm-kitchen-sink.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh kitchen-sink pnpm -# run twice and make sure it works - $ pnpm run build lint > /dev/null 2>&1 - $ pnpm run build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/pnpm-with-svelte.t b/turborepo-tests/examples/tests/pnpm-with-svelte.t deleted file mode 100644 index de8059c6068d05..00000000000000 --- a/turborepo-tests/examples/tests/pnpm-with-svelte.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh with-svelte pnpm -# run twice and make sure it works - $ pnpm run build lint > /dev/null 2>&1 - $ pnpm run build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/yarn-non-monorepo.t b/turborepo-tests/examples/tests/yarn-non-monorepo.t deleted file mode 100644 index bf568c053eda8a..00000000000000 --- a/turborepo-tests/examples/tests/yarn-non-monorepo.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh non-monorepo yarn -# run twice and make sure it works - $ npx turbo build lint > /dev/null 2>&1 - $ npx turbo build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/yarn-with-npm.t b/turborepo-tests/examples/tests/yarn-with-npm.t deleted file mode 100644 index ccaa44edde1c9c..00000000000000 --- a/turborepo-tests/examples/tests/yarn-with-npm.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh with-npm yarn -# run twice and make sure it works - $ yarn build lint > /dev/null 2>&1 - $ yarn build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/tests/yarn-with-yarn.t b/turborepo-tests/examples/tests/yarn-with-yarn.t deleted file mode 100644 index 5dc81aead11408..00000000000000 --- a/turborepo-tests/examples/tests/yarn-with-yarn.t +++ /dev/null @@ -1,5 +0,0 @@ - $ . ${TESTDIR}/setup.sh with-yarn yarn -# run twice and make sure it works - $ yarn turbo build lint > /dev/null 2>&1 - $ yarn turbo build lint > /dev/null 2>&1 - $ git diff diff --git a/turborepo-tests/examples/turbo.json b/turborepo-tests/examples/turbo.json deleted file mode 100644 index 3a4ed3341b43fa..00000000000000 --- a/turborepo-tests/examples/turbo.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": ["//"], - "pipeline": { - // This is a synthetic tasks that lets us pull in other workspaces as dependencies - // So changes in internal workspaces that we depend on, will trigger this task. - "topo": { - "dependsOn": ["^topo"] - }, - "test": { - "dependsOn": ["topo"], - "outputs": [] - } - } -} diff --git a/turborepo-tests/helpers/setup_git.sh b/turborepo-tests/helpers/setup_git.sh index b38301162863ca..2ca53d926e5a65 100755 --- a/turborepo-tests/helpers/setup_git.sh +++ b/turborepo-tests/helpers/setup_git.sh @@ -1,11 +1,19 @@ #!/usr/bin/env bash TARGET_DIR=$1 + +# If a second parameter isn't passed, default to true +SHOULD_INSTALL=${2:-true} + git init ${TARGET_DIR} --quiet --initial-branch=main GIT_ARGS="--git-dir=${TARGET_DIR}/.git --work-tree=${TARGET_DIR}" git ${GIT_ARGS} config user.email "turbo-test@example.com" git ${GIT_ARGS} config user.name "Turbo Test" echo "script-shell=$(which bash)" > ${TARGET_DIR}/.npmrc -npm --prefix=${TARGET_DIR} install --silent + +if [ $SHOULD_INSTALL == "true" ]; then + npm --prefix=${TARGET_DIR} install --silent +fi + git ${GIT_ARGS} add . git ${GIT_ARGS} commit -m "Initial" --quiet