2022-12-18 10:00:00 +01:00
|
|
|
import process from 'node:process'
|
2023-02-02 11:46:31 -06:00
|
|
|
import { execSync } from 'child_process'
|
2022-12-18 10:00:00 +01:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2023-02-02 11:46:31 -06:00
|
|
|
const branch = process.env.VERCEL_GIT_COMMIT_REF
|
|
|
|
// Always build develop branch
|
|
|
|
if (branch === 'develop') {
|
2022-12-18 10:00:00 +01:00
|
|
|
console.log('✅ - develop build - Proceed to build')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2023-02-02 11:46:31 -06:00
|
|
|
// 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/lab`
|
|
|
|
).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)
|
|
|
|
}
|
|
|
|
|
2022-12-18 10:00:00 +01:00
|
|
|
console.log('🛑 - Unhandled case - Do not build')
|
|
|
|
console.log(` VERCEL_GIT_COMMIT_AUTHOR_LOGIN: ${process.env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN}`)
|
2023-02-02 11:46:31 -06:00
|
|
|
console.log(` VERCEL_GIT_COMMIT_REF: ${branch}`)
|
2022-12-18 10:00:00 +01:00
|
|
|
process.exit(0)
|