Skip to content

Commit d9155f8

Browse files
committed
github-script calls an external TS file
1 parent 1199ce1 commit d9155f8

File tree

6 files changed

+446
-53
lines changed

6 files changed

+446
-53
lines changed

.github/scripts/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.github/scripts/find-artifact.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as core from "@actions/core";
2+
import * as github from "@actions/github";
3+
4+
interface Inputs {
5+
github: ReturnType<typeof github.getOctokit>;
6+
context: typeof github.context;
7+
core: typeof core;
8+
}
9+
10+
module.exports = async ({github, context, core}: Inputs) => {
11+
const token = process.env.GITHUB_TOKEN;
12+
const commitSha = process.env.BASE_SHA;
13+
const artifactName = process.env.ARTIFACT_NAME;
14+
const workflowName = process.env.WORKFLOW_NAME;
15+
16+
// Get all workflow runs for this commit
17+
const runs = await github.rest.actions.listWorkflowRunsForRepo({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
per_page: 20,
21+
event: "push",
22+
head_sha: commitSha
23+
});
24+
25+
if (runs.data.workflow_runs.length === 0) {
26+
core.setFailed(`No workflow runs found for commit ${commitSha}`);
27+
return;
28+
}
29+
30+
const workflowRuns = runs.data.workflow_runs;
31+
if (workflowRuns.length === 0) {
32+
core.setFailed(`No workflow runs found for commit ${commitSha}`);
33+
return;
34+
}
35+
36+
let found = false;
37+
for (const run of workflowRuns) {
38+
if (run.status !== "completed" || run.conclusion !== "success") {
39+
continue;
40+
}
41+
42+
if (run.name !== workflowName) {
43+
continue;
44+
}
45+
46+
const artifactsResp = await github.rest.actions.listWorkflowRunArtifacts({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
run_id: run.id,
50+
});
51+
52+
const artifact = artifactsResp.data.artifacts.find(a => a.name === artifactName);
53+
if (artifact) {
54+
core.setOutput("artifact_id", artifact.id.toString());
55+
core.setOutput("run_id", run.id.toString());
56+
found = true;
57+
break;
58+
}
59+
}
60+
61+
if (!found) {
62+
core.setFailed(`No artifact named '${artifactName}' found for commit ${commitSha}`);
63+
}
64+
}

.github/scripts/package-lock.json

Lines changed: 323 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)