Skip to content

Commit

Permalink
Update next-swc handling for PR stats (#50933)
Browse files Browse the repository at this point in the history
This fixes the wasm swc build being used for PR stats unexpectedly since
pnpm pack wasn't actually including the swc binary. This also adds a
hard error preventing the wasm swc binary from being leveraged in the
future for PR stats.

x-ref:
[vercel/next.js/actions/runs/5193512579/jobs/9364168639](https://github.com/vercel/next.js/actions/runs/5193512579/jobs/9364168639)
x-ref:
#50853 (comment)

---------

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
ijjk and styfle committed Jun 7, 2023
1 parent 8eb1428 commit 6ef7619
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 52 deletions.
11 changes: 9 additions & 2 deletions .github/actions/next-stats-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
FROM node:16-bullseye
FROM ubuntu:22.04

LABEL com.github.actions.name="Next.js PR Stats"
LABEL com.github.actions.description="Compares stats of a PR with the main branch"
LABEL repository="https://github.com/vercel/next-stats-action"

COPY . /next-stats

RUN apt update && apt upgrade -y
RUN apt install unzip wget curl nano htop screen build-essential pkg-config libssl-dev git build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libreadline-dev libffi-dev python3 moreutils jq iproute2 openssh-server sudo whois dnsutils -y

RUN ln $(which python3) /usr/bin/python

RUN curl -sfLS https://install-node.vercel.app/v18 | bash -s -- -f

# Install node_modules
RUN npm i -g pnpm@7.24.3
RUN npm i -g pnpm@7.24.3 yarn@1.22.19
RUN cd /next-stats && pnpm install --production

RUN git config --global user.email 'stats@localhost'
Expand Down
4 changes: 0 additions & 4 deletions .github/actions/next-stats-action/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ 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 = {
YARN_CACHE_FOLDER: path.join(workDir, 'yarn-cache'),
}
const allowedConfigLocations = [
'./',
'.stats-app',
Expand All @@ -25,6 +22,5 @@ module.exports = {
mainRepoDir,
diffRepoDir,
statsAppDir,
yarnEnvValues,
allowedConfigLocations,
}
3 changes: 3 additions & 0 deletions .github/actions/next-stats-action/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
)
.catch(console.error)

console.log(await exec(`ls ${path.join(__dirname, '../native')}`))
console.log(await exec(`cd ${dir} && ls ${dir}/packages/next-swc/native`))

logger(`Linking packages in ${dir}`)
const isMainRepo = dir === mainRepoDir
const pkgPaths = await linkPackages({
Expand Down
26 changes: 6 additions & 20 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = (actionInfo) => {
}
const pkgData = require(pkgDataPath)
const { name } = pkgData

pkgDatas.set(name, {
pkgDataPath,
pkg,
Expand All @@ -103,7 +104,7 @@ module.exports = (actionInfo) => {
if (!pkgData.files) {
pkgData.files = []
}
pkgData.files.push('native/*')
pkgData.files.push('native')
require('console').log(
'using swc binaries: ',
await exec(`ls ${path.join(path.dirname(pkgDataPath), 'native')}`)
Expand All @@ -124,18 +125,11 @@ module.exports = (actionInfo) => {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native/*')
pkgData.files.push('native')
}
}
}

if (pkgData?.scripts?.prepublishOnly) {
// There's a bug in `pnpm pack` where it will run
// the prepublishOnly script and that will fail.
// See https://github.com/pnpm/pnpm/issues/2941
delete pkgData.scripts.prepublishOnly
}

await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
Expand All @@ -147,21 +141,13 @@ module.exports = (actionInfo) => {
// to the correct versions
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkg, pkgPath, pkgData, packedPkgPath } = pkgDatas.get(pkgName)
// Copied from pnpm source: https://github.com/pnpm/pnpm/blob/5a5512f14c47f4778b8d2b6d957fb12c7ef40127/releasing/plugin-commands-publishing/src/pack.ts#L96
const tmpTarball = path.join(
pkgPath,
`${pkgData.name.replace('@', '').replace('/', '-')}-${
pkgData.version
}.tgz`
)
await execa('pnpm', ['pack'], {
const { pkgPath, packedPkgPath } = pkgDatas.get(pkgName)

await execa('yarn', ['pack', '-f', packedPkgPath], {
cwd: pkgPath,
})
await fs.copyFile(tmpTarball, packedPkgPath)
})
)

return pkgPaths
},
}
Expand Down
25 changes: 4 additions & 21 deletions .github/actions/next-stats-action/src/run/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const path = require('path')
const fs = require('fs-extra')
const getPort = require('get-port')
const glob = require('../util/glob')
const exec = require('../util/exec')
const logger = require('../util/logger')
const getDirSize = require('./get-dir-size')
const collectStats = require('./collect-stats')
const collectDiffs = require('./collect-diffs')
const { statsAppDir, diffRepoDir, yarnEnvValues } = require('../constants')
const { statsAppDir, diffRepoDir } = require('../constants')

async function runConfigs(
configs = [],
Expand Down Expand Up @@ -59,13 +58,7 @@ async function runConfigs(

const buildStart = Date.now()
console.log(
await exec(
`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`,
false,
{
env: yarnEnvValues,
}
)
await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false)
)
curStats.General.buildDuration = Date.now() - buildStart

Expand Down Expand Up @@ -160,13 +153,7 @@ async function runConfigs(

const secondBuildStart = Date.now()
console.log(
await exec(
`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`,
false,
{
env: yarnEnvValues,
}
)
await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false)
)
curStats.General.buildDurationCached = Date.now() - secondBuildStart
}
Expand Down Expand Up @@ -203,13 +190,9 @@ async function linkPkgs(pkgDir = '', pkgPaths) {
}
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgData, null, 2), 'utf8')

await fs.remove(yarnEnvValues.YARN_CACHE_FOLDER)
await exec(
`cd ${pkgDir} && pnpm install --strict-peer-dependencies=false`,
false,
{
env: yarnEnvValues,
}
false
)
}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull_request_stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
NEXT_SKIP_NATIVE_POSTINSTALL: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
NEXT_TEST_JOB: 1
NEXT_DISABLE_SWC_WASM: 1

jobs:
build:
Expand Down
13 changes: 8 additions & 5 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ export async function loadBindings(): Promise<any> {
}

let attempts: any[] = []
const shouldLoadWasmFallbackFirst = triples.some(
(triple: any) =>
!!triple?.raw && knownDefaultWasmFallbackTriples.includes(triple.raw)
)
const disableWasmFallback = process.env.NEXT_DISABLE_SWC_WASM
const shouldLoadWasmFallbackFirst =
!disableWasmFallback &&
triples.some(
(triple: any) =>
!!triple?.raw && knownDefaultWasmFallbackTriples.includes(triple.raw)
)

if (shouldLoadWasmFallbackFirst) {
const fallbackBindings = await tryLoadWasmWithFallback(
Expand All @@ -117,7 +120,7 @@ export async function loadBindings(): Promise<any> {
}

// For these platforms we already tried to load wasm and failed, skip reattempt
if (!shouldLoadWasmFallbackFirst) {
if (!shouldLoadWasmFallbackFirst && !disableWasmFallback) {
const fallbackBindings = await tryLoadWasmWithFallback(
attempts,
isCustomTurbopack
Expand Down

0 comments on commit 6ef7619

Please sign in to comment.