generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 36
/
getInputs.ts
54 lines (45 loc) · 1.27 KB
/
getInputs.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
import formatDate from "./formatDate";
import { getInput, warning } from "@actions/core/lib/core";
interface Inputs {
tag: string;
version: string;
date: string;
owner: string;
repo: string;
changelogPath: string;
}
function parseTagAndVersion(): [string, string] {
const tagInput = getInput("tag");
if (tagInput) {
const version = tagInput.startsWith("v") ? tagInput.substring(1) : tagInput;
return [tagInput, version];
} else {
const versionInput = getInput("version");
if (!versionInput) {
throw new Error("Neither version nor tag specified");
}
warning("Version argument will be deprecated soon, use tag instead.");
return [versionInput, versionInput];
}
}
export default function getInputs(): Inputs {
const [tag, version] = parseTagAndVersion();
const dateInput = getInput("date");
const date = formatDate(
dateInput ? new Date(Date.parse(dateInput)) : new Date()
);
const changelogPath = getInput("changelogPath") || "./CHANGELOG.md";
const githubRepository = process.env.GITHUB_REPOSITORY;
if (!githubRepository) {
throw new Error("GITHUB_REPOSITORY is not set");
}
const [owner, repo] = githubRepository.split("/");
return {
tag,
version,
date,
owner,
repo,
changelogPath
};
}