@@ -525,7 +525,13 @@ function resolvePaths(patterns) {
525
525
.replace(new RegExp(`\\${path.sep}`, 'g'), '/');
526
526
core.debug(`Matched: ${relativeFile}`);
527
527
// Paths are made relative so the tar entries are all relative to the root of the workspace.
528
- paths.push(`${relativeFile}`);
528
+ if (relativeFile === '') {
529
+ // path.relative returns empty string if workspace and file are equal
530
+ paths.push('.');
531
+ }
532
+ else {
533
+ paths.push(`${relativeFile}`);
534
+ }
529
535
}
530
536
}
531
537
catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -683,6 +689,7 @@ const util = __importStar(__nccwpck_require__(3837));
683
689
const utils = __importStar(__nccwpck_require__(1518));
684
690
const constants_1 = __nccwpck_require__(8840);
685
691
const requestUtils_1 = __nccwpck_require__(3981);
692
+ const abort_controller_1 = __nccwpck_require__(2557);
686
693
/**
687
694
* Pipes the body of a HTTP response to a stream
688
695
*
@@ -866,15 +873,24 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
866
873
const fd = fs.openSync(archivePath, 'w');
867
874
try {
868
875
downloadProgress.startDisplayTimer();
876
+ const controller = new abort_controller_1.AbortController();
877
+ const abortSignal = controller.signal;
869
878
while (!downloadProgress.isDone()) {
870
879
const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize;
871
880
const segmentSize = Math.min(maxSegmentSize, contentLength - segmentStart);
872
881
downloadProgress.nextSegment(segmentSize);
873
- const result = yield client.downloadToBuffer(segmentStart, segmentSize, {
882
+ const result = yield promiseWithTimeout(options.segmentTimeoutInMs || 3600000, client.downloadToBuffer(segmentStart, segmentSize, {
883
+ abortSignal,
874
884
concurrency: options.downloadConcurrency,
875
885
onProgress: downloadProgress.onProgress()
876
- });
877
- fs.writeFileSync(fd, result);
886
+ }));
887
+ if (result === 'timeout') {
888
+ controller.abort();
889
+ throw new Error('Aborting cache download as the download time exceeded the timeout.');
890
+ }
891
+ else if (Buffer.isBuffer(result)) {
892
+ fs.writeFileSync(fd, result);
893
+ }
878
894
}
879
895
}
880
896
finally {
@@ -885,6 +901,16 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
885
901
});
886
902
}
887
903
exports.downloadCacheStorageSDK = downloadCacheStorageSDK;
904
+ const promiseWithTimeout = (timeoutMs, promise) => __awaiter(void 0, void 0, void 0, function* () {
905
+ let timeoutHandle;
906
+ const timeoutPromise = new Promise(resolve => {
907
+ timeoutHandle = setTimeout(() => resolve('timeout'), timeoutMs);
908
+ });
909
+ return Promise.race([promise, timeoutPromise]).then(result => {
910
+ clearTimeout(timeoutHandle);
911
+ return result;
912
+ });
913
+ });
888
914
//# sourceMappingURL=downloadUtils.js.map
889
915
890
916
/***/ }),
@@ -1044,6 +1070,7 @@ const fs_1 = __nccwpck_require__(7147);
1044
1070
const path = __importStar(__nccwpck_require__(1017));
1045
1071
const utils = __importStar(__nccwpck_require__(1518));
1046
1072
const constants_1 = __nccwpck_require__(8840);
1073
+ const IS_WINDOWS = process.platform === 'win32';
1047
1074
function getTarPath(args, compressionMethod) {
1048
1075
return __awaiter(this, void 0, void 0, function* () {
1049
1076
switch (process.platform) {
@@ -1091,26 +1118,43 @@ function getWorkingDirectory() {
1091
1118
var _a;
1092
1119
return (_a = process.env['GITHUB_WORKSPACE']) !== null && _a !== void 0 ? _a : process.cwd();
1093
1120
}
1121
+ // Common function for extractTar and listTar to get the compression method
1122
+ function getCompressionProgram(compressionMethod) {
1123
+ // -d: Decompress.
1124
+ // unzstd is equivalent to 'zstd -d'
1125
+ // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
1126
+ // Using 30 here because we also support 32-bit self-hosted runners.
1127
+ switch (compressionMethod) {
1128
+ case constants_1.CompressionMethod.Zstd:
1129
+ return [
1130
+ '--use-compress-program',
1131
+ IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
1132
+ ];
1133
+ case constants_1.CompressionMethod.ZstdWithoutLong:
1134
+ return ['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd'];
1135
+ default:
1136
+ return ['-z'];
1137
+ }
1138
+ }
1139
+ function listTar(archivePath, compressionMethod) {
1140
+ return __awaiter(this, void 0, void 0, function* () {
1141
+ const args = [
1142
+ ...getCompressionProgram(compressionMethod),
1143
+ '-tf',
1144
+ archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
1145
+ '-P'
1146
+ ];
1147
+ yield execTar(args, compressionMethod);
1148
+ });
1149
+ }
1150
+ exports.listTar = listTar;
1094
1151
function extractTar(archivePath, compressionMethod) {
1095
1152
return __awaiter(this, void 0, void 0, function* () {
1096
1153
// Create directory to extract tar into
1097
1154
const workingDirectory = getWorkingDirectory();
1098
1155
yield io.mkdirP(workingDirectory);
1099
- // --d: Decompress.
1100
- // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
1101
- // Using 30 here because we also support 32-bit self-hosted runners.
1102
- function getCompressionProgram() {
1103
- switch (compressionMethod) {
1104
- case constants_1.CompressionMethod.Zstd:
1105
- return ['--use-compress-program', 'zstd -d --long=30'];
1106
- case constants_1.CompressionMethod.ZstdWithoutLong:
1107
- return ['--use-compress-program', 'zstd -d'];
1108
- default:
1109
- return ['-z'];
1110
- }
1111
- }
1112
1156
const args = [
1113
- ...getCompressionProgram(),
1157
+ ...getCompressionProgram(compressionMethod ),
1114
1158
'-xf',
1115
1159
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
1116
1160
'-P',
@@ -1129,15 +1173,19 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) {
1129
1173
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join('\n'));
1130
1174
const workingDirectory = getWorkingDirectory();
1131
1175
// -T#: Compress using # working thread. If # is 0, attempt to detect and use the number of physical CPU cores.
1176
+ // zstdmt is equivalent to 'zstd -T0'
1132
1177
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
1133
1178
// Using 30 here because we also support 32-bit self-hosted runners.
1134
1179
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
1135
1180
function getCompressionProgram() {
1136
1181
switch (compressionMethod) {
1137
1182
case constants_1.CompressionMethod.Zstd:
1138
- return ['--use-compress-program', 'zstd -T0 --long=30'];
1183
+ return [
1184
+ '--use-compress-program',
1185
+ IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
1186
+ ];
1139
1187
case constants_1.CompressionMethod.ZstdWithoutLong:
1140
- return ['--use-compress-program', 'zstd -T0'];
1188
+ return ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt '];
1141
1189
default:
1142
1190
return ['-z'];
1143
1191
}
@@ -1159,32 +1207,6 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) {
1159
1207
});
1160
1208
}
1161
1209
exports.createTar = createTar;
1162
- function listTar(archivePath, compressionMethod) {
1163
- return __awaiter(this, void 0, void 0, function* () {
1164
- // --d: Decompress.
1165
- // --long=#: Enables long distance matching with # bits.
1166
- // Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
1167
- // Using 30 here because we also support 32-bit self-hosted runners.
1168
- function getCompressionProgram() {
1169
- switch (compressionMethod) {
1170
- case constants_1.CompressionMethod.Zstd:
1171
- return ['--use-compress-program', 'zstd -d --long=30'];
1172
- case constants_1.CompressionMethod.ZstdWithoutLong:
1173
- return ['--use-compress-program', 'zstd -d'];
1174
- default:
1175
- return ['-z'];
1176
- }
1177
- }
1178
- const args = [
1179
- ...getCompressionProgram(),
1180
- '-tf',
1181
- archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
1182
- '-P'
1183
- ];
1184
- yield execTar(args, compressionMethod);
1185
- });
1186
- }
1187
- exports.listTar = listTar;
1188
1210
//# sourceMappingURL=tar.js.map
1189
1211
1190
1212
/***/ }),
@@ -1235,7 +1257,8 @@ function getDownloadOptions(copy) {
1235
1257
const result = {
1236
1258
useAzureSdk: true,
1237
1259
downloadConcurrency: 8,
1238
- timeoutInMs: 30000
1260
+ timeoutInMs: 30000,
1261
+ segmentTimeoutInMs: 3600000
1239
1262
};
1240
1263
if (copy) {
1241
1264
if (typeof copy.useAzureSdk === 'boolean') {
@@ -1247,10 +1270,21 @@ function getDownloadOptions(copy) {
1247
1270
if (typeof copy.timeoutInMs === 'number') {
1248
1271
result.timeoutInMs = copy.timeoutInMs;
1249
1272
}
1273
+ if (typeof copy.segmentTimeoutInMs === 'number') {
1274
+ result.segmentTimeoutInMs = copy.segmentTimeoutInMs;
1275
+ }
1276
+ }
1277
+ const segmentDownloadTimeoutMins = process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS'];
1278
+ if (segmentDownloadTimeoutMins &&
1279
+ !isNaN(Number(segmentDownloadTimeoutMins)) &&
1280
+ isFinite(Number(segmentDownloadTimeoutMins))) {
1281
+ result.segmentTimeoutInMs = Number(segmentDownloadTimeoutMins) * 60 * 1000;
1250
1282
}
1251
1283
core.debug(`Use Azure SDK: ${result.useAzureSdk}`);
1252
1284
core.debug(`Download concurrency: ${result.downloadConcurrency}`);
1253
1285
core.debug(`Request timeout (ms): ${result.timeoutInMs}`);
1286
+ core.debug(`Cache segment download timeout mins env var: ${process.env['SEGMENT_DOWNLOAD_TIMEOUT_MINS']}`);
1287
+ core.debug(`Segment download timeout (ms): ${result.segmentTimeoutInMs}`);
1254
1288
return result;
1255
1289
}
1256
1290
exports.getDownloadOptions = getDownloadOptions;
0 commit comments