From 65e996b70f5d65773748100e12ec00366c576d8c Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 6 Jun 2023 10:17:47 -0700 Subject: [PATCH] Optimize cloning for PR stats (#50859) Follow-up to https://github.com/vercel/next.js/pull/50853 this optimizes how we clone the branches for generating stats. Before: https://github.com/vercel/next.js/actions/runs/5191059058/jobs/9358459062 21min After: https://github.com/vercel/next.js/actions/runs/5191282140/jobs/9358934393?pr=50859 11min --- .github/actions/next-stats-action/src/index.js | 6 ++---- .../actions/next-stats-action/src/prepare/repo-setup.js | 9 ++++----- .github/workflows/trigger_release.yml | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/actions/next-stats-action/src/index.js b/.github/actions/next-stats-action/src/index.js index 23ea3882c5a46..ce7bdd50f91a6 100644 --- a/.github/actions/next-stats-action/src/index.js +++ b/.github/actions/next-stats-action/src/index.js @@ -41,8 +41,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) { // clone PR/newer repository/ref first to get settings if (!actionInfo.skipClone) { - await cloneRepo(actionInfo.prRepo, diffRepoDir) - await checkoutRef(actionInfo.prRef, diffRepoDir) + await cloneRepo(actionInfo.prRepo, diffRepoDir, actionInfo.prRef) } if (actionInfo.isRelease) { @@ -67,8 +66,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) { // clone main repository/ref if (!actionInfo.skipClone) { - await cloneRepo(statsConfig.mainRepo, mainRepoDir) - await checkoutRef(statsConfig.mainBranch, mainRepoDir) + await cloneRepo(statsConfig.mainRepo, mainRepoDir, statsConfig.mainBranch) } /* eslint-disable-next-line */ actionInfo.commitId = await getCommitId(diffRepoDir) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index e64655f4e467e..4b971162bc88c 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -8,12 +8,11 @@ const execa = require('execa') module.exports = (actionInfo) => { return { - async cloneRepo(repoPath = '', dest = '') { + async cloneRepo(repoPath = '', dest = '', branch = '', depth = '20') { await remove(dest) - await exec(`git clone ${actionInfo.gitRoot}${repoPath} ${dest}`) - }, - async checkoutRef(ref = '', repoDir = '') { - await exec(`cd ${repoDir} && git fetch && git checkout ${ref}`) + await exec( + `git clone ${actionInfo.gitRoot}${repoPath} --single-branch --branch ${branch} --depth=${depth} ${dest}` + ) }, async getLastStable(repoDir = '', ref) { const { stdout } = await exec(`cd ${repoDir} && git tag -l`) diff --git a/.github/workflows/trigger_release.yml b/.github/workflows/trigger_release.yml index 000f78e0221a7..c0962d685af22 100644 --- a/.github/workflows/trigger_release.yml +++ b/.github/workflows/trigger_release.yml @@ -49,7 +49,7 @@ jobs: node-version: 18 check-latest: true - - run: git clone https://ijjk:${{ secrets.START_RELEASE_TOKEN }}@github.com/vercel/next.js.git --depth=25 . + - run: git clone https://github.com/vercel/next.js.git --depth=25 . - run: git describe || 'echo failed to get tag'