forked from mukunku/tag-exists-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 1001 Bytes
/
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
const core = require('@actions/core');
const { context, GitHub } = require('@actions/github');
async function run() {
try {
//Get input
const tag = process.env.TAG || process.env.INPUT_TAG || '';
console.log(`Searching for tag: ${tag}`);
// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo
const github = new GitHub(process.env.GITHUB_TOKEN);
var exists = 'false';
try {
const getRefResponse = await github.git.getRef({
owner,
repo,
ref: `tags/${tag}`
});
if (getRefResponse.status === 200) {
console.log("Tag was found");
exists = 'true';
}
} catch(error) {
console.log("Tag was not found");
}
core.setOutput('exists', exists);
} catch (error) {
core.setFailed(error.message);
}
}
run();