-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
52 lines (43 loc) · 1.63 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
45
46
47
48
49
50
51
52
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
try {
//Get input
const tag = process.env.TAG || process.env.INPUT_TAG || '';
const repoInput = core.getInput('repo') || process.env.GITHUB_REPOSITORY;
console.log(`Searching for tag: ${tag} in ${repoInput}`);
if (!repoInput.includes('/')) {
throw new Error(`${repoInput} is not a valid repo`);
}
// Get owner and repo from context of payload that triggered the action
const [ owner, ...repository ] = repoInput.split('/');
const repo = repository.join('/');
const octokit = github.getOctokit(process.env.GITHUB_TOKEN || core.getInput('github_token'));
var exists = 'false';
try {
const getRefResponse = await octokit.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`
});
if (getRefResponse.status === 200) {
console.log("Tag was found");
exists = 'true';
} else {
core.setFailed("Unknown status was returned: " + getRefResponse.status);
}
} catch(error) {
if (error.status === 404) {
console.log("Tag was not found");
} else {
core.setFailed("Unknown status was returned: " + error.status);
console.error(error);
}
}
core.setOutput('exists', exists);
} catch (error) {
core.setFailed(error.message);
console.error(error);
}
}
run();