Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use turbo for packing files in test setup #44074

Merged
merged 15 commits into from Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 36 additions & 4 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Expand Up @@ -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 = '') {
Expand Down Expand Up @@ -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(
jankaifer marked this conversation as resolved.
Show resolved Hide resolved
nextjsRepoRoot,
'packages',
pkg,
`${pkg}-packed.tgz`
)

const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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
)
})
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -30,6 +30,9 @@ test/**/tsconfig.json
test/tmp/**
test/.trace

# Packing packages during tests
packages/*/*-packed.tgz

# Editors
**/.idea
**/.#*
Expand Down