-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.42 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
53
54
55
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 response = await octokit.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`
});
if (response.status === 200) {
console.log("Tag was found");
exists = "true";
} else {
core.setFailed("Unexpected status was returned: " + response.status);
}
} catch (error) {
if (error.status === 404) {
console.log("Tag was not found");
} else {
core.setFailed("Unexpected status was returned: " + error.status);
console.error(error);
}
}
core.setOutput("exists", exists);
} catch (error) {
core.setFailed(error.message);
console.error(error);
}
}
run();