forked from nrwl/last-successful-commit-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
28 lines (27 loc) · 769 Bytes
/
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
const core = require("@actions/core");
const github = require("@actions/github");
try {
const octokit = github.getOctokit(core.getInput("github_token"));
const owner = github.context.repo.owner
const repo = github.context.repo.repo
octokit.actions
.listWorkflowRuns({
owner,
repo,
workflow_id: core.getInput("workflow_id"),
status: "completed",
branch: core.getInput("branch"),
})
.then((res) => {
const lastSuccessCommitHash =
res.data.workflow_runs.length > 0
? res.data.workflow_runs[0].head_commit.id
: "";
core.setOutput("commit_hash", lastSuccessCommitHash);
})
.catch((e) => {
core.setFailed(e.message);
});
} catch (e) {
core.setFailed(e.message);
}