diff --git a/.github/actions/next-stats-action/src/constants.js b/.github/actions/next-stats-action/src/constants.js index 2b31994f5dca0fd5cb5fa4a0894a479fee6323da..ba3ec39b2ffd5cadd3cfe32612f83c45b46abed6 100644 --- a/.github/actions/next-stats-action/src/constants.js +++ b/.github/actions/next-stats-action/src/constants.js @@ -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, } diff --git a/.github/actions/next-stats-action/src/index.js b/.github/actions/next-stats-action/src/index.js index add5ab4b525613a9cb97b875da4a26031edcdeda..2bacd52b3501d1f6edf76b098eefa12ae5ebc558 100644 --- a/.github/actions/next-stats-action/src/index.js +++ b/.github/actions/next-stats-action/src/index.js @@ -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) diff --git a/.github/actions/next-stats-action/src/run/index.js b/.github/actions/next-stats-action/src/run/index.js index c1556b13628e9375c640ed5f700ae54cdb125c9b..e8ddf32dea70f862334876ef41bec63d5fee852a 100644 --- a/.github/actions/next-stats-action/src/run/index.js +++ b/.github/actions/next-stats-action/src/run/index.js @@ -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 diff --git a/.github/actions/next-stats-action/src/util/exec.js b/.github/actions/next-stats-action/src/util/exec.js index ea16221b9056b78d55d51991c380735cc9fb3e2a..689bd5b2952aad338c50c1df6f2d98982a796ad8 100644 --- a/.github/actions/next-stats-action/src/util/exec.js +++ b/.github/actions/next-stats-action/src/util/exec.js @@ -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 = {}) {