forked from pozetroninc/github-action-get-latest-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
47 lines (43 loc) · 1.3 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
const core = require('@actions/core');
const { Octokit } = require("@octokit/rest");
const repository = core.getInput('repository');
const token = core.getInput('token');
var owner = core.getInput('owner');
var repo = core.getInput('repo');
var excludes = core.getInput('excludes').trim().split(",");
const octokit = (() => {
if (token) {
return new Octokit({ auth: token,});
} else {
return new Octokit();
}
})();
async function run() {
try {
if (repository){
[owner, repo] = repository.split("/");
}
var releases = await octokit.repos.listReleases({
owner: owner,
repo: repo,
});
releases = releases.data;
if (excludes.includes('prerelease')) {
releases = releases.filter(x => x.prerelease != true);
}
if (excludes.includes('draft')) {
releases = releases.filter(x => x.draft != true);
}
if (releases.length) {
core.setOutput('release', releases[0].tag_name);
core.setOutput('id', String(releases[0].id));
core.setOutput('description', String(releases[0].body));
} else {
core.setFailed("No valid releases");
}
}
catch (error) {
core.setFailed(error.message);
}
}
run()