-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
70 lines (62 loc) · 1.96 KB
/
main.js
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
import path from "path";
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import {
determineVersion,
getFullVersionFromScarb,
versionWithPrefix,
} from "./versions";
import { downloadScarb } from "./download";
import { getOsTriplet } from "./platform";
import { restoreCache } from "./cache-restore";
export default async function main() {
try {
const scarbVersionInput = core.getInput("scarb-version");
const toolVersionsPathInput = core.getInput("tool-versions");
const scarbLockPathInput = core.getInput("scarb-lock");
const enableCache = core.getBooleanInput("cache");
const addToPath = core.getBooleanInput("add-to-path");
const { repo: scarbRepo, version: scarbVersion } = await determineVersion(
scarbVersionInput,
toolVersionsPathInput,
{
repo: "software-mansion/scarb",
nightliesRepo: "software-mansion/scarb-nightlies",
},
);
const triplet = getOsTriplet();
await core.group(
`Setting up Scarb ${versionWithPrefix(scarbVersion)}`,
async () => {
let scarbPrefix = tc.find("scarb", scarbVersion, triplet);
if (!scarbPrefix) {
const download = await downloadScarb(scarbRepo, scarbVersion);
scarbPrefix = await tc.cacheDir(
download,
"scarb",
scarbVersion,
triplet
);
}
core.setOutput("scarb-prefix", scarbPrefix);
if (addToPath) {
core.addPath(path.join(scarbPrefix, "bin"));
}
},
);
core.setOutput("scarb-version", await getFullVersionFromScarb());
if (enableCache) {
await restoreCache(scarbLockPathInput).catch((e) => {
core.error(
`There was an error when restoring cache: ${
e instanceof Error ? e.message : e
}`,
);
});
} else {
core.info(`Caching disabled, not restoring cache.`);
}
} catch (e) {
core.setFailed(e);
}
}