Skip to content

Commit f67be5d

Browse files
committed
build: compile sources
Signed-off-by: Dwi Siswanto <me@dw1.io>
1 parent 1fe2ce2 commit f67be5d

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

dist/const.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.TMP_DIR = exports.shell = exports.path = exports.os = exports.io = exports.https = exports.fs = exports.core = void 0;
3+
exports.TMP_DIR = exports.shell = exports.path = exports.os = exports.io = exports.https = exports.fs = exports.core = exports.cache = void 0;
4+
exports.cache = require('@actions/cache');
45
exports.core = require('@actions/core');
56
exports.fs = require('fs');
67
exports.https = require('https');

dist/index.js

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function get_slim() {
5252
}
5353
}
5454
catch (_a) {
55-
throw new Error('ERROR! Could not retrieve the current Slim version number.');
55+
throw new Error(`ERROR! Could not get the Slim version ${VER}.`);
5656
}
5757
URL = `https://downloads.dockerslim.com/releases/${VER}`;
5858
// Get kernel name and machine architecture.
@@ -89,39 +89,61 @@ function get_slim() {
8989
}
9090
// Derive the filename
9191
FILENAME = `dist_${DIST}.${EXT}`;
92-
const file = const_1.fs.createWriteStream(const_1.path.join(const_1.TMP_DIR, FILENAME));
93-
yield new Promise((resolve, reject) => {
94-
const_1.https.get(`${URL}/${FILENAME}`, (response) => {
95-
response.pipe(file);
96-
file.on('finish', () => {
97-
file.close();
98-
resolve(file);
99-
});
100-
}).on('error', (error) => {
101-
const_1.fs.unlinkSync(const_1.path.join(const_1.TMP_DIR, FILENAME));
102-
reject(error);
103-
});
104-
});
105-
const_1.core.debug(`Unpacking ${const_1.path.join(const_1.TMP_DIR, FILENAME)}`);
106-
if (EXT === 'zip') {
107-
const extract = require('extract-zip');
108-
yield extract(const_1.path.join(const_1.TMP_DIR, FILENAME), {
109-
dir: const_1.TMP_DIR
110-
});
92+
// Get the bin from cache
93+
const cachePrefix = `slim-${VER}`;
94+
const cacheKey = `${cachePrefix}-${DIST}`;
95+
const cachePath = const_1.path.join('/tmp', cacheKey);
96+
try {
97+
const_1.core.debug('Restoring cache');
98+
const cacheResult = yield const_1.cache.restoreCache([cachePath], cacheKey, [`${cachePrefix}-`]);
99+
if (typeof cacheResult === 'undefined') {
100+
throw new Error(`ERROR! Cache miss: ${cacheKey} was not found in the cache.`);
101+
}
102+
const_1.core.debug(`${cacheKey} cache was restored.`);
103+
SLIM_PATH = cachePath;
111104
}
112-
else if (EXT === 'tar.gz') {
113-
const tar = require('tar');
114-
yield tar.x({
115-
file: const_1.path.join(const_1.TMP_DIR, FILENAME),
116-
cwd: const_1.TMP_DIR
105+
catch (e) {
106+
const_1.core.error(e);
107+
const file = const_1.fs.createWriteStream(const_1.path.join(const_1.TMP_DIR, FILENAME));
108+
yield new Promise((resolve, reject) => {
109+
const_1.https.get(`${URL}/${FILENAME}`, (response) => {
110+
response.pipe(file);
111+
file.on('finish', () => {
112+
file.close();
113+
resolve(file);
114+
});
115+
}).on('error', (error) => {
116+
const_1.fs.unlinkSync(const_1.path.join(const_1.TMP_DIR, FILENAME));
117+
reject(error);
118+
});
117119
});
120+
const_1.core.debug(`Unpacking ${const_1.path.join(const_1.TMP_DIR, FILENAME)}`);
121+
if (EXT === 'zip') {
122+
const extract = require('extract-zip');
123+
yield extract(const_1.path.join(const_1.TMP_DIR, FILENAME), {
124+
dir: const_1.TMP_DIR
125+
});
126+
}
127+
else if (EXT === 'tar.gz') {
128+
const tar = require('tar');
129+
yield tar.x({
130+
file: const_1.path.join(const_1.TMP_DIR, FILENAME),
131+
cwd: const_1.TMP_DIR
132+
});
133+
}
134+
else {
135+
throw new Error('ERROR! Unexpected file extension.');
136+
}
137+
SLIM_PATH = const_1.path.join(const_1.TMP_DIR, `dist_${DIST}`);
138+
const_1.core.debug(`Copying ${SLIM_PATH} -> (${cachePath})`);
139+
yield const_1.io.cp(SLIM_PATH, cachePath, { recursive: true, force: true });
140+
const cacheId = yield const_1.cache.saveCache([cachePath], cacheKey);
141+
const_1.core.debug(`${cacheKey} cache saved (ID: ${cacheId})`);
118142
}
119-
else {
120-
throw new Error('ERROR! Unexpected file extension.');
143+
finally {
144+
const_1.core.addPath(SLIM_PATH);
145+
const_1.core.info(`Using slim version ${VER}`);
121146
}
122-
SLIM_PATH = const_1.path.join(const_1.TMP_DIR, `dist_${DIST}`);
123-
const_1.core.addPath(SLIM_PATH);
124-
const_1.core.info(`Using slim version ${VER}`);
125147
});
126148
}
127149
function run() {

0 commit comments

Comments
 (0)