Skip to content

Commit

Permalink
Merge branch 'canary' into dvoytenko/otel-internal-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 12, 2023
2 parents d58bf5b + 8013ef7 commit 10ebe5b
Show file tree
Hide file tree
Showing 134 changed files with 3,035 additions and 2,538 deletions.
5 changes: 2 additions & 3 deletions .github/actions/next-stats-action/package.json
Expand Up @@ -4,7 +4,6 @@
"dependencies": {
"async-sema": "^3.1.0",
"execa": "2.0.3",
"fs-extra": "^8.1.0",
"get-port": "^5.0.0",
"glob": "^7.1.4",
"gzip-size": "^5.1.1",
Expand All @@ -20,7 +19,7 @@
},
"engines": {
"node": ">=16.14.0",
"pnpm": "8.7.1"
"pnpm": "8.9.0"
},
"packageManager": "pnpm@8.7.1"
"packageManager": "pnpm@8.9.0"
}
39 changes: 25 additions & 14 deletions .github/actions/next-stats-action/src/add-comment.js
Expand Up @@ -24,6 +24,8 @@ const shortenLabel = (itemKey) =>
: itemKey

const twoMB = 2 * 1024 * 1024
const ONE_HUNDRED_BYTES = 100
const ONE_HUNDRED_MS = 100

