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') {
|
|
|
|
console.log('✅ - develop build - Proceed to build')
|
2022-12-18 10:00:00 +01:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2023-02-02 13:26:20 -06:00
|
|
|
// Only build pull requests that made changes to org
|
2023-02-02 11:46:31 -06:00
|
|
|
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
|
|
|
|
try {
|
2023-02-11 16:14:31 -06:00
|
|
|
// we need to fetch develop in order to get the merge base
|
|
|
|
execSync(`git fetch origin develop:develop --depth=1`)
|
|
|
|
// now check for changes
|
2023-02-02 11:46:31 -06:00
|
|
|
const changes = execSync(
|
2023-02-11 16:14:31 -06:00
|
|
|
`git diff --name-only $(git merge-base develop HEAD) HEAD -- ../shared .`
|
2023-02-02 11:46:31 -06:00
|
|
|
).toString()
|
|
|
|
if (changes) {
|
2023-02-02 13:26:20 -06:00
|
|
|
console.log('✅ - Org Pull Request - Proceed to build')
|
2023-02-02 11:46:31 -06:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// just don't error out
|
|
|
|
}
|
|
|
|
|
2023-02-02 13:26:20 -06:00
|
|
|
console.log('🛑 - Pull Request made no changes to Org - Do not build')
|
2023-02-02 11:46:31 -06:00
|
|
|
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)
|