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
This commit is contained in:
JJ Kasper 2023-06-06 10:17:47 -07:00 committed by GitHub
parent ea74ad0431
commit 65e996b70f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 10 deletions

View file

@ -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)

View file

@ -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`)

View file

@ -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'