Skip to content

Commit

Permalink
improve pr stats action
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Apr 15, 2021
1 parent 8cbcf5b commit 33167d9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/actions/next-stats-action/src/add-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = async function addComment(
else if (!isGzipItem && !groupKey.match(gzipIgnoreRegex)) return

if (
itemKey !== 'buildDuration' ||
!itemKey.startsWith('buildDuration') ||
(isBenchmark && itemKey.match(/req\/sec/))
) {
if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal
Expand Down
48 changes: 29 additions & 19 deletions .github/actions/next-stats-action/src/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function runConfigs(
let curStats = {
General: {
buildDuration: null,
buildDurationCached: null,
nodeModulesSize: null,
},
}
Expand Down Expand Up @@ -55,20 +56,25 @@ async function runConfigs(
)
}

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

// apply renames to get deterministic output names
for (const rename of config.renames) {
const results = await glob(rename.srcGlob, { cwd: statsAppDir })
if (results.length === 0 || results[0] === rename.dest) continue
await fs.move(
path.join(statsAppDir, results[0]),
path.join(statsAppDir, rename.dest)
)
for (const result of results) {
let dest = rename.removeHash
? result.replace(/(\.|-)[0-9a-f]{20}(\.|-)/g, '$1HASH$1')
: rename.dest
if (result === dest) continue
await fs.move(
path.join(statsAppDir, result),
path.join(statsAppDir, dest)
)
}
}

const collectedStats = await collectStats(config, statsConfig)
Expand All @@ -80,19 +86,17 @@ async function runConfigs(
const applyRenames = (renames, stats) => {
if (renames) {
for (const rename of renames) {
let { cur, prev } = rename
cur = path.basename(cur)
prev = path.basename(prev)

Object.keys(stats).forEach((group) => {
Object.keys(stats[group]).forEach((item) => {
let { cur, prev } = rename
cur = path.basename(cur)
prev = path.basename(prev)

if (cur === item) {
stats[group][prev] = stats[group][item]
stats[group][prev + ' gzip'] = stats[group][item + ' gzip']
delete stats[group][item]
delete stats[group][item + ' gzip']
}
})
if (stats[group][cur]) {
stats[group][prev] = stats[group][cur]
stats[group][prev + ' gzip'] = stats[group][cur + ' gzip']
delete stats[group][cur]
delete stats[group][cur + ' gzip']
}
})
}
}
Expand Down Expand Up @@ -146,6 +150,12 @@ async function runConfigs(
/* eslint-disable-next-line */
mainRepoStats = curStats
}

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

logger(`Finished running: ${config.title}`)
Expand Down
58 changes: 29 additions & 29 deletions test/.stats-app/stats-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,17 @@ const renames = [
dest: '.next/static/BUILD_ID/pages',
},
{
srcGlob: '.next/static/runtime/main-*',
dest: '.next/static/runtime/main-HASH.js',
srcGlob: '.next/static/*/pages/**/*',
removeHash: true,
},
{
srcGlob: '.next/static/chunks/main-*',
dest: '.next/static/chunks/main-HASH.js',
srcGlob: '.next/static/runtime/*',
removeHash: true,
},
{
srcGlob: '.next/static/runtime/webpack-*',
dest: '.next/static/runtime/webpack-HASH.js',
srcGlob: '.next/static/chunks/*',
removeHash: true,
},
{
srcGlob: '.next/static/chunks/webpack-*',
dest: '.next/static/chunks/webpack-HASH.js',
},
{
srcGlob: '.next/static/runtime/polyfills-*',
dest: '.next/static/runtime/polyfills-HASH.js',
},
{
srcGlob: '.next/static/chunks/polyfills-*',
dest: '.next/static/chunks/polyfills-HASH.js',
},
{
srcGlob: '.next/static/chunks/commons*',
dest: '.next/static/chunks/commons.HASH.js',
},
{
srcGlob: '.next/static/chunks/framework*',
dest: '.next/static/chunks/framework.HASH.js',
},
// misc
{
srcGlob: '.next/static/*/_buildManifest.js',
dest: '.next/static/BUILD_ID/_buildManifest.js',
Expand All @@ -86,6 +65,9 @@ module.exports = {
content: `
module.exports = {
generateBuildId: () => 'BUILD_ID',
future: {
webpack5: true
},
webpack(config) {
config.optimization.minimize = false
config.optimization.minimizer = undefined
Expand Down Expand Up @@ -148,8 +130,26 @@ module.exports = {
],
},
{
title: 'Webpack 5 Mode',
title: 'Webpack 4 Mode',
diff: 'onOutputChange',
diffConfigFiles: [
{
path: 'next.config.js',
content: `
module.exports = {
generateBuildId: () => 'BUILD_ID',
future: {
webpack5: false
},
webpack(config) {
config.optimization.minimize = false
config.optimization.minimizer = undefined
return config
}
}
`,
},
],
renames,
configFiles: [
{
Expand All @@ -158,7 +158,7 @@ module.exports = {
module.exports = {
generateBuildId: () => 'BUILD_ID',
future: {
webpack5: true
webpack5: false
}
}
`,
Expand Down

0 comments on commit 33167d9

Please sign in to comment.