3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-05-03 16:35:48 +00:00

Merge pull request #2 from useblacksmith/bump-version

dist: bump version cache
This commit is contained in:
Aditya Maru 2024-04-20 15:03:50 -04:00 committed by GitHub
commit 5d260ed846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 93 additions and 13 deletions

48
dist/restore/index.js vendored
View file

@ -143,13 +143,20 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
} }
else { else {
// Supress all non-validation cache related errors because caching should be optional // Supress all non-validation cache related errors because caching should be optional
core.warning(`Failed to restore: ${error.message}`); if (error.message.includes(`Cache service responded with 404`)) {
core.info(`Did not get a cache hit; proceeding as an uncached run`);
}
else {
core.warning(`Failed to restore: ${error.message}`);
}
} }
} }
finally { finally {
// Try to delete the archive to save space // Try to delete the archive to save space
try { try {
yield utils.unlinkFile(archivePath); const before = Date.now();
yield unlinkWithTimeout(archivePath, 5000);
core.info(`cleaning up archive took ${Date.now() - before}ms`);
} }
catch (error) { catch (error) {
core.debug(`Failed to delete archive: ${error}`); core.debug(`Failed to delete archive: ${error}`);
@ -159,6 +166,27 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
}); });
} }
exports.restoreCache = restoreCache; exports.restoreCache = restoreCache;
function unlinkWithTimeout(path, timeoutMs) {
return __awaiter(this, void 0, void 0, function* () {
const timeout = new Promise((_, reject) => {
setTimeout(() => {
reject(new Error('Unlink operation timed out'));
}, timeoutMs);
});
try {
yield Promise.race([utils.unlinkFile(path), timeout]);
}
catch (error) {
if (error.message === 'Unlink operation timed out') {
core.warning(`Unlink operation exceeded the timeout of ${timeoutMs}ms`);
}
else {
core.debug(`Failed to delete archive: ${error}`);
}
throw error;
}
});
}
/** /**
* Saves a list of files with the specified key * Saves a list of files with the specified key
* *
@ -318,7 +346,6 @@ function getRequestOptions() {
} }
function createHttpClient() { function createHttpClient() {
const token = process.env['BLACKSMITH_CACHE_TOKEN']; const token = process.env['BLACKSMITH_CACHE_TOKEN'];
core.debug(`BLACKSMITH_CACHE_TOKEN: ${token}`);
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token !== null && token !== void 0 ? token : ''); const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token !== null && token !== void 0 ? token : '');
return new http_client_1.HttpClient('useblacksmith/cache', [bearerCredentialHandler], getRequestOptions()); return new http_client_1.HttpClient('useblacksmith/cache', [bearerCredentialHandler], getRequestOptions());
} }
@ -992,6 +1019,7 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
yield fdesc.sync(); yield fdesc.sync();
progressLogger = new DownloadProgress(fileSize); progressLogger = new DownloadProgress(fileSize);
progressLogger.startDisplayTimer(); progressLogger.startDisplayTimer();
core.info(`Downloading ${archivePath}`);
// Divvy up the download into chunks based on CONCURRENCY // Divvy up the download into chunks based on CONCURRENCY
const chunkSize = Math.ceil(fileSize / CONCURRENCY); const chunkSize = Math.ceil(fileSize / CONCURRENCY);
const chunkRanges = []; const chunkRanges = [];
@ -1017,9 +1045,21 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
})); }));
yield Promise.all(downloads); yield Promise.all(downloads);
} }
catch (err) {
core.warning(`Failed to download cache: ${err}`);
throw err;
}
finally { finally {
yield fdesc.close(); // Stop the progress logger regardless of whether the download succeeded or failed.
// Not doing this will cause the entire action to halt if the download fails.
progressLogger === null || progressLogger === void 0 ? void 0 : progressLogger.stopDisplayTimer(); progressLogger === null || progressLogger === void 0 ? void 0 : progressLogger.stopDisplayTimer();
try {
yield fdesc.close();
}
catch (err) {
// Intentionally swallow any errors in closing the file descriptor.
core.warning(`Failed to close file descriptor: ${err}`);
}
} }
}); });
} }

48
dist/save/index.js vendored
View file

@ -143,13 +143,20 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
} }
else { else {
// Supress all non-validation cache related errors because caching should be optional // Supress all non-validation cache related errors because caching should be optional
core.warning(`Failed to restore: ${error.message}`); if (error.message.includes(`Cache service responded with 404`)) {
core.info(`Did not get a cache hit; proceeding as an uncached run`);
}
else {
core.warning(`Failed to restore: ${error.message}`);
}
} }
} }
finally { finally {
// Try to delete the archive to save space // Try to delete the archive to save space
try { try {
yield utils.unlinkFile(archivePath); const before = Date.now();
yield unlinkWithTimeout(archivePath, 5000);
core.info(`cleaning up archive took ${Date.now() - before}ms`);
} }
catch (error) { catch (error) {
core.debug(`Failed to delete archive: ${error}`); core.debug(`Failed to delete archive: ${error}`);
@ -159,6 +166,27 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
}); });
} }
exports.restoreCache = restoreCache; exports.restoreCache = restoreCache;
function unlinkWithTimeout(path, timeoutMs) {
return __awaiter(this, void 0, void 0, function* () {
const timeout = new Promise((_, reject) => {
setTimeout(() => {
reject(new Error('Unlink operation timed out'));
}, timeoutMs);
});
try {
yield Promise.race([utils.unlinkFile(path), timeout]);
}
catch (error) {
if (error.message === 'Unlink operation timed out') {
core.warning(`Unlink operation exceeded the timeout of ${timeoutMs}ms`);
}
else {
core.debug(`Failed to delete archive: ${error}`);
}
throw error;
}
});
}
/** /**
* Saves a list of files with the specified key * Saves a list of files with the specified key
* *
@ -318,7 +346,6 @@ function getRequestOptions() {
} }
function createHttpClient() { function createHttpClient() {
const token = process.env['BLACKSMITH_CACHE_TOKEN']; const token = process.env['BLACKSMITH_CACHE_TOKEN'];
core.debug(`BLACKSMITH_CACHE_TOKEN: ${token}`);
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token !== null && token !== void 0 ? token : ''); const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token !== null && token !== void 0 ? token : '');
return new http_client_1.HttpClient('useblacksmith/cache', [bearerCredentialHandler], getRequestOptions()); return new http_client_1.HttpClient('useblacksmith/cache', [bearerCredentialHandler], getRequestOptions());
} }
@ -992,6 +1019,7 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
yield fdesc.sync(); yield fdesc.sync();
progressLogger = new DownloadProgress(fileSize); progressLogger = new DownloadProgress(fileSize);
progressLogger.startDisplayTimer(); progressLogger.startDisplayTimer();
core.info(`Downloading ${archivePath}`);
// Divvy up the download into chunks based on CONCURRENCY // Divvy up the download into chunks based on CONCURRENCY
const chunkSize = Math.ceil(fileSize / CONCURRENCY); const chunkSize = Math.ceil(fileSize / CONCURRENCY);
const chunkRanges = []; const chunkRanges = [];
@ -1017,9 +1045,21 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
})); }));
yield Promise.all(downloads); yield Promise.all(downloads);
} }
catch (err) {
core.warning(`Failed to download cache: ${err}`);
throw err;
}
finally { finally {
yield fdesc.close(); // Stop the progress logger regardless of whether the download succeeded or failed.
// Not doing this will cause the entire action to halt if the download fails.
progressLogger === null || progressLogger === void 0 ? void 0 : progressLogger.stopDisplayTimer(); progressLogger === null || progressLogger === void 0 ? void 0 : progressLogger.stopDisplayTimer();
try {
yield fdesc.close();
}
catch (err) {
// Intentionally swallow any errors in closing the file descriptor.
core.warning(`Failed to close file descriptor: ${err}`);
}
} }
}); });
} }

8
package-lock.json generated
View file

@ -9,7 +9,7 @@
"version": "2.7.2", "version": "2.7.2",
"license": "LGPL-3.0", "license": "LGPL-3.0",
"dependencies": { "dependencies": {
"@actions/blacksmith-cache": "npm:@useblacksmith/cache@3.2.41", "@actions/blacksmith-cache": "npm:@useblacksmith/cache@3.2.48",
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0", "@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
"@actions/cache": "^3.2.3", "@actions/cache": "^3.2.3",
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",
@ -29,9 +29,9 @@
}, },
"node_modules/@actions/blacksmith-cache": { "node_modules/@actions/blacksmith-cache": {
"name": "@useblacksmith/cache", "name": "@useblacksmith/cache",
"version": "3.2.41", "version": "3.2.48",
"resolved": "https://registry.npmjs.org/@useblacksmith/cache/-/cache-3.2.41.tgz", "resolved": "https://registry.npmjs.org/@useblacksmith/cache/-/cache-3.2.48.tgz",
"integrity": "sha512-uGMhrp+3wnRN67i96mCsf3OswU4UREuQxwujQE1Ti15ESJBdhuDp6mt5L57RbUhNEfLqIRxZMqQCDCj/OLqKXQ==", "integrity": "sha512-w9uGDYKXHi4MyOrL60COMrHgYA9LBYRFbw1whGR0Ve8oRlQ9PfmOKEe2v9VT/65E/S3Wni/TGwhgMI0RBEoSmw==",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/exec": "^1.0.1", "@actions/exec": "^1.0.1",

View file

@ -22,7 +22,7 @@
}, },
"homepage": "https://github.com/Swatinem/rust-cache#readme", "homepage": "https://github.com/Swatinem/rust-cache#readme",
"dependencies": { "dependencies": {
"@actions/blacksmith-cache": "npm:@useblacksmith/cache@3.2.41", "@actions/blacksmith-cache": "npm:@useblacksmith/cache@3.2.48",
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0", "@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
"@actions/cache": "^3.2.3", "@actions/cache": "^3.2.3",
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",