-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathhasChanged.js
41 lines (32 loc) · 917 Bytes
/
hasChanged.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
const exec = require('@actions/exec')
async function main(pathsToSearch = '') {
throwsForInvalidPaths(pathsToSearch)
return hasChanged(pathsToSearch)
}
function throwsForInvalidPaths(pathsToSearch) {
if (pathsToSearch && typeof pathsToSearch === 'string') return
throw new Error('pathsToSearch needs to be a string')
}
function getCWD() {
const { GITHUB_WORKSPACE = '.', SOURCE = '.' } = process.env
return `${GITHUB_WORKSPACE}/${SOURCE}`
}
async function hasChanged(pathsToSearch) {
const paths = pathsToSearch.split(' ')
// --quiet: exits with 1 if there were differences (https://git-scm.com/docs/git-diff)
const exitCode = await exec.exec('git', [
'diff',
'--quiet',
'HEAD~1',
'HEAD',
'--',
...paths,
], {
ignoreReturnCode: true,
silent: false,
cwd: getCWD()
})
const pathsChanged = exitCode === 1
return pathsChanged
}
module.exports = main