module.exports = async function addComment(
results = [],
Expand Down Expand Up @@ -82,24 +84,21 @@ module.exports = async function addComment(
// otherwise only show gzip values
else if (!isGzipItem && !groupKey.match(gzipIgnoreRegex)) return

if (
!itemKey.startsWith('buildDuration') ||
(isBenchmark && itemKey.match(/req\/sec/))
) {
if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal
if (typeof diffItemVal === 'number') diffRepoTotal += diffItemVal
}

// calculate the change
if (mainItemVal !== diffItemVal) {
if (
typeof mainItemVal === 'number' &&
typeof diffItemVal === 'number'
) {
change = round(diffItemVal - mainItemVal, 2)
const roundedValue = round(diffItemVal - mainItemVal, 2)

// check if there is still a change after rounding
if (change !== 0) {
if (
roundedValue !== 0 &&
((prettyType === 'ms' && roundedValue > ONE_HUNDRED_MS) ||
(prettyType === 'bytes' && roundedValue > ONE_HUNDRED_BYTES))
) {
change = roundedValue
const absChange = Math.abs(change)
const warnIfNegative = isBenchmark && itemKey.match(/req\/sec/)
const warn = warnIfNegative
Expand All @@ -112,12 +111,22 @@ module.exports = async function addComment(
change = `${warn}${change < 0 ? '-' : '+'}${
useRawValue ? absChange : prettify(absChange, prettyType)
}`
} else {
change = 'N/A'
}
} else {
change = 'N/A'
}
}

if (
(change !== 'N/A' && !itemKey.startsWith('buildDuration')) ||
(isBenchmark && itemKey.match(/req\/sec/))
) {
if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal
if (typeof diffItemVal === 'number') diffRepoTotal += diffItemVal
}

groupTable += `| ${
isBenchmark ? itemKey : shortenLabel(itemKey)
} | ${mainItemStr} | ${diffItemStr} | ${change} |\n`
Expand Down Expand Up @@ -169,8 +178,7 @@ module.exports = async function addComment(

// add diffs
if (result.diffs) {
const diffHeading = '#### Diffs\n'
let diffContent = diffHeading
let diffContent = ''

Object.keys(result.diffs).forEach((itemKey) => {
const curDiff = result.diffs[itemKey]
Expand All @@ -187,8 +195,11 @@ module.exports = async function addComment(
diffContent += `\n</details>\n`
})

if (diffContent !== diffHeading) {
if (diffContent.length > 0) {
resultContent += `<details>\n`
resultContent += `<summary><strong>Diff details</strong></summary>\n\n`
resultContent += diffContent
resultContent += `\n</details>\n\n`
}
}
let increaseDecreaseNote = ''
Expand All @@ -199,7 +210,7 @@ module.exports = async function addComment(
increaseDecreaseNote = ' (Decrease detected ✓)'
}

comment += `<details>\n`
comment += `<details open>\n`
comment += `<summary><strong>${result.title}</strong>${increaseDecreaseNote}</summary>\n\n<br/>\n\n`
comment += resultContent
comment += '</details>\n'
Expand Down
15 changes: 7 additions & 8 deletions .github/actions/next-stats-action/src/index.js
@@ -1,5 +1,6 @@
const path = require('path')
const fs = require('fs-extra')
const fs = require('fs/promises')
const { existsSync } = require('fs')
const exec = require('./util/exec')
const logger = require('./util/logger')
const runConfigs = require('./run')
Expand All @@ -21,7 +22,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {

;(async () => {
try {
if (await fs.pathExists(path.join(__dirname, '../SKIP_NEXT_STATS.txt'))) {
if (existsSync(path.join(__dirname, '../SKIP_NEXT_STATS.txt'))) {
console.log(
'SKIP_NEXT_STATS.txt file present, exiting stats generation..'
)
Expand Down Expand Up @@ -100,7 +101,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
for (const dir of repoDirs) {
logger(`Running initial build for ${dir}`)
if (!actionInfo.skipClone) {
const usePnpm = await fs.pathExists(path.join(dir, 'pnpm-lock.yaml'))
const usePnpm = existsSync(path.join(dir, 'pnpm-lock.yaml'))

if (!statsConfig.skipInitialInstall) {
await exec.spawnPromise(
Expand All @@ -121,15 +122,13 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
}

await fs
.copy(
.cp(
path.join(__dirname, '../native'),
path.join(dir, 'packages/next-swc/native')
path.join(dir, 'packages/next-swc/native'),
{ recursive: true, force: true }
)
.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
24 changes: 11 additions & 13 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
@@ -1,16 +1,14 @@
const path = require('path')
const fse = require('fs-extra')
const fs = require('fs')
const fsp = require('fs/promises')
const fs = require('fs/promises')
const { existsSync } = require('fs')
const exec = require('../util/exec')
const { remove } = require('fs-extra')
const logger = require('../util/logger')
const execa = require('execa')

module.exports = (actionInfo) => {
return {
async cloneRepo(repoPath = '', dest = '', branch = '', depth = '20') {
await remove(dest)
await fs.rm(dest, { recursive: true, force: true })
await exec(
`git clone ${actionInfo.gitRoot}${repoPath} --single-branch --branch ${branch} --depth=${depth} ${dest}`
)
Expand Down Expand Up @@ -72,7 +70,7 @@ module.exports = (actionInfo) => {
let pkgs

try {
pkgs = await fsp.readdir(path.join(repoDir, 'packages'))
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('no packages to link')
Expand All @@ -87,8 +85,8 @@ module.exports = (actionInfo) => {
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)

const pkgDataPath = path.join(pkgPath, 'package.json')
if (fs.existsSync(pkgDataPath)) {
const pkgData = JSON.parse(await fsp.readFile(pkgDataPath))
if (existsSync(pkgDataPath)) {
const pkgData = JSON.parse(await fs.readFile(pkgDataPath))
const { name } = pkgData

pkgDatas.set(name, {
Expand Down Expand Up @@ -122,7 +120,7 @@ module.exports = (actionInfo) => {
pkgData.files.push('native')

try {
const swcBinariesDirContents = await fsp.readdir(
const swcBinariesDirContents = await fs.readdir(
path.join(pkgPath, 'native')
)
require('console').log(
Expand Down Expand Up @@ -155,7 +153,7 @@ module.exports = (actionInfo) => {
}
}

await fsp.writeFile(
await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
Expand Down Expand Up @@ -186,9 +184,9 @@ module.exports = (actionInfo) => {
'disabled-native-gitignore'
)

await fsp.rename(nativeGitignorePath, renamedGitignorePath)
await fs.rename(nativeGitignorePath, renamedGitignorePath)
cleanup = async () => {
await fsp.rename(renamedGitignorePath, nativeGitignorePath)
await fs.rename(renamedGitignorePath, nativeGitignorePath)
}
}

Expand All @@ -201,7 +199,7 @@ module.exports = (actionInfo) => {
})

return Promise.all([
fsp.rename(path.resolve(pkgPath, stdout.trim()), packedPkgPath),
fs.rename(path.resolve(pkgPath, stdout.trim()), packedPkgPath),
cleanup?.(),
])
}
Expand Down
64 changes: 56 additions & 8 deletions .github/actions/next-stats-action/src/run/collect-diffs.js
@@ -1,5 +1,6 @@
const path = require('path')
const fs = require('fs-extra')
const fs = require('fs/promises')
const { existsSync } = require('fs')
const exec = require('../util/exec')
const glob = require('../util/glob')
const logger = require('../util/logger')
Expand All @@ -12,15 +13,17 @@ module.exports = async function collectDiffs(
if (initial) {
logger('Setting up directory for diffing')
// set-up diffing directory
await fs.remove(diffingDir)
await fs.mkdirp(diffingDir)
await fs.rm(diffingDir, { recursive: true, force: true })
await fs.mkdir(diffingDir, { recursive: true })
await exec(`cd ${diffingDir} && git init`)
} else {
// remove any previous files in case they won't be overwritten
const toRemove = await glob('!(.git)', { cwd: diffingDir, dot: true })

await Promise.all(
toRemove.map((file) => fs.remove(path.join(diffingDir, file)))
toRemove.map((file) =>
fs.rm(path.join(diffingDir, file), { recursive: true, force: true })
)
)
}
const diffs = {}
Expand All @@ -40,7 +43,7 @@ module.exports = async function collectDiffs(
const absPath = path.join(statsAppDir, file)

const diffDest = path.join(diffingDir, file)
await fs.copy(absPath, diffDest)
await fs.cp(absPath, diffDest, { recursive: true, force: true })
}

if (curFiles.length > 0) {
Expand Down Expand Up @@ -75,7 +78,7 @@ module.exports = async function collectDiffs(

for (const line of renamedFiles) {
const [, prev, cur] = line.split('\t')
await fs.move(path.join(diffingDir, cur), path.join(diffingDir, prev))
await fs.rename(path.join(diffingDir, cur), path.join(diffingDir, prev))
diffs._renames.push({
prev,
cur,
Expand All @@ -91,7 +94,7 @@ module.exports = async function collectDiffs(

for (const file of changedFiles) {
const fileKey = path.basename(file)
const hasFile = await fs.exists(path.join(diffingDir, file))
const hasFile = existsSync(path.join(diffingDir, file))

if (!hasFile) {
diffs[fileKey] = 'deleted'
Expand All @@ -103,7 +106,7 @@ module.exports = async function collectDiffs(
`cd ${diffingDir} && git diff --minimal HEAD ${file}`
)
stdout = (stdout.split(file).pop() || '').trim()
if (stdout.length > 0) {
if (stdout.length > 0 && !isLikelyHashOrIDChange(stdout)) {
diffs[fileKey] = stdout
}
} catch (err) {
Expand All @@ -114,3 +117,48 @@ module.exports = async function collectDiffs(
}
return diffs
}

function isLikelyHashOrIDChange(diff) {
const lines = diff.split('\n')
let additions = []
let deletions = []

// Separate additions and deletions
for (const line of lines) {
if (line.startsWith('+')) {
additions.push(line.substring(1).split(/\b/))
} else if (line.startsWith('-')) {
deletions.push(line.substring(1).split(/\b/))
}
}

// If the number of additions and deletions is different, it's not a hash or ID change
if (additions.length !== deletions.length) {
return false
}

// Compare each addition with each deletion
for (let i = 0; i < additions.length; i++) {
const additionTokens = additions[i]
const deletionTokens = deletions[i]

// Identify differing tokens
const differingTokens = additionTokens.filter(
(token, index) => token !== deletionTokens[index]
)

// Analyze differing tokens
for (const token of differingTokens) {
const isLikelyHash = /^[a-f0-9]+$/.test(token)
const isLikelyID = /^[0-9]+$/.test(token)
// this is most likely noise because some path include the repo name, which can be main or diff
const isLikelyNoise = ['main', 'diff'].includes(token)

if (!isLikelyHash && !isLikelyID && !isLikelyNoise) {
return false
}
}
}

return true
}
4 changes: 2 additions & 2 deletions .github/actions/next-stats-action/src/run/collect-stats.js
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs-extra')
const fs = require('fs/promises')
const getPort = require('get-port')
const fetch = require('node-fetch')
const glob = require('../util/glob')
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = async function collectStats(

if (hasPagesToFetch) {
const fetchedPagesDir = path.join(curDir, 'fetched-pages')
await fs.mkdirp(fetchedPagesDir)
await fs.mkdir(fetchedPagesDir, { recursive: true })

for (let url of runConfig.pagesToFetch) {
url = url.replace('$PORT', port)
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/next-stats-action/src/run/get-dir-size.js
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs-extra')
const fs = require('fs/promises')

// getDirSize recursively gets size of all files in a directory
async function getDirSize(dir, ctx = { size: 0 }) {
Expand Down

0 comments on commit 10ebe5b

Please sign in to comment.