Skip to content

Commit 036a523

Browse files
Fix: Add .zip extension to Windows package downloads for Expand-Archive Compatibility (#916)
* Fix: specify filename during Windows package download * Changed unit test download urls
1 parent 04c1311 commit 036a523

File tree

5 files changed

+77
-8
lines changed

5 files changed

+77
-8
lines changed

Diff for: __tests__/utils.test.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
getVersionInputFromFile,
1313
getVersionInputFromPlainFile,
1414
getVersionInputFromTomlFile,
15-
getNextPageUrl
15+
getNextPageUrl,
16+
IS_WINDOWS,
17+
getDownloadFileName
1618
} from '../src/utils';
1719

1820
jest.mock('@actions/cache');
@@ -159,3 +161,37 @@ describe('getNextPageUrl', () => {
159161
expect(getNextPageUrl(generateResponse(page2Links))).toBeNull();
160162
});
161163
});
164+
165+
describe('getDownloadFileName', () => {
166+
const originalEnv = process.env;
167+
const tempDir = path.join(__dirname, 'runner', 'temp');
168+
169+
beforeEach(() => {
170+
process.env = {...originalEnv};
171+
});
172+
173+
afterEach(() => {
174+
process.env = originalEnv;
175+
});
176+
177+
it('should return the correct path on Windows', () => {
178+
if (IS_WINDOWS) {
179+
process.env['RUNNER_TEMP'] = tempDir;
180+
const downloadUrl =
181+
'https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-win32-x64.zip';
182+
const expectedPath = path.join(
183+
process.env.RUNNER_TEMP,
184+
path.basename(downloadUrl)
185+
);
186+
expect(getDownloadFileName(downloadUrl)).toBe(expectedPath);
187+
}
188+
});
189+
190+
it('should return undefined on non-Windows', () => {
191+
if (!IS_WINDOWS) {
192+
const downloadUrl =
193+
'https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz';
194+
expect(getDownloadFileName(downloadUrl)).toBeUndefined();
195+
}
196+
});
197+
});

Diff for: dist/setup/index.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -91441,7 +91441,8 @@ function installPyPy(pypyVersion, pythonVersion, architecture, allowPreReleases,
9144191441
const downloadUrl = `${foundAsset.download_url}`;
9144291442
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
9144391443
try {
91444-
const pypyPath = yield tc.downloadTool(downloadUrl);
91444+
const fileName = (0, utils_1.getDownloadFileName)(downloadUrl);
91445+
const pypyPath = yield tc.downloadTool(downloadUrl, fileName);
9144591446
core.info('Extracting downloaded archive...');
9144691447
if (utils_1.IS_WINDOWS) {
9144791448
downloadDir = yield tc.extractZip(pypyPath);
@@ -91703,7 +91704,8 @@ function installCpythonFromRelease(release) {
9170391704
core.info(`Download from "${downloadUrl}"`);
9170491705
let pythonPath = '';
9170591706
try {
91706-
pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
91707+
const fileName = (0, utils_1.getDownloadFileName)(downloadUrl);
91708+
pythonPath = yield tc.downloadTool(downloadUrl, fileName, AUTH);
9170791709
core.info('Extract downloaded archive');
9170891710
let pythonExtractedFolder;
9170991711
if (utils_1.IS_WINDOWS) {
@@ -91938,7 +91940,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9193891940
return (mod && mod.__esModule) ? mod : { "default": mod };
9193991941
};
9194091942
Object.defineProperty(exports, "__esModule", ({ value: true }));
91941-
exports.getNextPageUrl = exports.getBinaryDirectory = exports.getVersionInputFromFile = exports.getVersionInputFromPlainFile = exports.getVersionInputFromTomlFile = exports.getOSInfo = exports.getLinuxInfo = exports.logWarning = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
91943+
exports.getDownloadFileName = exports.getNextPageUrl = exports.getBinaryDirectory = exports.getVersionInputFromFile = exports.getVersionInputFromPlainFile = exports.getVersionInputFromTomlFile = exports.getOSInfo = exports.getLinuxInfo = exports.logWarning = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
9194291944
/* eslint no-unsafe-finally: "off" */
9194391945
const cache = __importStar(__nccwpck_require__(7799));
9194491946
const core = __importStar(__nccwpck_require__(2186));
@@ -92198,6 +92200,20 @@ function getNextPageUrl(response) {
9219892200
return null;
9219992201
}
9220092202
exports.getNextPageUrl = getNextPageUrl;
92203+
/**
92204+
* Add temporary fix for Windows
92205+
* On Windows, it is necessary to retain the .zip extension for proper extraction.
92206+
* because the tc.extractZip() failure due to tc.downloadTool() not adding .zip extension.
92207+
* Related issue: https://github.com/actions/toolkit/issues/1179
92208+
* Related issue: https://github.com/actions/setup-python/issues/819
92209+
*/
92210+
function getDownloadFileName(downloadUrl) {
92211+
const tempDir = process.env.RUNNER_TEMP || '.';
92212+
return exports.IS_WINDOWS
92213+
? path.join(tempDir, path.basename(downloadUrl))
92214+
: undefined;
92215+
}
92216+
exports.getDownloadFileName = getDownloadFileName;
9220192217

9220292218

9220392219
/***/ }),

Diff for: src/install-pypy.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
createSymlinkInFolder,
1515
isNightlyKeyword,
1616
writeExactPyPyVersionFile,
17-
getBinaryDirectory
17+
getBinaryDirectory,
18+
getDownloadFileName
1819
} from './utils';
1920

2021
export async function installPyPy(
@@ -69,7 +70,8 @@ export async function installPyPy(
6970
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
7071

7172
try {
72-
const pypyPath = await tc.downloadTool(downloadUrl);
73+
const fileName = getDownloadFileName(downloadUrl);
74+
const pypyPath = await tc.downloadTool(downloadUrl, fileName);
7375

7476
core.info('Extracting downloaded archive...');
7577
if (IS_WINDOWS) {

Diff for: src/install-python.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as tc from '@actions/tool-cache';
44
import * as exec from '@actions/exec';
55
import * as httpm from '@actions/http-client';
66
import {ExecOptions} from '@actions/exec/lib/interfaces';
7-
import {IS_WINDOWS, IS_LINUX} from './utils';
7+
import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';
88

99
const TOKEN = core.getInput('token');
1010
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
@@ -98,7 +98,8 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
9898
core.info(`Download from "${downloadUrl}"`);
9999
let pythonPath = '';
100100
try {
101-
pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
101+
const fileName = getDownloadFileName(downloadUrl);
102+
pythonPath = await tc.downloadTool(downloadUrl, fileName, AUTH);
102103
core.info('Extract downloaded archive');
103104
let pythonExtractedFolder;
104105
if (IS_WINDOWS) {

Diff for: src/utils.ts

+14
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,17 @@ export function getNextPageUrl<T>(response: ifm.TypedResponse<T>) {
310310
}
311311
return null;
312312
}
313+
314+
/**
315+
* Add temporary fix for Windows
316+
* On Windows, it is necessary to retain the .zip extension for proper extraction.
317+
* because the tc.extractZip() failure due to tc.downloadTool() not adding .zip extension.
318+
* Related issue: https://github.com/actions/toolkit/issues/1179
319+
* Related issue: https://github.com/actions/setup-python/issues/819
320+
*/
321+
export function getDownloadFileName(downloadUrl: string): string | undefined {
322+
const tempDir = process.env.RUNNER_TEMP || '.';
323+
return IS_WINDOWS
324+
? path.join(tempDir, path.basename(downloadUrl))
325+
: undefined;
326+
}

0 commit comments

Comments
 (0)