Skip to content

Commit 9781783

Browse files
committed
workaround for #91
1 parent f5ff338 commit 9781783

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

dist/index.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const core = __nccwpck_require__(2186);
2525
const io = __nccwpck_require__(7436);
2626
const tools = __nccwpck_require__(7784);
2727
const path = __nccwpck_require__(1017);
28+
const fs = __nccwpck_require__(7147);
2829
const semver_1 = __nccwpck_require__(1383);
2930
const catalog = __nccwpck_require__(5284);
3031
const shared = __nccwpck_require__(6946);
@@ -261,16 +262,36 @@ class ToolsGetter {
261262
restoreCache(outPath, key) {
262263
return cache.restoreCache([outPath], key.toString());
263264
}
265+
extract(archiveSuffix, downloaded, outputPath) {
266+
return __awaiter(this, void 0, void 0, function* () {
267+
try {
268+
yield extractFunction[archiveSuffix](downloaded, outputPath);
269+
}
270+
catch (exception) {
271+
// Fix up the path for https://github.com/actions/toolkit/issues/1179
272+
if (process.platform === 'win32') {
273+
const zipExtension = ".zip";
274+
if (path.extname(downloaded) !== zipExtension) {
275+
const downloadedZip = downloaded + zipExtension;
276+
fs.renameSync(downloaded, downloadedZip);
277+
return yield extractFunction[archiveSuffix](downloadedZip, outputPath);
278+
}
279+
}
280+
throw exception;
281+
}
282+
return downloaded;
283+
});
284+
}
264285
downloadTools(cmakePackage, ninjaPackage, outputPath) {
265286
return __awaiter(this, void 0, void 0, function* () {
266287
let outPath;
267288
yield core.group("Downloading and extracting CMake", () => __awaiter(this, void 0, void 0, function* () {
268289
const downloaded = yield tools.downloadTool(cmakePackage.url);
269-
yield extractFunction[cmakePackage.dropSuffix](downloaded, outputPath);
290+
yield this.extract(cmakePackage.dropSuffix, downloaded, outputPath);
270291
}));
271292
yield core.group("Downloading and extracting Ninja", () => __awaiter(this, void 0, void 0, function* () {
272293
const downloaded = yield tools.downloadTool(ninjaPackage.url);
273-
yield extractFunction[ninjaPackage.dropSuffix](downloaded, outputPath);
294+
yield this.extract(ninjaPackage.dropSuffix, downloaded, outputPath);
274295
}));
275296
});
276297
}

src/get-cmake.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as core from '@actions/core';
77
import * as io from '@actions/io';
88
import * as tools from '@actions/tool-cache';
99
import * as path from 'path';
10+
import * as fs from 'fs';
1011
import { SemVer, maxSatisfying } from 'semver';
1112
import * as catalog from './releases-catalog'
1213
import * as shared from './releases-collector'
@@ -256,18 +257,38 @@ export class ToolsGetter {
256257
return cache.restoreCache([outPath], key.toString());
257258
}
258259

260+
private async extract(archiveSuffix: string, downloaded: string, outputPath: string): Promise<string> {
261+
try {
262+
await extractFunction[archiveSuffix](downloaded, outputPath);
263+
} catch (exception) {
264+
// Fix up the downloaded archive extension for https://github.com/actions/toolkit/issues/1179
265+
if (process.platform === 'win32') {
266+
const zipExtension = ".zip";
267+
if (path.extname(downloaded) !== zipExtension) {
268+
const downloadedZip = downloaded + zipExtension;
269+
fs.renameSync(downloaded, downloadedZip);
270+
return await extractFunction[archiveSuffix](downloadedZip, outputPath);
271+
}
272+
}
273+
274+
throw exception;
275+
}
276+
277+
return downloaded;
278+
}
279+
259280
private async downloadTools(
260281
cmakePackage: shared.PackageInfo, ninjaPackage: shared.PackageInfo,
261282
outputPath: string): Promise<void> {
262283
let outPath: string;
263284
await core.group("Downloading and extracting CMake", async () => {
264285
const downloaded = await tools.downloadTool(cmakePackage.url);
265-
await extractFunction[cmakePackage.dropSuffix](downloaded, outputPath);
286+
await this.extract(cmakePackage.dropSuffix, downloaded, outputPath);
266287
});
267288

268289
await core.group("Downloading and extracting Ninja", async () => {
269290
const downloaded = await tools.downloadTool(ninjaPackage.url);
270-
await extractFunction[ninjaPackage.dropSuffix](downloaded, outputPath);
291+
await this.extract(ninjaPackage.dropSuffix, downloaded, outputPath);
271292
});
272293
}
273294

0 commit comments

Comments
 (0)