forked from dawidd6/action-get-tag
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
36 lines (28 loc) · 776 Bytes
/
main.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")
async function main() {
try {
const ref = process.env.GITHUB_REF
const strip_v = process.env.INPUT_STRIP_V
const default_version = process.env.INPUT_DEFAULT
let tag
if(!ref)
throw "GITHUB_REF is not defined"
if(ref.startsWith("refs/tags/"))
tag = ref.replace(/^refs\/tags\//, "")
else if(default_version)
tag = default_version
else
throw `Not a tag ref (${ref}) or default version not set`
if(!tag)
throw `No tag version found`
if(strip_v === "true" && tag.startsWith("v"))
tag = tag.replace(/^v/, "")
core.info(`ref=${ref}`)
core.info(`tag=${tag}`)
core.setOutput("tag", tag);
}
catch (error) {
core.setFailed(error);
}
}
main()