Unverified Commit 1c2ee7c6 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

improve pr stats action (#24086)

* add cache build duration tracking
* default = webpack 5
* better hash handling
* allow to opt-out of webpack5 via `future.webpack5: false`
parent 1797fc50
...@@ -83,7 +83,7 @@ module.exports = async function addComment( ...@@ -83,7 +83,7 @@ module.exports = async function addComment(
else if (!isGzipItem && !groupKey.match(gzipIgnoreRegex)) return else if (!isGzipItem && !groupKey.match(gzipIgnoreRegex)) return
if ( if (
itemKey !== 'buildDuration' || !itemKey.startsWith('buildDuration') ||
(isBenchmark && itemKey.match(/req\/sec/)) (isBenchmark && itemKey.match(/req\/sec/))
) { ) {
if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal
......
...@@ -26,6 +26,7 @@ async function runConfigs( ...@@ -26,6 +26,7 @@ async function runConfigs(
let curStats = { let curStats = {
General: { General: {
buildDuration: null, buildDuration: null,
buildDurationCached: null,
nodeModulesSize: null, nodeModulesSize: null,
}, },
} }
...@@ -55,20 +56,25 @@ async function runConfigs( ...@@ -55,20 +56,25 @@ async function runConfigs(
) )
} }
const buildStart = new Date().getTime() const buildStart = Date.now()
await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false, { await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false, {
env: yarnEnvValues, env: yarnEnvValues,
}) })
curStats.General.buildDuration = new Date().getTime() - buildStart curStats.General.buildDuration = Date.now() - buildStart
// apply renames to get deterministic output names // apply renames to get deterministic output names
for (const rename of config.renames) { for (const rename of config.renames) {
const results = await glob(rename.srcGlob, { cwd: statsAppDir }) const results = await glob(rename.srcGlob, { cwd: statsAppDir })
if (results.length === 0 || results[0] === rename.dest) continue for (const result of results) {
await fs.move( let dest = rename.removeHash
path.join(statsAppDir, results[0]), ? result.replace(/(\.|-)[0-9a-f]{20}(\.|-)/g, '$1HASH$2')
path.join(statsAppDir, rename.dest) : rename.dest
) if (result === dest) continue
await fs.move(
path.join(statsAppDir, result),
path.join(statsAppDir, dest)
)
}
} }
const collectedStats = await collectStats(config, statsConfig) const collectedStats = await collectStats(config, statsConfig)
...@@ -80,19 +86,17 @@ async function runConfigs( ...@@ -80,19 +86,17 @@ async function runConfigs(
const applyRenames = (renames, stats) => { const applyRenames = (renames, stats) => {
if (renames) { if (renames) {
for (const rename of 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).forEach((group) => {
Object.keys(stats[group]).forEach((item) => { if (stats[group][cur]) {
let { cur, prev } = rename stats[group][prev] = stats[group][cur]
cur = path.basename(cur) stats[group][prev + ' gzip'] = stats[group][cur + ' gzip']
prev = path.basename(prev) delete stats[group][cur]
delete stats[group][cur + ' gzip']
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']
}
})
}) })
} }
} }
...@@ -146,6 +150,12 @@ async function runConfigs( ...@@ -146,6 +150,12 @@ async function runConfigs(
/* eslint-disable-next-line */ /* eslint-disable-next-line */
mainRepoStats = curStats 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}`) logger(`Finished running: ${config.title}`)
......
...@@ -78,6 +78,14 @@ export async function shouldLoadWithWebpack5( ...@@ -78,6 +78,14 @@ export async function shouldLoadWithWebpack5(
} }
} }
// Opted-out manually
if (userConfig.future?.webpack5 === false) {
return {
enabled: false,
reason: 'no-future-flag',
}
}
// Uncomment to add auto-enable when there is no custom webpack config // Uncomment to add auto-enable when there is no custom webpack config
// The user isn't configuring webpack // The user isn't configuring webpack
if (!userConfig.webpack) { if (!userConfig.webpack) {
...@@ -98,7 +106,7 @@ function reasonMessage(reason: CheckReasons) { ...@@ -98,7 +106,7 @@ function reasonMessage(reason: CheckReasons) {
case 'future-flag': case 'future-flag':
return 'future.webpack5 option enabled' return 'future.webpack5 option enabled'
case 'no-future-flag': case 'no-future-flag':
return 'future.webpack5 option not enabled' return 'future.webpack5 option disabled'
case 'no-config': case 'no-config':
return 'no next.config.js' return 'no next.config.js'
case 'webpack-config': case 'webpack-config':
......
...@@ -30,38 +30,17 @@ const renames = [ ...@@ -30,38 +30,17 @@ const renames = [
dest: '.next/static/BUILD_ID/pages', dest: '.next/static/BUILD_ID/pages',
}, },
{ {
srcGlob: '.next/static/runtime/main-*', srcGlob: '.next/static/*/pages/**/*',
dest: '.next/static/runtime/main-HASH.js', removeHash: true,
}, },
{ {
srcGlob: '.next/static/chunks/main-*', srcGlob: '.next/static/runtime/*',
dest: '.next/static/chunks/main-HASH.js', removeHash: true,
}, },
{ {
srcGlob: '.next/static/runtime/webpack-*', srcGlob: '.next/static/chunks/*',
dest: '.next/static/runtime/webpack-HASH.js', 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', srcGlob: '.next/static/*/_buildManifest.js',
dest: '.next/static/BUILD_ID/_buildManifest.js', dest: '.next/static/BUILD_ID/_buildManifest.js',
...@@ -86,6 +65,9 @@ module.exports = { ...@@ -86,6 +65,9 @@ module.exports = {
content: ` content: `
module.exports = { module.exports = {
generateBuildId: () => 'BUILD_ID', generateBuildId: () => 'BUILD_ID',
future: {
webpack5: true
},
webpack(config) { webpack(config) {
config.optimization.minimize = false config.optimization.minimize = false
config.optimization.minimizer = undefined config.optimization.minimizer = undefined
...@@ -148,8 +130,26 @@ module.exports = { ...@@ -148,8 +130,26 @@ module.exports = {
], ],
}, },
{ {
title: 'Webpack 5 Mode', title: 'Webpack 4 Mode',
diff: 'onOutputChange', 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, renames,
configFiles: [ configFiles: [
{ {
...@@ -158,7 +158,7 @@ module.exports = { ...@@ -158,7 +158,7 @@ module.exports = {
module.exports = { module.exports = {
generateBuildId: () => 'BUILD_ID', generateBuildId: () => 'BUILD_ID',
future: { future: {
webpack5: true webpack5: false
} }
} }
`, `,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment