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

Revert "Fix release stats" #45164

Merged
merged 12 commits into from
Jan 29, 2023
Merged
11 changes: 4 additions & 7 deletions .github/actions/next-stats-action/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const path = require('path')
const os = require('os')
const fs = require('fs')
jankaifer marked this conversation as resolved.
Show resolved Hide resolved

const benchTitle = 'Page Load Tests'
const workDir = path.join(os.tmpdir(), 'next-stats')
const mainRepoName = 'main-repo'
const diffRepoName = 'diff-repo'
const mainRepoDir = path.join(workDir, mainRepoName)
const diffRepoDir = path.join(workDir, diffRepoName)
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'next-stats'))
const mainRepoDir = path.join(workDir, 'main-repo')
const diffRepoDir = path.join(workDir, 'diff-repo')
const statsAppDir = path.join(workDir, 'stats-app')
const diffingDir = path.join(workDir, 'diff')
const yarnEnvValues = {
Expand All @@ -23,8 +22,6 @@ module.exports = {
benchTitle,
workDir,
diffingDir,
mainRepoName,
diffRepoName,
mainRepoDir,
diffRepoDir,
statsAppDir,
Expand Down
153 changes: 20 additions & 133 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,140 +55,27 @@ module.exports = (actionInfo) => {
}
},
async linkPackages({ repoDir, nextSwcVersion }) {
let hasTestPack = false

try {
hasTestPack = Boolean(
((await fs.readJSON(path.join(repoDir, 'package.json'))).scripts ||
{})['test-pack']
)
} catch (err) {
console.error(err)
}

if (hasTestPack) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})

const pkgPaths = new Map()
const pkgs = (await fs.readdir(path.join(repoDir, 'packages'))).filter(
(item) => !item.startsWith('.')
)

pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(
repoDir,
'packages',
pkgDirname,
`packed-${pkgDirname}.tgz`
)
)
})
return pkgPaths
} else {
// TODO: remove after next stable release (current v13.1.2)
const pkgPaths = new Map()
const pkgDatas = new Map()
let pkgs

try {
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('no packages to link')
return pkgPaths
}
throw err
}

for (const pkg of pkgs) {
const pkgPath = path.join(repoDir, 'packages', pkg)
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)

const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
require('console').log(`Skipping ${pkgDataPath}`)
continue
}
const pkgData = require(pkgDataPath)
const { name } = pkgData
pkgDatas.set(name, {
pkgDataPath,
pkg,
pkgPath,
pkgData,
packedPkgPath,
})
pkgPaths.set(name, packedPkgPath)
}

for (const pkg of pkgDatas.keys()) {
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)

for (const pkg of pkgDatas.keys()) {
const { packedPkgPath } = pkgDatas.get(pkg)
if (!pkgData.dependencies || !pkgData.dependencies[pkg]) continue
pkgData.dependencies[pkg] = packedPkgPath
}

// make sure native binaries are included in local linking
if (pkg === '@next/swc') {
if (!pkgData.files) {
pkgData.files = []
}
pkgData.files.push('native')
require('console').log(
'using swc binaries: ',
await exec(`ls ${path.join(path.dirname(pkgDataPath), 'native')}`)
)
}

if (pkg === 'next') {
if (nextSwcVersion) {
Object.assign(pkgData.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native')
}
}
}

await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
)
}

// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkg, pkgPath } = pkgDatas.get(pkgName)
await exec(
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
true
)
})
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})

const pkgPaths = new Map()
const pkgs = await fs.readdir(path.join(repoDir, 'packages'))

pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(repoDir, 'packages', pkgDirname, `packed-${pkgDirname}.tgz`)
)

return pkgPaths
}
})
return pkgPaths
},
}
}