forked from nrwl/last-successful-commit-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (27 loc) · 772 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, repo] = process.env.GITHUB_REPOSITORY.split("/");
octokit.actions
.listWorkflowRuns({
owner,
repo,
workflow_id: core.getInput("workflow_id"),
status: "success",
branch: core.getInput("branch"),
event: "push",
})
.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);
}