-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1.47 KB
/
index.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
44
const core = require('@actions/core');
const { execSync } = require('child_process');
(async () => {
try {
const path = core.getInput('path')
const gitPoint = core.getInput('git-point')
console.log(`Path for verification: ${path}`)
console.log(`Git point for verification: ${gitPoint}`)
const paths = getChangedPaths(gitPoint)
console.log(paths)
const pathChanged = paths.some(element => element.startsWith(path))
console.log(`Path changed: ${pathChanged}`)
core.setOutput("path-changed", pathChanged)
} catch (error) {
core.setFailed(error.message)
}
})()
function getChangedPaths(gitPoint) {
try {
let latestPoint = gitPoint
console.log(`Provided tag: ${latestPoint}`)
if (!latestPoint) {
latestPoint = execSync('git tag --list --sort=-version:refname "v*" --merged | head -n 1').toString().trim()
console.log(`Latest tag: ${latestPoint}`)
}
if (!latestPoint) {
let latestPoint = execSync('git tag --list --sort=-version:refname "v*" --merged | head -n 1').toString().trim()
atestPoint = execSync('git rev-list --max-parents=0 HEAD').toString().trim()
console.log(`Getting changed paths since the commit: ${latestPoint}`)
}
return execSync(`git diff --name-only ${latestPoint}`).toString().trim().split(/\r?\n/)
} catch(e) {
console.error(e)
}
}