limit the number of times skip_build deepens merge-base check
This commit is contained in:
parent
82b9ae1aee
commit
86f8a32e78
1 changed files with 19 additions and 7 deletions
|
@ -2,7 +2,7 @@ import process from 'node:process'
|
||||||
import { execSync } from 'child_process'
|
import { execSync } from 'child_process'
|
||||||
|
|
||||||
export const shouldSkipBuild = (siteName, checkFolders = '../shared .') => {
|
export const shouldSkipBuild = (siteName, checkFolders = '../shared .') => {
|
||||||
console.log('Skip build script version 1.0.0')
|
console.log('Skip build script version 1.1.0')
|
||||||
|
|
||||||
// Do not block production builds
|
// Do not block production builds
|
||||||
if (process.env.VERCEL_ENV === 'production') {
|
if (process.env.VERCEL_ENV === 'production') {
|
||||||
|
@ -38,10 +38,22 @@ export const shouldSkipBuild = (siteName, checkFolders = '../shared .') => {
|
||||||
)
|
)
|
||||||
// we need to fetch develop in order to get the merge base
|
// we need to fetch develop in order to get the merge base
|
||||||
execSync(`git fetch origin develop:develop --depth=5`)
|
execSync(`git fetch origin develop:develop --depth=5`)
|
||||||
|
|
||||||
|
let hasMerge = ''
|
||||||
|
for (let a = 0; a < 5; a++) {
|
||||||
|
try {
|
||||||
|
hasMerge = execSync(`git merge-base develop HEAD`).toString()
|
||||||
|
break
|
||||||
|
} catch {
|
||||||
// if depth 5 wasn't enough, keep deepening until we find the merge base
|
// if depth 5 wasn't enough, keep deepening until we find the merge base
|
||||||
execSync(
|
execSync(`git fetch origin develop:develop --deepen=1`)
|
||||||
`until git merge-base develop HEAD > /dev/null; do git fetch origin develop:develop --deepen=1; done`
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
|
if (!hasMerge.length) {
|
||||||
|
console.log(`🛑 - Can't find merge base for pull request - Do not build`)
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
// now check for changes
|
// now check for changes
|
||||||
const changes = execSync(
|
const changes = execSync(
|
||||||
|
@ -51,8 +63,8 @@ export const shouldSkipBuild = (siteName, checkFolders = '../shared .') => {
|
||||||
console.log(`✅ - ${siteName} Pull Request - Proceed to build`)
|
console.log(`✅ - ${siteName} Pull Request - Proceed to build`)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (e) {
|
||||||
// just don't error out
|
console.log(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`🛑 - Pull Request made no changes to ${siteName} - Do not build`)
|
console.log(`🛑 - Pull Request made no changes to ${siteName} - Do not build`)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue