-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
85 lines (74 loc) · 2.27 KB
/
Copy pathindex.ts
File metadata and controls
85 lines (74 loc) · 2.27 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as core from "@actions/core";
import * as github from "@actions/github";
import {
getOptionalInput,
getOrCreateRunId,
getRequiredFernToken,
installFernCli,
instrumentAction,
isPostPhase,
markMainPhaseStarted,
runAction,
runPostCleanup,
} from "@fern-github-actions/shared";
import { normalizeFernVersion } from "./parse-inputs.js";
import { postOrUpdateComment } from "./post-comment.js";
import { runAutomationsPreview } from "./run-preview.js";
interface ActionInputs {
fernToken: string;
fernVersion: string;
githubToken: string | undefined;
}
function parseInputs(): ActionInputs {
return {
fernToken: getRequiredFernToken(),
fernVersion: normalizeFernVersion(getOptionalInput("fern-version")),
githubToken: getOptionalInput("github-token"),
};
}
async function run(inputs: ActionInputs): Promise<void> {
const runId = getOrCreateRunId();
core.setOutput("run-id", runId);
await installFernCli(inputs.fernVersion);
const results = await runAutomationsPreview({ fernToken: inputs.fernToken });
if (results.length === 0) {
core.info("No eligible generator groups found. Skipping preview.");
core.setOutput("results", "[]");
return;
}
const prNumber = github.context.payload.pull_request?.number;
if (prNumber != null) {
if (!inputs.githubToken) {
core.warning("Skipping PR comment: github-token input is empty.");
} else {
try {
await postOrUpdateComment({ results, prNumber, token: inputs.githubToken });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
core.warning(`Failed to post PR comment: ${message}`);
}
}
} else {
core.info("Not a pull request event — skipping PR comment.");
for (const result of results) {
if (result.status === "success" && result.installCommand) {
core.info(`${result.groupName}: ${result.installCommand}`);
}
}
}
core.setOutput("results", JSON.stringify(results));
}
runAction(async () => {
if (isPostPhase()) {
runPostCleanup();
return;
}
markMainPhaseStarted();
await instrumentAction("preview", async () => {
const inputs = parseInputs();
if (inputs.githubToken) {
core.setSecret(inputs.githubToken);
}
await run(inputs);
});
});