From e04019bee903dee2a021f9321b0b818a1f8bf3f8 Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Fri, 16 Dec 2022 09:49:59 +0100 Subject: [PATCH 01/10] Pack packages in test setup with turbo --- .../src/prepare/repo-setup.js | 40 +++++++++++++++++-- .gitignore | 3 ++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 3034d47fc1747ac..e6dd054546fd250 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -10,6 +10,13 @@ const mockTrace = () => ({ traceChild: () => mockTrace(), }) +const nextjsRepoRoot = path.join(__dirname, '../../../../../') +/** Save turbo cache to persistent storage */ +const turboCacheLocation = path.join( + nextjsRepoRoot, + 'node_modules/.cache/turbo' +) + module.exports = (actionInfo) => { return { async cloneRepo(repoPath = '', dest = '') { @@ -81,9 +88,16 @@ module.exports = (actionInfo) => { await rootSpan .traceChild('prepare packages for packing') .traceAsyncFn(async () => { + const repoData = require(path.join(repoDir, 'package.json')) + for (const pkg of pkgs) { const pkgPath = path.join(repoDir, 'packages', pkg) - const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`) + const packedPkgPath = path.join( + nextjsRepoRoot, + 'packages', + pkg, + `${pkg}-packed.tgz` + ) const pkgDataPath = path.join(pkgPath, 'package.json') if (!fs.existsSync(pkgDataPath)) { @@ -103,7 +117,8 @@ module.exports = (actionInfo) => { } for (const pkg of pkgDatas.keys()) { - const { pkgDataPath, pkgData } = pkgDatas.get(pkg) + const { pkgDataPath, pkgData, pkgPath, packedPkgPath } = + pkgDatas.get(pkg) for (const pkg of pkgDatas.keys()) { const { packedPkgPath } = pkgDatas.get(pkg) @@ -139,6 +154,23 @@ module.exports = (actionInfo) => { } } + // Turbo requires package manager specification + pkgData.packageManager ??= repoData.packageManager + + pkgData.scripts ??= {} + pkgData.scripts['test-pack'] = `yarn pack -f ${packedPkgPath}` + await fs.writeJSON(path.join(pkgPath, 'turbo.json'), { + pipeline: { + 'test-pack': { + outputs: [packedPkgPath], + inputs: ['*', '!node_modules/', '!.turbo/'], + }, + }, + }) + + // Turbo requires pnpm-lock.yaml that is not empty + await fs.writeFile(path.join(pkgPath, 'pnpm-lock.yaml'), '') + await fs.writeFile( pkgDataPath, JSON.stringify(pkgData, null, 2), @@ -156,9 +188,9 @@ module.exports = (actionInfo) => { await packingSpan .traceChild(`pack ${pkgName}`) .traceAsyncFn(async () => { - const { pkg, pkgPath } = pkgDatas.get(pkgName) + const { pkgPath } = pkgDatas.get(pkgName) await exec( - `cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`, + `cd ${pkgPath} && turbo run test-pack --cache-dir="${turboCacheLocation}"`, true ) }) diff --git a/.gitignore b/.gitignore index 6bbbba1173fd1c3..b6a457036d8fcb5 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,9 @@ test/**/tsconfig.json test/tmp/** test/.trace +# Packing packages during tests +packages/*/*-packed.tgz + # Editors **/.idea **/.#* From 306376a5799401f09ef831879211766488dfcf61 Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Fri, 16 Dec 2022 15:21:49 +0100 Subject: [PATCH 02/10] Move packed pkgs destination to test/tmp --- .github/actions/next-stats-action/src/prepare/repo-setup.js | 6 +++--- .gitignore | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index e6dd054546fd250..c78bb3f6e8980a6 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -16,6 +16,7 @@ const turboCacheLocation = path.join( nextjsRepoRoot, 'node_modules/.cache/turbo' ) +const packedPkgsDir = path.join(nextjsRepoRoot, 'test/tmp/packedPkgs') module.exports = (actionInfo) => { return { @@ -88,14 +89,13 @@ module.exports = (actionInfo) => { await rootSpan .traceChild('prepare packages for packing') .traceAsyncFn(async () => { + await fs.ensureDir(packedPkgsDir) const repoData = require(path.join(repoDir, 'package.json')) for (const pkg of pkgs) { const pkgPath = path.join(repoDir, 'packages', pkg) const packedPkgPath = path.join( - nextjsRepoRoot, - 'packages', - pkg, + packedPkgsDir, `${pkg}-packed.tgz` ) diff --git a/.gitignore b/.gitignore index b6a457036d8fcb5..6bbbba1173fd1c3 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,6 @@ test/**/tsconfig.json test/tmp/** test/.trace -# Packing packages during tests -packages/*/*-packed.tgz - # Editors **/.idea **/.#* From ddb594e9fda5feea17e8c6e804275610158ed73f Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Mon, 19 Dec 2022 12:06:26 +0100 Subject: [PATCH 03/10] use turbo package from next.js project --- .github/actions/next-stats-action/src/prepare/repo-setup.js | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index dea200de3f4130f..380b1a0592ebb9c 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -191,7 +191,7 @@ module.exports = (actionInfo) => { .traceAsyncFn(async () => { const { pkgPath } = pkgDatas.get(pkgName) await exec( - `cd ${pkgPath} && turbo run test-pack --cache-dir="${turboCacheLocation}"`, + `cd ${pkgPath} && pnpm run --dir=${nextjsRepoRoot} turbo run test-pack --cache-dir="${turboCacheLocation}"`, true ) }) diff --git a/package.json b/package.json index 690163865715ff2..945bcc81b2b0539 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "build": "turbo run build", "lerna": "lerna", "dev": "turbo run dev --parallel", + "turbo": "turbo", "test-types": "pnpm tsc", "test-unit": "pnpm jest test/unit/", "test-dev": "cross-env NEXT_TEST_MODE=dev pnpm testheadless", From e4b2fe57f54f883192eae6b7712d50a383543f72 Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Mon, 19 Dec 2022 12:58:04 +0100 Subject: [PATCH 04/10] make sure turbo runs in the correct folder --- .github/actions/next-stats-action/src/prepare/repo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 380b1a0592ebb9c..a25837c8b0555e7 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -191,7 +191,7 @@ module.exports = (actionInfo) => { .traceAsyncFn(async () => { const { pkgPath } = pkgDatas.get(pkgName) await exec( - `cd ${pkgPath} && pnpm run --dir=${nextjsRepoRoot} turbo run test-pack --cache-dir="${turboCacheLocation}"`, + `pnpm run --dir="${nextjsRepoRoot}" turbo run test-pack --cache-dir="${turboCacheLocation}" --cwd="${pkgPath}"`, true ) }) From 2c938147a98df83def869d80430a275ad6dc3aa4 Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Mon, 19 Dec 2022 13:12:10 +0100 Subject: [PATCH 05/10] use ||= instead of ??= we need to support older node versions --- .github/actions/next-stats-action/src/prepare/repo-setup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index a25837c8b0555e7..41d6d4affc50dcb 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -155,9 +155,9 @@ module.exports = (actionInfo) => { } // Turbo requires package manager specification - pkgData.packageManager ??= repoData.packageManager + pkgData.packageManager ||= repoData.packageManager - pkgData.scripts ??= {} + pkgData.scripts ||= {} pkgData.scripts['test-pack'] = `yarn pack -f ${packedPkgPath}` await fs.writeJSON(path.join(pkgPath, 'turbo.json'), { pipeline: { From dec021f6de8b7b1ac7e002ddd9cf356759ba5e4c Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Tue, 20 Dec 2022 10:10:24 +0100 Subject: [PATCH 06/10] remove logical assigment - unsupported in node v14 --- .../next-stats-action/src/prepare/repo-setup.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 41d6d4affc50dcb..d811402596e19d2 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -155,10 +155,14 @@ module.exports = (actionInfo) => { } // Turbo requires package manager specification - pkgData.packageManager ||= repoData.packageManager + pkgData.packageManager = + pkgData.packageManager || repoData.packageManager + + pkgData.scripts = { + ...pkgData.scripts, + 'test-pack': `yarn pack -f ${packedPkgPath}`, + } - pkgData.scripts ||= {} - pkgData.scripts['test-pack'] = `yarn pack -f ${packedPkgPath}` await fs.writeJSON(path.join(pkgPath, 'turbo.json'), { pipeline: { 'test-pack': { From 66bd18fa7b75c4375ad6fa9a63f3663c8bbb88ae Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Tue, 20 Dec 2022 10:14:24 +0100 Subject: [PATCH 07/10] Add `turbo` as dependency for stats-action --- .github/actions/next-stats-action/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/next-stats-action/package.json b/.github/actions/next-stats-action/package.json index 4d2e88dae3e3e66..26cf5d34735b762 100644 --- a/.github/actions/next-stats-action/package.json +++ b/.github/actions/next-stats-action/package.json @@ -12,6 +12,7 @@ "prettier": "^1.18.2", "pretty-bytes": "^5.3.0", "pretty-ms": "^5.0.0", - "semver": "7.3.4" + "semver": "7.3.4", + "turbo": "1.6.3" } } From a0abf126c0d971d78009d37c392b4158ff9a84cf Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Tue, 20 Dec 2022 12:05:02 +0100 Subject: [PATCH 08/10] Fix turboreporoot location in genereta stats action --- .../src/prepare/repo-setup.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index d811402596e19d2..149eed89b7e5a49 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -10,13 +10,17 @@ const mockTrace = () => ({ traceChild: () => mockTrace(), }) -const nextjsRepoRoot = path.join(__dirname, '../../../../../') +let turboRepoRoot = path.join(__dirname, '..', '..', '..', '..', '..') + +// stats-action runs this code without access to the original repo. +// In that case we just use the temporary directory (everything is temporary anyway in CI) +if (turboRepoRoot === '/') { + turboRepoRoot = path.join(__dirname, '..', '..', '..') +} + /** Save turbo cache to persistent storage */ -const turboCacheLocation = path.join( - nextjsRepoRoot, - 'node_modules/.cache/turbo' -) -const packedPkgsDir = path.join(nextjsRepoRoot, 'test/tmp/packedPkgs') +const turboCacheLocation = path.join(turboRepoRoot, 'node_modules/.cache/turbo') +const packedPkgsDir = path.join(turboRepoRoot, 'test/tmp/packedPkgs') module.exports = (actionInfo) => { return { @@ -195,7 +199,7 @@ module.exports = (actionInfo) => { .traceAsyncFn(async () => { const { pkgPath } = pkgDatas.get(pkgName) await exec( - `pnpm run --dir="${nextjsRepoRoot}" turbo run test-pack --cache-dir="${turboCacheLocation}" --cwd="${pkgPath}"`, + `pnpm run --dir="${turboRepoRoot}" turbo run test-pack --cache-dir="${turboCacheLocation}" --cwd="${pkgPath}"`, true ) }) From cf607b2c61ddece971f319ab32e1670197e65eb2 Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Tue, 20 Dec 2022 12:05:56 +0100 Subject: [PATCH 09/10] fix relative path to action root --- .github/actions/next-stats-action/src/prepare/repo-setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 149eed89b7e5a49..9db46ce48df0e04 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -15,7 +15,7 @@ let turboRepoRoot = path.join(__dirname, '..', '..', '..', '..', '..') // stats-action runs this code without access to the original repo. // In that case we just use the temporary directory (everything is temporary anyway in CI) if (turboRepoRoot === '/') { - turboRepoRoot = path.join(__dirname, '..', '..', '..') + turboRepoRoot = path.join(__dirname, '..', '..') } /** Save turbo cache to persistent storage */ From 39ce3eee31fb4c811ec035c38b4a9794875e8924 Mon Sep 17 00:00:00 2001 From: Jan Kaifer Date: Tue, 20 Dec 2022 13:01:51 +0100 Subject: [PATCH 10/10] add turbo script to next-stats-action --- .github/actions/next-stats-action/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/next-stats-action/package.json b/.github/actions/next-stats-action/package.json index 26cf5d34735b762..3949a110476ff35 100644 --- a/.github/actions/next-stats-action/package.json +++ b/.github/actions/next-stats-action/package.json @@ -1,6 +1,9 @@ { "private": true, "main": "src/index.js", + "scripts": { + "turbo": "turbo" + }, "dependencies": { "async-sema": "^3.1.0", "fs-extra": "^8.1.0",