Skip to content

Commit

Permalink
chore: make every examples test a workspace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mehulkar committed May 16, 2023
1 parent 7869188 commit 676e97c
Show file tree
Hide file tree
Showing 36 changed files with 404 additions and 117 deletions.
40 changes: 3 additions & 37 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
with:
PATTERNS: |
examples/**
turborepo-tests/examples/**
examples-tests/**
!**.md
!**.mdx
Expand Down Expand Up @@ -322,40 +322,6 @@ 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
Expand Down Expand Up @@ -397,14 +363,14 @@ jobs:
cache: ${{ matrix.manager }}
cache-dependency-path: package.json

- name: Check \"${{ matrix.example }}\" example with \"${{ matrix.manager }}\"
- name: Test examples
shell: bash
env:
FORCE_COLOR: true
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.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/*"

rust_prepare:
name: Check rust crates
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions examples-tests/helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@turborepo-examples-tests/helpers",
"scripts": {
"setup": "./setup_prysk.sh"
}
}
14 changes: 14 additions & 0 deletions examples-tests/helpers/setup_prysk.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions examples-tests/helpers/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["//"],
"pipeline": {
"setup": {},
"topo": {}
}
}
11 changes: 11 additions & 0 deletions examples-tests/npm-non-monorepo/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh non-monorepo yarn
$ . ${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
Expand Down
11 changes: 11 additions & 0 deletions examples-tests/npm-with-npm/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh with-yarn npm
$ . ${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
Expand Down
11 changes: 11 additions & 0 deletions examples-tests/npm-with-yarn/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh with-npm npm
$ . ${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
Expand Down
11 changes: 11 additions & 0 deletions examples-tests/pnpm-basic/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh basic pnpm
$ . ${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
Expand Down
11 changes: 11 additions & 0 deletions examples-tests/pnpm-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@turborepo-examples-tests/pnpm-gatsby",
"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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh with-gatsby pnpm
$ . ${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
Expand Down
11 changes: 11 additions & 0 deletions examples-tests/pnpm-kitchen-sink/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh with-svelte pnpm
$ . ${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
Expand Down
11 changes: 11 additions & 0 deletions examples-tests/pnpm-with-svelte/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ . ${TESTDIR}/setup.sh kitchen-sink pnpm
$ . ${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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
set -e
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)"
Expand All @@ -28,6 +28,7 @@ fi

function set_package_manager() {
cat package.json | jq ".packageManager=\"$1\"" | sponge package.json
corepack enable
}

# Set the packageManger version
Expand All @@ -36,16 +37,19 @@ PNPM_PACKAGE_MANAGER_VALUE="pnpm@6.26.1"
YARN_PACKAGE_MANAGER_VALUE="yarn@1.22.17"
if [ "$pkgManager" == "npm" ]; then
set_package_manager "$NPM_PACKAGE_MANAGER_VALUE"
npm install > /dev/null
npm install > /dev/null 2>&1
elif [ "$pkgManager" == "pnpm" ]; then
set_package_manager "$PNPM_PACKAGE_MANAGER_VALUE"
pnpm install > /dev/null
pnpm install > /dev/null 2>&1
elif [ "$pkgManager" == "yarn" ]; then
set_package_manager "$YARN_PACKAGE_MANAGER_VALUE"
yarn install > /dev/null
# 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"
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"
11 changes: 11 additions & 0 deletions examples-tests/yarn-non-monorepo/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
39 changes: 39 additions & 0 deletions examples-tests/yarn-non-monorepo/test.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$ . ${TESTDIR}/../setup.sh non-monorepo yarn
yarn cache v1.22.17
success Cleared cache.
Done in [\.0-9]+m?s\. (re)
yarn install v1.22.17
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in [\.0-9]+m?s\. (re)
# run twice and make sure it works
$ yarn turbo build lint --output-logs=none
yarn run v1.22.17
\$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re)
• Running build, lint
• Remote caching disabled
Tasks: 2 successful, 2 total
Cached: 0 cached, 2 total
Time:\s*[\.0-9]+m?s (re)
Done in [\.0-9]+m?s\. (re)
$ yarn turbo build lint --output-logs=none
yarn run v1.22.17
\$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re)
• Running build, lint
• Remote caching disabled
Tasks: 2 successful, 2 total
Cached: 2 cached, 2 total
Time:\s*[\.0-9]+m?s >>> FULL TURBO (re)
Done in [\.0-9]+m?s\. (re)
$ git diff
11 changes: 11 additions & 0 deletions examples-tests/yarn-with-npm/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
41 changes: 41 additions & 0 deletions examples-tests/yarn-with-npm/test.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$ . ${TESTDIR}/../setup.sh with-npm yarn
yarn cache v1.22.17
success Cleared cache.
Done in [\.0-9]+m?s\. (re)
yarn install v1.22.17
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in [\.0-9]+m?s\. (re)
# run twice and make sure it works
$ yarn turbo build lint --output-logs=none
yarn run v1.22.17
\$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re)
• Packages in scope: docs, eslint-config-custom, tsconfig, ui, web
• Running build, lint in 5 packages
• Remote caching disabled
Tasks: 5 successful, 5 total
Cached: 0 cached, 5 total
Time:\s*[\.0-9]+m?s (re)
Done in [\.0-9]+m?s\. (re)
$ yarn turbo build lint --output-logs=none
yarn run v1.22.17
\$ (.*)node_modules/.bin/turbo build lint --output-logs=none (re)
• Packages in scope: docs, eslint-config-custom, tsconfig, ui, web
• Running build, lint in 5 packages
• Remote caching disabled
Tasks: 5 successful, 5 total
Cached: 5 cached, 5 total
Time:\s*[\.0-9]+m?s >>> FULL TURBO (re)
Done in [\.0-9]+m?s\. (re)
$ git diff
11 changes: 11 additions & 0 deletions examples-tests/yarn-with-yarn/package.json
Original file line number Diff line number Diff line change
@@ -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:*"
}
}
Loading

0 comments on commit 676e97c

Please sign in to comment.