1
0
Fork 0

refine skip build logic to build relevant pull requests

This commit is contained in:
Enoch Riese 2023-02-02 11:46:31 -06:00
parent 4a84343b64
commit a1cc978207
4 changed files with 92 additions and 13 deletions

View file

@ -1,4 +1,5 @@
import process from 'node:process'
import { execSync } from 'child_process'
const branches = ['develop', 'joost']
@ -14,13 +15,32 @@ if (process.env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN === 'dependabot[bot]') {
process.exit(0)
}
// Do not build anything that is not the develop branch
if (branches.includes(process.env.VERCEL_GIT_COMMIT_REF)) {
console.log('✅ - elected branch build - Proceed to build')
const branch = process.env.VERCEL_GIT_COMMIT_REF
// Always build develop branch
if (branch === 'develop') {
console.log('✅ - develop build - Proceed to build')
process.exit(1)
}
// Only build pull requests that made changes to lab
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
try {
const changes = execSync(
`git diff --name-only $(git merge-base develop ${branch}) ${branch} sites/shared/ sites/org`
).toString()
if (changes) {
console.log('✅ - Lab Pull Request - Proceed to build')
process.exit(1)
}
} catch {
// just don't error out
}
console.log('🛑 - Pull Request made no changes to Lab - Do not build')
process.exit(0)
}
console.log('🛑 - Unhandled case - Do not build')
console.log(` VERCEL_GIT_COMMIT_AUTHOR_LOGIN: ${process.env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN}`)
console.log(` VERCEL_GIT_COMMIT_REF: ${process.env.VERCEL_GIT_COMMIT_REF}`)
console.log(` VERCEL_GIT_COMMIT_REF: ${branch}`)
process.exit(0)