-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.ts
77 lines (66 loc) · 2.62 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
75
76
77
import * as core from '@actions/core'
import * as github from '@actions/github'
import { components } from '@octokit/openapi-types/types'
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');
// 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.rest.repos.listReleases({
repo: github.context.repo.repo,
owner: github.context.repo.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: components["schemas"]["release"]): void {
core.setOutput('id', release.id);
core.setOutput('name', release.name);
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);
core.setOutput('url', release.url);
core.setOutput('html_url', release.html_url);
}
/**
* Write debug
* @param release - founded release
*/
function WriteDebug(release: components["schemas"]["release"]): 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}`);
core.debug(`url: ${release.url}`)
core.debug(`html_url: ${release.html_url}`)
}
run();