8000 Merge pull request #2 from useblacksmith/bump-cache-version · useblacksmith/setup-python@573a647 · GitHub
[go: up one dir, main page]

Skip to content

Commit 573a647

Browse files
authored
Merge pull request #2 from useblacksmith/bump-cache-version
dist: bump cache version
2 parents e00a9ae + 3710c88 commit 573a647

File tree

4 files changed

+93
-13
lines changed

4 files changed

+93
-13
lines changed

dist/cache-save/index.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,20 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
143143
}
144144
else {
145145
// Supress all non-validation cache related errors because caching should be optional
146-
core.warning(`Failed to restore: ${error.message}`);
146+
if (error.message.includes(`Cache service responded with 404`)) {
147+
core.info(`Did not get a cache hit; proceeding as an uncached run`);
148+
}
149+
else {
150+
core.warning(`Failed to restore: ${error.message}`);
151+
}
147152
}
148153
}
149154
finally {
150155
// Try to delete the archive to save space
151156
try {
152-
yield utils.unlinkFile(archivePath);
157+
const before = Date.now();
158+
yield unlinkWithTimeout(archivePath, 5000);
159+
core.info(`cleaning up archive took ${Date.now() - before}ms`);
153160
}
154161
catch (error) {
155162
core.debug(`Failed to delete archive: ${error}`);
@@ -159,6 +166,27 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
159166
});
160167
}
161168
exports.restoreCache = restoreCache;
169+
function unlinkWithTimeout(path, timeoutMs) {
170+
return __awaiter(this, void 0, void 0, function* () {
171+
const timeout = new Promise((_, reject) => {
172+
setTimeout(() => {
173+
reject(new Error('Unlink operation timed out'));
174+
}, timeoutMs);
175+
});
176+
try {
177+
yield Promise.race([utils.unlinkFile(path), timeout]);
178+
}
179+
catch (error) {
180+
if (error.message === 'Unlink operation timed out') {
181+
core.warning(`Unlink operation exceeded the timeout of ${timeoutMs}ms`);
182+
}
183+
else {
184+
core.debug(`Failed to delete archive: ${error}`);
185+
}
186+
throw error;
187+
}
188+
});
189+
}
162190
/**
163191
* Saves a list of files with the specified key
164192
*
@@ -318,7 +346,6 @@ function getRequestOptions() {
318346
}
319347
function createHttpClient() {
320348
const token = process.env['BLACKSMITH_CACHE_TOKEN'];
321-
core.debug(`BLACKSMITH_CACHE_TOKEN: ${token}`);
322349
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token !== null && token !== void 0 ? token : '');
323350
return new http_client_1.HttpClient('useblacksmith/cache', [bearerCredentialHandler], getRequestOptions());
324351
}
@@ -992,6 +1019,7 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
9921019
yield fdesc.sync();
9931020
progressLogger = new DownloadProgress(fileSize);
9941021
progressLogger.startDisplayTimer();
1022+
core.info(`Downloading ${archivePath}`);
9951023
// Divvy up the download into chunks based on CONCURRENCY
9961024
const chunkSize = Math.ceil(fileSize / CONCURRENCY);
9971025
const chunkRanges = [];
@@ -1017,9 +1045,21 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
10171045
}));
10181046
yield Promise.all(downloads);
10191047
}
1048+
catch (err) {
1049+
core.warning(`Failed to download cache: ${err}`);
1050+
throw err;
1051+
}
10201052
finally {
1021-
yield fdesc.close();
1053+
// Stop the progress logger regardless of whether the download succeeded or failed.
1054+
// Not doing this will cause the entire action to halt if the download fails.
10221055
progressLogger === null || progressLogger === void 0 ? void 0 : progressLogger.stopDisplayTimer();
1056+
try {
1057+
yield fdesc.close();
1058+
}
1059+
catch (err) {
1060+
// Intentionally swallow any errors in closing the file descriptor.
1061+
core.warning(`Failed to close file descriptor: ${err}`);
1062+
}
10231063
}
10241064
});
10251065
}

dist/setup/index.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,20 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
143143
}
144144
else {
145145
// Supress all non-validation cache related errors because caching should be optional
146-
core.warning(`Failed to restore: ${error.message}`);
146+
if (error.message.includes(`Cache service responded with 404`)) {
147+
core.info(`Did not get a cache hit; proceeding as an uncached run`);
148+
}
149+
else {
150+
core.warning(`Failed to restore: ${error.message}`);
151+
}
147152
}
148153
}
149154
finally {
150155
// Try to delete the archive to save space
151156
try {
152-
yield utils.unlinkFile(archivePath);
157+
const before = Date.now();
158+
yield unlinkWithTimeout(archivePath, 5000);
159+
core.info(`cleaning up archive took ${Date.now() - before}ms`);
153160
}
154161
catch (error) {
155162
core.debug(`Failed to delete archive: ${error}`);
@@ -159,6 +166,27 @@ function restoreCache(paths, primaryKey, restoreKeys, options, enableCrossOsArch
159166
});
160167
}
161168
exports.restoreCache = restoreCache;
169+
function unlinkWithTimeout(path, timeoutMs) {
170+
return __awaiter(this, void 0, void 0, function* () {
171+
const timeout = new Promise((_, reject) => {
172+
setTimeout(() => {
173+
reject(new Error('Unlink operation timed out'));
174+
}, timeoutMs);
175+
});
176+
try {
177+
yield Promise.race([utils.unlinkFile(path), timeout]);
178+
}
179+
catch (error) {
180+
if (error.message === 'Unlink operation timed out') {
181+
core.warning(`Unlink operation exceeded the timeout of ${timeoutMs}ms`);
182+
}
183+
else {
184+
core.debug(`Failed to delete archive: ${error}`);
185+
}
186+
throw error;
187+
}
188+
});
189+
}
162190
/**
163191
* Saves a list of files with the specified key
164192
*
@@ -318,7 +346,6 @@ function getRequestOptions() {
318346
}
319347
function createHttpClient() {
320348
const token = process.env['BLACKSMITH_CACHE_TOKEN'];
321-
core.debug(`BLACKSMITH_CACHE_TOKEN: ${token}`);
322349
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token !== null && token !== void 0 ? token : '');
323350
return new http_client_1.HttpClient('useblacksmith/cache', [bearerCredentialHandler], getRequestOptions());
324351
}
@@ -992,6 +1019,7 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
9921019
yield fdesc.sync();
9931020
progressLogger = new DownloadProgress(fileSize);
9941021
progressLogger.startDisplayTimer();
1022+
core.info(`Downloading ${archivePath}`);
9951023
// Divvy up the download into chunks based on CONCURRENCY
9961024
const chunkSize = Math.ceil(fileSize / CONCURRENCY);
9971025
const chunkRanges = [];
@@ -1017,9 +1045,21 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
10171045
}));
10181046
yield Promise.all(downloads);
10191047
}
1048+
catch (err) {
1049+
core.warning(`Failed to download cache: ${err}`);
1050+
throw err;
1051+
}
10201052
finally {
1021-
yield fdesc.close();
1053+
// Stop the progress logger regardless of whether the download succeeded or failed.
1054+
// Not doing this will cause the entire action to halt if the download fails.
10221055
progressLogger === null || progressLogger === void 0 ? void 0 : progressLogger.stopDisplayTimer();
1056+
try {
1057+
yield fdesc.close();
1058+
}
1059+
catch (err) {
1060+
// Intentionally swallow any errors in closing the file descriptor.
1061+
core.warning(`Failed to close file descriptor: ${err}`);
1062+
}
10231063
}
10241064
});
10251065
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"author": "GitHub",
2626
"license": "MIT",
2727
"dependencies": {
28-
"@actions/cache": "npm:@useblacksmith/cache@3.2.41",
28+
"@actions/cache": "npm:@useblacksmith/cache@3.2.48",
2929
"@actions/core": "^1.10.0",
3030
"@actions/exec": "^1.1.0",
3131
"@actions/glob": "^0.4.0",

0 commit comments

Comments
 (0)
0