-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
73 lines (59 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import execa from 'execa';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import {
getBinDir,
getCacheKeyPrefix,
getPluginsDir,
getShimsDir,
getToolchainCacheKey,
getToolsDir,
getUidFile,
getWorkspaceRoot,
installBin,
isCacheEnabled,
isUsingMoon,
} from './helpers';
async function restoreCache() {
if (!isCacheEnabled()) {
return;
}
core.info('Attempting to restore cached toolchain');
const primaryKey = await getToolchainCacheKey();
const cachePrefix = getCacheKeyPrefix();
const cacheKey = await cache.restoreCache(
[getPluginsDir(), getToolsDir(), getUidFile()],
primaryKey,
[`${cachePrefix}-${process.platform}`, cachePrefix],
);
if (cacheKey) {
core.saveState('cacheHitKey', cacheKey);
core.info(`Toolchain cache restored using key ${primaryKey}`);
} else {
core.info(`Toolchain cache does not exist using key ${primaryKey}`);
}
core.setOutput('cache-key', cacheKey ?? primaryKey);
core.setOutput('cache-hit', !!cacheKey);
}
async function run() {
try {
const shimsDir = getShimsDir();
const binDir = getBinDir();
core.info(`Added ${shimsDir} and ${binDir} to PATH`);
core.addPath(binDir);
core.addPath(shimsDir);
await installBin('proto');
if (isUsingMoon()) {
await installBin('moon');
}
await restoreCache();
if (core.getBooleanInput('auto-install')) {
core.info('Auto-installing tools');
await execa('proto', ['use'], { cwd: getWorkspaceRoot(), stdio: 'inherit' });
}
} catch (error: unknown) {
core.setFailed(error as Error);
}
}
// eslint-disable-next-line unicorn/prefer-top-level-await
void run();