forked from nrwl/last-successful-commit-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (27 loc) · 764 Bytes
/
index.js
File metadata and controls
28 lines (27 loc) · 764 Bytes
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
import { getInput, setOutput, setFailed, warning } from "@actions/core";
import { Octokit } from "@octokit/rest";
try {
const octokit = new Octokit({
auth: getInput("github_token")
});
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
octokit.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: getInput("workflow_id"),
status: "completed",
conclusion: "success",
branch: getInput("branch"),
}).then(({ data }) => {
if (data.workflow_runs.length > 0) {
setOutput("commit_sha", data.workflow_runs[0].head_sha);
} else {
warning("Unable to find last successful commit");
setOutput("commit_sha", "");
}
}).catch((e) => {
setFailed(e);
});
} catch(e) {
setFailed(e);
}