44 lines
1.3 KiB
JavaScript
Executable file
44 lines
1.3 KiB
JavaScript
Executable file
import process from 'node:process'
|
|
import { execSync } from 'child_process'
|
|
|
|
// Do not block production builds
|
|
if (process.env.VERCEL_ENV === 'production') {
|
|
console.log('✅ - Production build - Proceed to build')
|
|
process.exit(1)
|
|
}
|
|
|
|
// Do not build dependabot PRs
|
|
if (process.env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN === 'dependabot[bot]') {
|
|
console.log('🛑 - Dependebot PR - Do not build')
|
|
process.exit(0)
|
|
}
|
|
|
|
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 dev
|
|
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
|
|
try {
|
|
const changes = execSync(
|
|
`git diff --name-only $(git merge-base origin/develop HEAD) HEAD -- sites/shared/ sites/dev`
|
|
).toString()
|
|
if (changes) {
|
|
console.log('✅ - Dev Pull Request - Proceed to build')
|
|
process.exit(1)
|
|
}
|
|
} catch {
|
|
// just don't error out
|
|
}
|
|
|
|
console.log('🛑 - Pull Request made no changes to Dev - 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: ${branch}`)
|
|
process.exit(0)
|