-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.ts
58 lines (54 loc) · 1.52 KB
/
action.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
import Fs from "fs";
import { action } from "./index";
import { getCache } from "./src/get_cache";
import { getOctokit, context } from "@actions/github";
import { restoreCache, saveCache } from "@actions/cache";
import { getInput } from "@actions/core";
import { LContext } from "./types";
const toolkit = getOctokit(process.env.GITHUB_TOKEN!);
const cacheKey = `notfoundbot-v2-${Date.now()}`;
const messages: string[] = [];
function message(msg: string) {
messages.push(msg);
console.log(msg);
}
(async function () {
const ctx: LContext = {
contentDir: getInput("content-folder"),
cwd: process.env.GITHUB_WORKSPACE || __dirname,
toolkit,
context,
cache: {},
message,
messages,
limit: 100,
branchName: `notfoundbot-${new Date()
.toLocaleDateString()
.replace(/\//g, "-")}`,
stats: {
cacheSkipped: 0,
upgradedSSL: 0,
urlsDetected: 0,
urlsScanned: 0,
protocolSkipped: 0,
relativeSkipped: 0,
archived: 0,
},
};
const cacheFilePath = ".notfoundbot-cache";
try {
await restoreCache([cacheFilePath], cacheKey, ["notfoundbot-v2-"]);
} catch (e) {
ctx.message("ERROR: Failed to restore cache!");
}
await getCache(ctx, cacheFilePath);
await action(ctx);
ctx.message(`Saving cache with ${Object.keys(ctx.cache).length} items`);
Fs.writeFileSync(cacheFilePath, JSON.stringify(ctx.cache));
try {
await saveCache([cacheFilePath], cacheKey);
} catch (e) {
ctx.message("ERROR: Failed to save cache!");
throw e;
}
})();