未验证 提交 10fda8a9 编写于 作者: J JJ Kasper 提交者: GitHub

Update stats action for running locally (#14143)

Noticed a few things that could be updated to make running the stats locally better e.g. if the folder name didn't match the name of the repo in the `stats-config.js` file it would fail to run and the `yarn` cache could break diffing from a cached package being used instead
上级 6163f30a
......@@ -8,6 +8,9 @@ const mainRepoDir = path.join(workDir, mainRepoName)
const diffRepoDir = path.join(workDir, diffRepoName)
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',
......@@ -24,5 +27,6 @@ module.exports = {
mainRepoDir,
diffRepoDir,
statsAppDir,
yarnEnvValues,
allowedConfigLocations,
}
......@@ -46,6 +46,12 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
)
}
if (actionInfo.isLocal) {
// make sure to use local repo location instead of the
// one provided in statsConfig
statsConfig.mainRepo = actionInfo.prRepo
}
// clone main repository/ref
if (!actionInfo.skipClone) {
await cloneRepo(statsConfig.mainRepo, mainRepoDir)
......
......@@ -6,7 +6,7 @@ const logger = require('../util/logger')
const getDirSize = require('./get-dir-size')
const collectStats = require('./collect-stats')
const collectDiffs = require('./collect-diffs')
const { statsAppDir, diffRepoDir, mainRepoDir } = require('../constants')
const { statsAppDir, diffRepoDir, yarnEnvValues } = require('../constants')
async function runConfigs(
configs = [],
......@@ -32,12 +32,7 @@ async function runConfigs(
// if stats-config is in root of project we're analyzing
// the whole project so copy from each repo
const curStatsAppPath =
relativeStatsAppDir === './'
? mainRepoStats
? diffRepoDir
: mainRepoDir
: path.join(diffRepoDir, relativeStatsAppDir)
const curStatsAppPath = path.join(diffRepoDir, relativeStatsAppDir)
// clean statsAppDir
await fs.remove(statsAppDir)
......@@ -61,7 +56,9 @@ async function runConfigs(
}
const buildStart = new Date().getTime()
await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`)
await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false, {
env: yarnEnvValues,
})
curStats.General.buildDuration = new Date().getTime() - buildStart
// apply renames to get deterministic output names
......@@ -182,7 +179,11 @@ async function linkPkgs(pkgDir = '', pkgPaths) {
}
}
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgData, null, 2), 'utf8')
await exec(`cd ${pkgDir} && yarn install`)
await fs.remove(yarnEnvValues.YARN_CACHE_FOLDER)
await exec(`cd ${pkgDir} && yarn install`, false, {
env: yarnEnvValues,
})
}
module.exports = runConfigs
......@@ -9,9 +9,13 @@ const env = {
PR_STATS_COMMENT_TOKEN: '',
}
function exec(command, noLog = false) {
function exec(command, noLog = false, opts = {}) {
if (!noLog) logger(`exec: ${command}`)
return execP(command, { env, timeout: 180 * 1000 })
return execP(command, {
timeout: 180 * 1000,
...opts,
env: { ...env, ...opts.env },
})
}
exec.spawn = function spawn(command = '', opts = {}) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册