forked from Script-Hub-Org/Script-Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignored-build-step.js
43 lines (33 loc) · 1.34 KB
/
ignored-build-step.js
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
const childProcess = require('child_process')
const path = require('path')
// https://vercel.com/support/articles/how-do-i-use-the-ignored-build-step-field-on-vercel
const ABORT_BUILD_CODE = 0
const CONTINUE_BUILD_CODE = 1
const continueBuild = () => process.exit(CONTINUE_BUILD_CODE)
const abortBuild = () => process.exit(ABORT_BUILD_CODE)
const app = process.argv[2] || path.basename(path.resolve())
const stepCheck = () => {
// no app name (directory) was passed in via args
if (!app) {
return abortBuild()
}
// get all file names changed in last commit
// const fileNameList = childProcess
// .execSync("git diff --name-only HEAD~1")
// .toString()
// .trim()
// .split("\n");
// This modification checks against the previous successful deploy commit SHA, which is provided by vercel now. (https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables)
const fileNameList = childProcess
.execSync(`git diff ${process.env.VERCEL_GIT_PREVIOUS_SHA} HEAD --name-only ./`)
.toString()
.trim()
.split('\n')
// check if any files in the app, or in any shared packages have changed
const shouldBuild = fileNameList.some(file => file.startsWith(`script-hub`) || file.startsWith('preview'))
if (shouldBuild) {
return continueBuild()
}
return abortBuild()
}
stepCheck()