-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignore_build.mjs
53 lines (43 loc) · 1.33 KB
/
ignore_build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// We only want Netlify to build the site if a PR changes files in this directory (./docs).
// See https://docs.netlify.com/configure-builds/ignore-builds.
// Netlify runs this via Node.js v16.
import { execSync } from 'node:child_process'
function main() {
const branch = process.env.BRANCH
// Reproduce the default behavior for main.
// See https://docs.netlify.com/configure-builds/ignore-builds/#mimic-default-behavior.
// `execSync` throws if the process times out or has a non-zero exit code.
if (branch === 'main') {
try {
execSync('git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF')
} catch (error) {
process.exitCode = 1
return
}
}
const changedFiles = execSync(
'git diff --name-only $CACHED_COMMIT_REF $COMMIT_REF'
)
.toString()
.trim()
.split('\n')
.filter(Boolean)
console.log({
changedFiles,
})
const shouldBuild = changedFiles.some((changedFile) =>
changedFile.startsWith('docs')
)
if (shouldBuild) {
console.log(
`PR '${process.env.HEAD}' has docs changes. Proceeding with build`
)
process.exitCode = 1
return
}
console.log(`PR '${process.env.HEAD}' doesn't have doc changes. Ignoring`)
}
const dashes = '-'.repeat(10)
console.log(`${dashes} IGNORE BUILD START ${dashes}`)
main()
console.log(`${dashes} IGNORE BUILD END ${dashes}`)