Skip to content

Commit ffeb6e1

Browse files
author
Vladimir Safonkin
committed
Check arch from action input for windows platform
1 parent 13ae5bb commit ffeb6e1

File tree

3 files changed

+142
-240
lines changed

3 files changed

+142
-240
lines changed

dist/cache-save/index.js

Lines changed: 68 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,7 @@ function resolvePaths(patterns) {
525525
.replace(new RegExp(`\\${path.sep}`, 'g'), '/');
526526
core.debug(`Matched: ${relativeFile}`);
527527
// Paths are made relative so the tar entries are all relative to the root of the workspace.
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-
}
528+
paths.push(`${relativeFile}`);
535529
}
536530
}
537531
catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -689,7 +683,6 @@ const util = __importStar(__nccwpck_require__(3837));
689683
const utils = __importStar(__nccwpck_require__(1518));
690684
const constants_1 = __nccwpck_require__(8840);
691685
const requestUtils_1 = __nccwpck_require__(3981);
692-
const abort_controller_1 = __nccwpck_require__(2557);
693686
/**
694687
* Pipes the body of a HTTP response to a stream
695688
*
@@ -873,24 +866,15 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
873866
const fd = fs.openSync(archivePath, 'w');
874867
try {
875868
downloadProgress.startDisplayTimer();
876-
const controller = new abort_controller_1.AbortController();
877-
const abortSignal = controller.signal;
878869
while (!downloadProgress.isDone()) {
879870
const segmentStart = downloadProgress.segmentOffset + downloadProgress.segmentSize;
880871
const segmentSize = Math.min(maxSegmentSize, contentLength - segmentStart);
881872
downloadProgress.nextSegment(segmentSize);
882-
const result = yield promiseWithTimeout(options.segmentTimeoutInMs || 3600000, client.downloadToBuffer(segmentStart, segmentSize, {
883-
abortSignal,
873+
const result = yield client.downloadToBuffer(segmentStart, segmentSize, {
884874
concurrency: options.downloadConcurrency,
885875
onProgress: downloadProgress.onProgress()
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-
}
876+
});
877+
fs.writeFileSync(fd, result);
894878
}
895879
}
896880
finally {
@@ -901,16 +885,6 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
901885
});
902886
}
903887
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-
});
914888
//# sourceMappingURL=downloadUtils.js.map
915889

916890
/***/ }),
@@ -1070,7 +1044,6 @@ const fs_1 = __nccwpck_require__(7147);
10701044
const path = __importStar(__nccwpck_require__(1017));
10711045
const utils = __importStar(__nccwpck_require__(1518));
10721046
const constants_1 = __nccwpck_require__(8840);
1073-
const IS_WINDOWS = process.platform === 'win32';
10741047
function getTarPath(args, compressionMethod) {
10751048
return __awaiter(this, void 0, void 0, function* () {
10761049
switch (process.platform) {
@@ -1118,43 +1091,26 @@ function getWorkingDirectory() {
11181091
var _a;
11191092
return (_a = process.env['GITHUB_WORKSPACE']) !== null && _a !== void 0 ? _a : process.cwd();
11201093
}
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;
11511094
function extractTar(archivePath, compressionMethod) {
11521095
return __awaiter(this, void 0, void 0, function* () {
11531096
// Create directory to extract tar into
11541097
const workingDirectory = getWorkingDirectory();
11551098
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+
}
11561112
const args = [
1157-
...getCompressionProgram(compressionMethod),
1113+
...getCompressionProgram(),
11581114
'-xf',
11591115
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
11601116
'-P',
@@ -1173,19 +1129,15 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) {
11731129
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join('\n'));
11741130
const workingDirectory = getWorkingDirectory();
11751131
// -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'
11771132
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
11781133
// Using 30 here because we also support 32-bit self-hosted runners.
11791134
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
11801135
function getCompressionProgram() {
11811136
switch (compressionMethod) {
11821137
case constants_1.CompressionMethod.Zstd:
1183-
return [
1184-
'--use-compress-program',
1185-
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
1186-
];
1138+
return ['--use-compress-program', 'zstd -T0 --long=30'];
11871139
case constants_1.CompressionMethod.ZstdWithoutLong:
1188-
return ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt'];
1140+
return ['--use-compress-program', 'zstd -T0'];
11891141
default:
11901142
return ['-z'];
11911143
}
@@ -1207,6 +1159,32 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) {
12071159
});
12081160
}
12091161
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;
12101188
//# sourceMappingURL=tar.js.map
12111189

12121190
/***/ }),
@@ -1257,8 +1235,7 @@ function getDownloadOptions(copy) {
12571235
const result = {
12581236
useAzureSdk: true,
12591237
downloadConcurrency: 8,
1260-
timeoutInMs: 30000,
1261-
segmentTimeoutInMs: 3600000
1238+
timeoutInMs: 30000
12621239
};
12631240
if (copy) {
12641241
if (typeof copy.useAzureSdk === 'boolean') {
@@ -1270,21 +1247,10 @@ function getDownloadOptions(copy) {
12701247
if (typeof copy.timeoutInMs === 'number') {
12711248
result.timeoutInMs = copy.timeoutInMs;
12721249
}
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;
12821250
}
12831251
core.debug(`Use Azure SDK: ${result.useAzureSdk}`);
12841252
core.debug(`Download concurrency: ${result.downloadConcurrency}`);
12851253
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}`);
12881254
return result;
12891255
}
12901256
exports.getDownloadOptions = getDownloadOptions;
@@ -4865,6 +4831,7 @@ const file_command_1 = __nccwpck_require__(717);
48654831
const utils_1 = __nccwpck_require__(5278);
48664832
const os = __importStar(__nccwpck_require__(2037));
48674833
const path = __importStar(__nccwpck_require__(1017));
4834+
const uuid_1 = __nccwpck_require__(8974);
48684835
const oidc_utils_1 = __nccwpck_require__(8041);
48694836
/**
48704837
* The code to exit an action
@@ -4894,9 +4861,20 @@ function exportVariable(name, val) {
48944861
process.env[name] = convertedVal;
48954862
const filePath = process.env['GITHUB_ENV'] || '';
48964863
if (filePath) {
4897-
return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val));
4864+
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
4865+
// These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter.
4866+
if (name.includes(delimiter)) {
4867+
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
4868+
}
4869+
if (convertedVal.includes(delimiter)) {
4870+
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
4871+
}
4872+
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
4873+
file_command_1.issueCommand('ENV', commandValue);
4874+
}
4875+
else {
4876+
command_1.issueCommand('set-env', { name }, convertedVal);
48984877
}
4899-
command_1.issueCommand('set-env', { name }, convertedVal);
49004878
}
49014879
exports.exportVariable = exportVariable;
49024880
/**
@@ -4914,7 +4892,7 @@ exports.setSecret = setSecret;
49144892
function addPath(inputPath) {
49154893
const filePath = process.env['GITHUB_PATH'] || '';
49164894
if (filePath) {
4917-
file_command_1.issueFileCommand('PATH', inputPath);
4895+
file_command_1.issueCommand('PATH', inputPath);
49184896
}
49194897
else {
49204898
command_1.issueCommand('add-path', {}, inputPath);
@@ -4954,10 +4932,7 @@ function getMultilineInput(name, options) {
49544932
const inputs = getInput(name, options)
49554933
.split('\n')
49564934
.filter(x => x !== '');
4957-
if (options && options.trimWhitespace === false) {
4958-
return inputs;
4959-
}
4960-
return inputs.map(input => input.trim());
4935+
return inputs;
49614936
}
49624937
exports.getMultilineInput = getMultilineInput;
49634938
/**
@@ -4990,12 +4965,8 @@ exports.getBooleanInput = getBooleanInput;
49904965
*/
49914966
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49924967
function setOutput(name, value) {
4993-
const filePath = process.env['GITHUB_OUTPUT'] || '';
4994-
if (filePath) {
4995-
return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
4996-
}
49974968
process.stdout.write(os.EOL);
4998-
command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
4969+
command_1.issueCommand('set-output', { name }, value);
49994970
}
50004971
exports.setOutput = setOutput;
50014972
/**
@@ -5124,11 +5095,7 @@ exports.group = group;
51245095
*/
51255096
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51265097
function saveState(name, value) {
5127-
const filePath = process.env['GITHUB_STATE'] || '';
5128-
if (filePath) {
5129-
return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value));
5130-
}
5131-
command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value));
5098+
command_1.issueCommand('save-state', { name }, value);
51325099
}
51335100
exports.saveState = saveState;
51345101
/**
@@ -5194,14 +5161,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
51945161
return result;
51955162
};
51965163
Object.defineProperty(exports, "__esModule", ({ value: true }));
5197-
exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
5164+
exports.issueCommand = void 0;
51985165
// We use any as a valid input type
51995166
/* eslint-disable @typescript-eslint/no-explicit-any */
52005167
const fs = __importStar(__nccwpck_require__(7147));
52015168
const os = __importStar(__nccwpck_require__(2037));
5202-
const uuid_1 = __nccwpck_require__(8974);
52035169
const utils_1 = __nccwpck_require__(5278);
5204-
function issueFileCommand(command, message) {
5170+
function issueCommand(command, message) {
52055171
const filePath = process.env[`GITHUB_${command}`];
52065172
if (!filePath) {
52075173
throw new Error(`Unable to find environment variable for file command ${command}`);
@@ -5213,22 +5179,7 @@ function issueFileCommand(command, message) {
52135179
encoding: 'utf8'
52145180
});
52155181
}
5216-
exports.issueFileCommand = issueFileCommand;
5217-
function prepareKeyValueMessage(key, value) {
5218-
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
5219-
const convertedValue = utils_1.toCommandValue(value);
5220-
// These should realistically never happen, but just in case someone finds a
5221-
// way to exploit uuid generation let's not allow keys or values that contain
5222-
// the delimiter.
5223-
if (key.includes(delimiter)) {
5224-
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
5225-
}
5226-
if (convertedValue.includes(delimiter)) {
5227-
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
5228-
}
5229-
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
5230-
}
5231-
exports.prepareKeyValueMessage = prepareKeyValueMessage;
5182+
exports.issueCommand = issueCommand;
52325183
//# sourceMappingURL=file-command.js.map
52335184

52345185
/***/ }),

0 commit comments

Comments
 (0)