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

improve pr stats action #24086

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$2')
: 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
10 changes: 9 additions & 1 deletion packages/next/next-server/server/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// The user isn't configuring webpack
if (!userConfig.webpack) {
Expand All @@ -98,7 +106,7 @@ function reasonMessage(reason: CheckReasons) {
case 'future-flag':
return 'future.webpack5 option enabled'
case 'no-future-flag':
return 'future.webpack5 option not enabled'
return 'future.webpack5 option disabled'
case 'no-config':
return 'no next.config.js'
case 'webpack-config':
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