-
Notifications
You must be signed in to change notification settings - Fork 1
/
post.js
49 lines (39 loc) · 1.48 KB
/
post.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
const core = require('@actions/core');
const cache = require('@actions/cache');
const fs = require('fs');
const CACHE_KEY = 'habitat-action-pkgs';
const CACHE_LOCK_PATH = '/hab/cache/artifacts/.cached';
// gather input
const cacheKey = core.getInput('cache-key') || `hab-artifacts-cache:${process.env.GITHUB_WORKFLOW}`;
// run with error wrapper
try {
module.exports = run();
} catch(err) {
core.setFailed(err.message);
}
async function run() {
// save cache
if (fs.existsSync(CACHE_LOCK_PATH)) {
// .cached file is written at beginning of caching, and removed after restore to
// guard against multiple post scripts trying to save the same cache
core.info(`Skipping caching, ${CACHE_LOCK_PATH} already exists`);
} else {
try {
core.startGroup(`Saving package cache`);
core.info(`Writing cache lock: ${CACHE_LOCK_PATH}`);
fs.writeFileSync(CACHE_LOCK_PATH, '');
try {
core.info(`Calling saveCache: ${cacheKey}`);
const savedCache = await cache.saveCache(['/hab/cache/artifacts'], cacheKey);
core.info(savedCache ? `Saved cache ${savedCache}` : 'No cache saved');
} catch (err) {
core.warning(`Failed to save cache: ${err.message}`);
}
} catch (err) {
core.setFailed(`Failed to save package cache: ${err.message}`);
return;
} finally {
core.endGroup();
}
}
}