forked from shivammathur/cache-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.ts
69 lines (66 loc) · 1.89 KB
/
cache.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
import {exec} from '@actions/exec';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as spu from 'setup-php/lib/utils';
import * as fs from 'fs';
import * as path from 'path';
import * as utils from './utils';
/**
* Handle dependencies
*
* @param extensions
* @param version
*/
export async function handleDependencies(
extensions: string,
version: string
): Promise<void> {
if (!/^5.[3-5]$/.test(version) && /linux|darwin/.test(process.platform)) {
const cache_key: string = (await utils.getOutput('key')) + '-deps';
const cache_dir: string = path.join(
await spu.readEnv('RUNNER_TOOL_CACHE'),
'deps'
);
const cache_hit: string | undefined = await cache.restoreCache(
[cache_dir],
cache_key,
[cache_key]
);
await exec(await utils.scriptCall('dependencies', extensions, version));
if (!cache_hit && fs.existsSync(cache_dir)) {
try {
await cache.saveCache([cache_dir], cache_key);
} catch {
await cache.saveCache([cache_dir], cache_key + '-take-2');
}
}
}
}
/**
* Run the script
*/
export async function run(): Promise<void> {
try {
const version: string = await spu.parseVersion(await spu.readPHPVersion());
const extensions: string = await utils.filterExtensions(
await spu.getInput('extensions', true)
);
const key: string = await spu.getInput('key', true);
await exec(await utils.scriptCall('data', extensions, version, key));
await handleDependencies(extensions, version);
} catch (error) {
core.setFailed((error as Error).message);
}
}
// call the run function
(async () => {
await run();
})().catch(error => {
if (error.name === cache.ValidationError.name) {
core.setFailed(error.message);
} else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message);
} else {
core.warning(error.message);
}
});