-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
57 lines (48 loc) · 1.59 KB
/
index.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
import * as core from "@actions/core";
import * as dayjs from "dayjs";
import * as utc from "dayjs/plugin/utc";
import * as timezone from "dayjs/plugin/timezone";
import * as customParseFormat from "dayjs/plugin/customParseFormat";
import * as isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import * as isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import { Config, Day, DAYS, validDateFormats } from "./config";
import type { Logger } from "./logger";
import { process } from "./process";
const logger: Logger = {
debug: (message: string) => {
core.debug(message);
},
notice: (message: string) => {
core.notice(message);
},
fail: (message: string) => {
core.setFailed(message);
},
setOutput: (name: string, value: any) => {
core.setOutput(name, value);
},
};
async function main() {
try {
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(customParseFormat);
dayjs.extend(isSameOrBefore);
dayjs.extend(isSameOrAfter);
const configString = core.getInput("config");
if (!configString) {
throw new Error(`Expected a config string input. Got: "${configString}`);
}
core.debug(`Schedule Config: ${configString}`);
const config: Config = JSON.parse(configString);
if (!config || !config.schedules || config.schedules.length === 0) {
throw new Error("No Schedule Found.");
}
core.debug(`Parsed Config: ${JSON.stringify(config, null, 2)}`);
dayjs.tz.setDefault(config.timeZone || "America/New_York");
process(dayjs(), config, logger);
} catch (error) {
core.setFailed(error.message);
}
}
main();