centralized skip_build script with real working git commands
This commit is contained in:
parent
c28891abc3
commit
a48ba26698
5 changed files with 68 additions and 190 deletions
60
scripts/skip-build-base.mjs
Normal file
60
scripts/skip-build-base.mjs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import process from 'node:process'
|
||||||
|
import { execSync } from 'child_process'
|
||||||
|
|
||||||
|
export const shouldSkipBuild = (siteName, checkFolders = '../shared .') => {
|
||||||
|
console.log('Skip build script version 1.0.0')
|
||||||
|
|
||||||
|
// 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('🛑 - Dependabot 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 the given site
|
||||||
|
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
|
||||||
|
try {
|
||||||
|
// we need to add the origin so that we can compare to develop
|
||||||
|
execSync(
|
||||||
|
`git remote add origin https://github.com/${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}.git`
|
||||||
|
)
|
||||||
|
// we need to fetch develop in order to get the merge base
|
||||||
|
execSync(`git fetch origin develop:develop --depth=5`)
|
||||||
|
// if depth 5 wasn't enough, keep deepening until we find the merge base
|
||||||
|
execSync(
|
||||||
|
`until git merge-base develop HEAD > /dev/null; do git fetch origin develop:develop --deepen=1; done`
|
||||||
|
)
|
||||||
|
|
||||||
|
// now check for changes
|
||||||
|
const changes = execSync(
|
||||||
|
`git diff --name-only $(git merge-base develop HEAD) HEAD -- ${checkFolders}`
|
||||||
|
).toString()
|
||||||
|
if (changes) {
|
||||||
|
console.log(`✅ - ${siteName} Pull Request - Proceed to build`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// just don't error out
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`🛑 - Pull Request made no changes to ${siteName} - 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)
|
||||||
|
}
|
|
@ -1,47 +1,3 @@
|
||||||
import process from 'node:process'
|
import { shouldSkipBuild } from '../../scripts/skip-build-base.mjs'
|
||||||
import { execSync } from 'child_process'
|
|
||||||
|
|
||||||
// Do not block production builds
|
shouldSkipBuild('Dev')
|
||||||
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 {
|
|
||||||
// we need to fetch develop in order to get the merge base
|
|
||||||
execSync(`git fetch origin develop:develop --depth=1`)
|
|
||||||
// now check for changes
|
|
||||||
const changes = execSync(
|
|
||||||
`git diff --name-only $(git merge-base develop HEAD) HEAD -- ../shared .`
|
|
||||||
).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)
|
|
||||||
|
|
|
@ -1,54 +1,3 @@
|
||||||
import process from 'node:process'
|
import { shouldSkipBuild } from '../../scripts/skip-build-base.mjs'
|
||||||
import { execSync } from 'child_process'
|
|
||||||
|
|
||||||
// Do not block production builds
|
shouldSkipBuild('Lab')
|
||||||
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('🛑 - Dependabot 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 lab
|
|
||||||
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
|
|
||||||
try {
|
|
||||||
// we need to fetch develop in order to get the merge base
|
|
||||||
console.log('skip build version 1')
|
|
||||||
execSync(
|
|
||||||
`git remote add origin https://github.com/${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}.git`
|
|
||||||
)
|
|
||||||
execSync(`git fetch origin develop:develop --depth=10`)
|
|
||||||
execSync(
|
|
||||||
`until git merge-base develop HEAD > /dev/null; do git fetch origin develop:develop --deepen=1; done`
|
|
||||||
)
|
|
||||||
// now check for changes
|
|
||||||
const changes = execSync(
|
|
||||||
`git diff --name-only $(git merge-base develop HEAD) HEAD -- ../shared .`
|
|
||||||
).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: ${branch}`)
|
|
||||||
process.exit(0)
|
|
||||||
|
|
|
@ -1,47 +1,3 @@
|
||||||
import process from 'node:process'
|
import { shouldSkipBuild } from '../../scripts/skip-build-base.mjs'
|
||||||
import { execSync } from 'child_process'
|
|
||||||
|
|
||||||
// Do not block production builds
|
shouldSkipBuild('Org')
|
||||||
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 org
|
|
||||||
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
|
|
||||||
try {
|
|
||||||
// we need to fetch develop in order to get the merge base
|
|
||||||
execSync(`git fetch origin develop:develop --depth=1`)
|
|
||||||
// now check for changes
|
|
||||||
const changes = execSync(
|
|
||||||
`git diff --name-only $(git merge-base develop HEAD) HEAD -- ../shared .`
|
|
||||||
).toString()
|
|
||||||
if (changes) {
|
|
||||||
console.log('✅ - Org Pull Request - Proceed to build')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// just don't error out
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('🛑 - Pull Request made no changes to Org - 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)
|
|
||||||
|
|
|
@ -1,50 +1,7 @@
|
||||||
|
import { shouldSkipBuild } from '../../scripts/skip-build-base.mjs'
|
||||||
import process from 'node:process'
|
import process from 'node:process'
|
||||||
import { execSync } from 'child_process'
|
|
||||||
|
|
||||||
// For now, never build CMS
|
// For now, never build CMS
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
|
||||||
// Do not block production builds
|
shouldSkipBuild('Sanity', '.')
|
||||||
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 sanity
|
|
||||||
if (process.env.VERCEL_GIT_PULL_REQUEST_ID) {
|
|
||||||
try {
|
|
||||||
// we need to fetch develop in order to get the merge base
|
|
||||||
execSync(`git fetch origin develop:develop --depth=1`)
|
|
||||||
// now check for changes
|
|
||||||
const changes = execSync(
|
|
||||||
`git diff --name-only $(git merge-base develop HEAD) HEAD -- .`
|
|
||||||
).toString()
|
|
||||||
if (changes) {
|
|
||||||
console.log('✅ - Sanity Pull Request - Proceed to build')
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// just don't error out
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('🛑 - Pull Request made no changes to Sanity - 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)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue