Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adityamaru committed Jul 22, 2024
1 parent b5e3ed4 commit cc47902
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 42 deletions.
61 changes: 43 additions & 18 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,25 @@ function downloadCacheAxiosMultiPart(archiveLocation, archivePath) {
});
try {
core.debug(`Downloading from ${archiveLocation} to ${archivePath}`);
const metadataResponse = yield axios_1.default.get(archiveLocation, {
headers: { Range: 'bytes=0-1' }
});
const contentRangeHeader = metadataResponse.headers['content-range'];
let metadataResponse;
let contentRangeHeader;
let retries = 0;
const maxRetries = 2;
while (retries <= maxRetries) {
metadataResponse = yield axios_1.default.get(archiveLocation, {
headers: { Range: 'bytes=0-1' }
});
contentRangeHeader = metadataResponse.headers['content-range'];
if (contentRangeHeader) {
break;
}
retries++;
if (retries <= maxRetries) {
core.debug(`Content-Range header not found. Retrying (${retries}/${maxRetries})...`);
}
}
if (!contentRangeHeader) {
throw new Error('Content-Range is not defined; unable to determine file size');
throw new Error('Content-Range is not defined after retries; unable to determine file size');
}
// Parse the total file size from the Content-Range header
const fileSize = parseInt(contentRangeHeader.split('/')[1]);
Expand Down Expand Up @@ -1247,7 +1260,6 @@ exports.downloadCacheHttpClient = downloadCacheHttpClient;
function downloadCacheHttpClientConcurrent(archiveLocation, archivePath, options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
core.info('Downloading from cache using Blacksmith Actions http-client');
const archiveDescriptor = yield fs.promises.open(archivePath, 'w+');
// Set file permissions so that other users can untar the cache
yield archiveDescriptor.chmod(0o644);
Expand All @@ -1262,19 +1274,32 @@ function downloadCacheHttpClientConcurrent(archiveLocation, archivePath, options
}, 300000);
stallTimeout.unref(); // Don't keep the process alive if the download is stalled.
try {
const metadataResponse = yield (0, requestUtils_1.retryHttpClientResponse)('downloadCache', () => __awaiter(this, void 0, void 0, function* () {
return httpClient.get(archiveLocation, {
Range: 'bytes=0-1'
let metadataResponse;
let contentRangeHeader;
let retries = 0;
const maxRetries = 2;
while (retries <= maxRetries) {
metadataResponse = yield (0, requestUtils_1.retryHttpClientResponse)('downloadCache', () => __awaiter(this, void 0, void 0, function* () {
return httpClient.get(archiveLocation, {
Range: 'bytes=0-1'
});
}));
// Abort download if no traffic received over the socket.
metadataResponse.message.socket.setTimeout(constants_1.SocketTimeout, () => {
metadataResponse.message.destroy();
core.debug(`Aborting download, socket timed out after ${constants_1.SocketTimeout} ms`);
});
}));
// Abort download if no traffic received over the socket.
metadataResponse.message.socket.setTimeout(constants_1.SocketTimeout, () => {
metadataResponse.message.destroy();
core.debug(`Aborting download, socket timed out after ${constants_1.SocketTimeout} ms`);
});
const contentRangeHeader = metadataResponse.message.headers['content-range'];
contentRangeHeader = metadataResponse.message.headers['content-range'];
if (contentRangeHeader) {
break;
}
retries++;
if (retries <= maxRetries) {
core.debug(`Content-Range header not found. Retrying (${retries}/${maxRetries})...`);
}
}
if (!contentRangeHeader) {
throw new Error('Content-Range is not defined; unable to determine file size');
throw new Error('Content-Range is not defined after retries; unable to determine file size');
}
// Parse the total file size from the Content-Range header
const length = parseInt(contentRangeHeader.split('/')[1]);
Expand Down Expand Up @@ -1709,7 +1734,7 @@ function getTarArgs(tarPath, compressionMethod, type, archivePath = '') {
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '--files-from', constants_1.ManifestFilename);
break;
case 'extract':
args.push('--skip-old-files', '-xf', BSD_TAR_ZSTD
args.push('-xf', BSD_TAR_ZSTD
? tarFile
: archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'));
break;
Expand Down
61 changes: 43 additions & 18 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,25 @@ function downloadCacheAxiosMultiPart(archiveLocation, archivePath) {
});
try {
core.debug(`Downloading from ${archiveLocation} to ${archivePath}`);
const metadataResponse = yield axios_1.default.get(archiveLocation, {
headers: { Range: 'bytes=0-1' }
});
const contentRangeHeader = metadataResponse.headers['content-range'];
let metadataResponse;
let contentRangeHeader;
let retries = 0;
const maxRetries = 2;
while (retries <= maxRetries) {
metadataResponse = yield axios_1.default.get(archiveLocation, {
headers: { Range: 'bytes=0-1' }
});
contentRangeHeader = metadataResponse.headers['content-range'];
if (contentRangeHeader) {
break;
}
retries++;
if (retries <= maxRetries) {
core.debug(`Content-Range header not found. Retrying (${retries}/${maxRetries})...`);
}
}
if (!contentRangeHeader) {
throw new Error('Content-Range is not defined; unable to determine file size');
throw new Error('Content-Range is not defined after retries; unable to determine file size');
}
// Parse the total file size from the Content-Range header
const fileSize = parseInt(contentRangeHeader.split('/')[1]);
Expand Down Expand Up @@ -1247,7 +1260,6 @@ exports.downloadCacheHttpClient = downloadCacheHttpClient;
function downloadCacheHttpClientConcurrent(archiveLocation, archivePath, options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
core.info('Downloading from cache using Blacksmith Actions http-client');
const archiveDescriptor = yield fs.promises.open(archivePath, 'w+');
// Set file permissions so that other users can untar the cache
yield archiveDescriptor.chmod(0o644);
Expand All @@ -1262,19 +1274,32 @@ function downloadCacheHttpClientConcurrent(archiveLocation, archivePath, options
}, 300000);
stallTimeout.unref(); // Don't keep the process alive if the download is stalled.
try {
const metadataResponse = yield (0, requestUtils_1.retryHttpClientResponse)('downloadCache', () => __awaiter(this, void 0, void 0, function* () {
return httpClient.get(archiveLocation, {
Range: 'bytes=0-1'
let metadataResponse;
let contentRangeHeader;
let retries = 0;
const maxRetries = 2;
while (retries <= maxRetries) {
metadataResponse = yield (0, requestUtils_1.retryHttpClientResponse)('downloadCache', () => __awaiter(this, void 0, void 0, function* () {
return httpClient.get(archiveLocation, {
Range: 'bytes=0-1'
});
}));
// Abort download if no traffic received over the socket.
metadataResponse.message.socket.setTimeout(constants_1.SocketTimeout, () => {
metadataResponse.message.destroy();
core.debug(`Aborting download, socket timed out after ${constants_1.SocketTimeout} ms`);
});
}));
// Abort download if no traffic received over the socket.
metadataResponse.message.socket.setTimeout(constants_1.SocketTimeout, () => {
metadataResponse.message.destroy();
core.debug(`Aborting download, socket timed out after ${constants_1.SocketTimeout} ms`);
});
const contentRangeHeader = metadataResponse.message.headers['content-range'];
contentRangeHeader = metadataResponse.message.headers['content-range'];
if (contentRangeHeader) {
break;
}
retries++;
if (retries <= maxRetries) {
core.debug(`Content-Range header not found. Retrying (${retries}/${maxRetries})...`);
}
}
if (!contentRangeHeader) {
throw new Error('Content-Range is not defined; unable to determine file size');
throw new Error('Content-Range is not defined after retries; unable to determine file size');
}
// Parse the total file size from the Content-Range header
const length = parseInt(contentRangeHeader.split('/')[1]);
Expand Down Expand Up @@ -1709,7 +1734,7 @@ function getTarArgs(tarPath, compressionMethod, type, archivePath = '') {
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '--files-from', constants_1.ManifestFilename);
break;
case 'extract':
args.push('--skip-old-files', '-xf', BSD_TAR_ZSTD
args.push('-xf', BSD_TAR_ZSTD
? tarFile
: archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'));
break;
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/Swatinem/rust-cache#readme",
"dependencies": {
"@actions/blacksmith-cache": "npm:@useblacksmith/[email protected].131",
"@actions/blacksmith-cache": "npm:@useblacksmith/[email protected].137",
"@actions/buildjet-cache": "npm:[email protected]",
"@actions/cache": "^3.2.3",
"@actions/core": "^1.10.1",
Expand All @@ -39,4 +39,4 @@
"scripts": {
"prepare": "ncc build --target es2020 -o dist/restore src/restore.ts && ncc build --target es2020 -o dist/save src/save.ts && linefix dist"
}
}
}

0 comments on commit cc47902

Please sign in to comment.