forked from InsonusK/get-latest-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
74 lines (63 loc) · 2.55 KB
/
index.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as core from '@actions/core'
import * as github from '@actions/github'
async function run(): Promise<void> {
// Get input values
const myToken = core.getInput('myToken');
const excludeReleaseTypes = core.getInput('exclude_types').split('|');
const topList = +core.getInput('view_top');
const repo = core.getInput('repo');
const owner = core.getInput('owner');
// Set parameters
const excludeDraft = excludeReleaseTypes.some(f => f === "draft");
const excludePrerelease = excludeReleaseTypes.some(f => f === "prerelease");
const excludeRelease = excludeReleaseTypes.some(f => f === "release");
const octokit = github.getOctokit(myToken);
// Load release list from GitHub
let releaseList = await octokit.repos.listReleases({
repo: repo,
owner: owner,
per_page: topList,
page: 1
});
// Search release list for latest required release
if (core.isDebug()) {
core.debug(`Found ${releaseList.data.length} releases`);
releaseList.data.forEach((el) => WriteDebug(el));
}
for (let i = 0; i < releaseList.data.length; i++) {
let releaseListElement = releaseList.data[i];
if ((!excludeDraft && releaseListElement.draft) ||
(!excludePrerelease && releaseListElement.prerelease) ||
(!excludeRelease && !releaseListElement.prerelease && !releaseListElement.draft)) {
core.debug(`Chosen: ${releaseListElement.id}`);
setOutput(releaseListElement);
break;
}
}
}
/**
* Setup action output values
* @param release - founded release
*/
function setOutput(release: { id: number, tag_name: string, created_at: string, draft: boolean, prerelease: boolean }): void {
core.setOutput('id', release.id);
core.setOutput('name', release.id);
core.setOutput('tag_name', release.tag_name);
core.setOutput('created_at', release.created_at);
core.setOutput('draft', release.draft);
core.setOutput('prerelease', release.prerelease);
core.setOutput('release', !release.prerelease && !release.draft);
}
/**
* Write debug
* @param release - founded release
*/
function WriteDebug(release: { id: number, tag_name: string, created_at: string, draft: boolean, prerelease: boolean, name: string }): void {
core.debug(`id: ${release.id}`);
core.debug(`name: ${release.name}`)
core.debug(`tag_name: ${release.tag_name}`);
core.debug(`created_at: ${release.created_at}`);
core.debug(`draft: ${release.draft}`);
core.debug(`prerelease: ${release.prerelease}`);
}
run();