Skip to content

Commit fd9ec64

Browse files
authored
Use turbo for packing files in test setup (#44074)
1 parent 02489c2 commit fd9ec64

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

Diff for: .github/actions/next-stats-action/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"private": true,
33
"main": "src/index.js",
4+
"scripts": {
5+
"turbo": "turbo"
6+
},
47
"dependencies": {
58
"async-sema": "^3.1.0",
69
"fs-extra": "^8.1.0",
@@ -12,6 +15,7 @@
1215
"prettier": "^1.18.2",
1316
"pretty-bytes": "^5.3.0",
1417
"pretty-ms": "^5.0.0",
15-
"semver": "7.3.4"
18+
"semver": "7.3.4",
19+
"turbo": "1.6.3"
1620
}
1721
}

Diff for: .github/actions/next-stats-action/src/prepare/repo-setup.js

+44-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ const mockTrace = () => ({
1010
traceChild: () => mockTrace(),
1111
})
1212

13+
let turboRepoRoot = path.join(__dirname, '..', '..', '..', '..', '..')
14+
15+
// stats-action runs this code without access to the original repo.
16+
// In that case we just use the temporary directory (everything is temporary anyway in CI)
17+
if (turboRepoRoot === '/') {
18+
turboRepoRoot = path.join(__dirname, '..', '..')
19+
}
20+
21+
/** Save turbo cache to persistent storage */
22+
const turboCacheLocation = path.join(turboRepoRoot, 'node_modules/.cache/turbo')
23+
const packedPkgsDir = path.join(turboRepoRoot, 'test/tmp/packedPkgs')
24+
1325
module.exports = (actionInfo) => {
1426
return {
1527
async cloneRepo(repoPath = '', dest = '') {
@@ -81,9 +93,15 @@ module.exports = (actionInfo) => {
8193
await rootSpan
8294
.traceChild('prepare packages for packing')
8395
.traceAsyncFn(async () => {
96+
await fs.ensureDir(packedPkgsDir)
97+
const repoData = require(path.join(repoDir, 'package.json'))
98+
8499
for (const pkg of pkgs) {
85100
const pkgPath = path.join(repoDir, 'packages', pkg)
86-
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)
101+
const packedPkgPath = path.join(
102+
packedPkgsDir,
103+
`${pkg}-packed.tgz`
104+
)
87105

88106
const pkgDataPath = path.join(pkgPath, 'package.json')
89107
if (!fs.existsSync(pkgDataPath)) {
@@ -103,7 +121,8 @@ module.exports = (actionInfo) => {
103121
}
104122

105123
for (const pkg of pkgDatas.keys()) {
106-
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)
124+
const { pkgDataPath, pkgData, pkgPath, packedPkgPath } =
125+
pkgDatas.get(pkg)
107126

108127
for (const pkg of pkgDatas.keys()) {
109128
const { packedPkgPath } = pkgDatas.get(pkg)
@@ -139,6 +158,27 @@ module.exports = (actionInfo) => {
139158
}
140159
}
141160

161+
// Turbo requires package manager specification
162+
pkgData.packageManager =
163+
pkgData.packageManager || repoData.packageManager
164+
165+
pkgData.scripts = {
166+
...pkgData.scripts,
167+
'test-pack': `yarn pack -f ${packedPkgPath}`,
168+
}
169+
170+
await fs.writeJSON(path.join(pkgPath, 'turbo.json'), {
171+
pipeline: {
172+
'test-pack': {
173+
outputs: [packedPkgPath],
174+
inputs: ['*', '!node_modules/', '!.turbo/'],
175+
},
176+
},
177+
})
178+
179+
// Turbo requires pnpm-lock.yaml that is not empty
180+
await fs.writeFile(path.join(pkgPath, 'pnpm-lock.yaml'), '')
181+
142182
await fs.writeFile(
143183
pkgDataPath,
144184
JSON.stringify(pkgData, null, 2),
@@ -157,9 +197,9 @@ module.exports = (actionInfo) => {
157197
await packingSpan
158198
.traceChild(`pack ${pkgName}`)
159199
.traceAsyncFn(async () => {
160-
const { pkg, pkgPath } = pkgDatas.get(pkgName)
200+
const { pkgPath } = pkgDatas.get(pkgName)
161201
await exec(
162-
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
202+
`pnpm run --dir="${turboRepoRoot}" turbo run test-pack --cache-dir="${turboCacheLocation}" --cwd="${pkgPath}"`,
163203
true
164204
)
165205
})

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": "turbo run build",
1313
"lerna": "lerna",
1414
"dev": "turbo run dev --parallel",
15+
"turbo": "turbo",
1516
"test-types": "pnpm tsc",
1617
"test-unit": "pnpm jest test/unit/",
1718
"test-dev": "cross-env NEXT_TEST_MODE=dev pnpm testheadless",

0 commit comments

Comments
 (0)