forked from olegtarasov/get-tag
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
36 lines (34 loc) · 1.08 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
const core = require('@actions/core')
const github = require('@actions/github')
async function run () {
try {
const ref = github.context.ref
const tagPath = 'refs/tags/'
if (ref && ref.startsWith(tagPath)) {
let tag = ref.substr(tagPath.length, ref.length)
const regexStr = core.getInput('tagRegex')
if (regexStr) {
const regex = new RegExp(regexStr)
const groupIdx = parseInt(core.getInput('tagRegexGroup') || '1')
const result = regex.exec(tag)
if (result && result.length > groupIdx) {
tag = result[groupIdx]
} else {
core.warning(`Failed to match regex '${regexStr}' in tag string '${tag}'. Result is '${result}'`)
return
}
// Return named groups on output
if (result.groups) {
for (const [key, value] of Object.entries(result.groups)) {
core.setOutput(key, value)
}
}
}
core.exportVariable('GIT_TAG_NAME', tag)
core.setOutput('tag', tag)
}
} catch (error) {
core.setFailed(error.message)
}
}
run()