-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (53 loc) · 1.36 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
import * as core from "@actions/core";
import * as github from "@actions/github";
async function action() {
const token = core.getInput("token");
const owner = core.getInput("org");
const repo = core.getInput("repo");
const workflow_id = core.getInput("workflow_id");
if (workflow_id === "") {
throw new Error("Invalid workflow_id provided");
}
const octokit = github.getOctokit(token);
/* cspell: disable-next-line */
const tagsResults = await octokit.rest.repos.listTags({
owner,
repo,
per_page: 1,
});
let ref = undefined;
if (
tagsResults &&
tagsResults.status === 200 &&
tagsResults.data.length === 1
) {
ref = tagsResults.data[0].name;
}
if (ref === undefined) {
core.setFailed(`Could not determined latest tag for target repo`);
return;
}
core.info(
`Dispatching workflow '${workflow_id}' in '${repo}' with ref '${ref}'`
);
const result = await octokit.request(
/* cspell: disable-next-line */
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
{
owner,
repo,
workflow_id,
ref,
}
);
if (result.status !== 204) {
core.setFailed(`Action failed with status ${result.status}`);
return;
}
}
action().catch((reason) => {
if (reason instanceof Error) {
core.error(reason);
}
core.setFailed(`An unknown error occurred`);
});