-
Notifications
You must be signed in to change notification settings - Fork 21
/
options.ts
89 lines (74 loc) · 2.52 KB
/
options.ts
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
86
87
88
89
import * as path from "node:path";
import * as core from "@actions/core";
import type { Octokit } from "../octokit";
import type { Thresholds } from "../types/Threshold";
import { type FileCoverageMode, getCoverageModeFrom } from "./FileCoverageMode";
import { type CommentOn, getCommentOn } from "./getCommentOn";
import { getCommitSHA } from "./getCommitSHA";
import { getPullRequestNumber } from "./getPullRequestNumber";
import { getViteConfigPath } from "./getViteConfigPath";
import { parseCoverageThresholds } from "./parseCoverageThresholds";
type Options = {
fileCoverageMode: FileCoverageMode;
jsonFinalPath: string;
jsonSummaryPath: string;
jsonSummaryComparePath: string | null;
name: string;
thresholds: Thresholds;
workingDirectory: string;
prNumber: number | undefined;
commitSHA: string;
commentOn: Array<CommentOn>;
};
async function readOptions(octokit: Octokit): Promise<Options> {
// Working directory can be used to modify all default/provided paths (for monorepos, etc)
const workingDirectory = core.getInput("working-directory");
const fileCoverageModeRaw = core.getInput("file-coverage-mode"); // all/changes/none
const fileCoverageMode = getCoverageModeFrom(fileCoverageModeRaw);
const jsonSummaryPath = path.resolve(
workingDirectory,
core.getInput("json-summary-path"),
);
const jsonFinalPath = path.resolve(
workingDirectory,
core.getInput("json-final-path"),
);
const jsonSummaryCompareInput = core.getInput("json-summary-compare-path");
let jsonSummaryComparePath: string | null = null;
if (jsonSummaryCompareInput) {
jsonSummaryComparePath = path.resolve(
workingDirectory,
jsonSummaryCompareInput,
);
}
const name = core.getInput("name");
const commentOn = getCommentOn();
// ViteConfig is optional, as it is only required for thresholds. If no vite config is provided, we will not include thresholds in the final report.
const viteConfigPath = await getViteConfigPath(
workingDirectory,
core.getInput("vite-config-path"),
);
const thresholds = viteConfigPath
? await parseCoverageThresholds(viteConfigPath)
: {};
const commitSHA = getCommitSHA();
let prNumber: number | undefined = undefined;
if (commentOn.includes("pr")) {
// Get the user-defined pull-request number and perform input validation
prNumber = await getPullRequestNumber(octokit);
}
return {
fileCoverageMode,
jsonFinalPath,
jsonSummaryPath,
jsonSummaryComparePath,
name,
thresholds,
workingDirectory,
prNumber,
commitSHA,
commentOn,
};
}
export { readOptions };
export type { Options };