Skip to content

Commit

Permalink
Fix: Add .zip extension to Windows package downloads for `Expand-Ar…
Browse files Browse the repository at this point in the history
…chive` Compatibility (#916)

* Fix: specify filename during Windows package download

* Changed unit test download urls
  • Loading branch information
priyagupta108 authored Aug 5, 2024
1 parent 04c1311 commit 036a523
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 8 deletions.
38 changes: 37 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
getVersionInputFromFile,
getVersionInputFromPlainFile,
getVersionInputFromTomlFile,
getNextPageUrl
getNextPageUrl,
IS_WINDOWS,
getDownloadFileName
} from '../src/utils';

jest.mock('@actions/cache');
Expand Down Expand Up @@ -159,3 +161,37 @@ describe('getNextPageUrl', () => {
expect(getNextPageUrl(generateResponse(page2Links))).toBeNull();
});
});

describe('getDownloadFileName', () => {
const originalEnv = process.env;
const tempDir = path.join(__dirname, 'runner', 'temp');

beforeEach(() => {
process.env = {...originalEnv};
});

afterEach(() => {
process.env = originalEnv;
});

it('should return the correct path on Windows', () => {
if (IS_WINDOWS) {
process.env['RUNNER_TEMP'] = tempDir;
const downloadUrl =
'https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-win32-x64.zip';
const expectedPath = path.join(
process.env.RUNNER_TEMP,
path.basename(downloadUrl)
);
expect(getDownloadFileName(downloadUrl)).toBe(expectedPath);
}
});

it('should return undefined on non-Windows', () => {
if (!IS_WINDOWS) {
const downloadUrl =
'https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz';
expect(getDownloadFileName(downloadUrl)).toBeUndefined();
}
});
});
22 changes: 19 additions & 3 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91441,7 +91441,8 @@ function installPyPy(pypyVersion, pythonVersion, architecture, allowPreReleases,
const downloadUrl = `${foundAsset.download_url}`;
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
try {
const pypyPath = yield tc.downloadTool(downloadUrl);
const fileName = (0, utils_1.getDownloadFileName)(downloadUrl);
const pypyPath = yield tc.downloadTool(downloadUrl, fileName);
core.info('Extracting downloaded archive...');
if (utils_1.IS_WINDOWS) {
downloadDir = yield tc.extractZip(pypyPath);
Expand Down Expand Up @@ -91703,7 +91704,8 @@ function installCpythonFromRelease(release) {
core.info(`Download from "${downloadUrl}"`);
let pythonPath = '';
try {
pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
const fileName = (0, utils_1.getDownloadFileName)(downloadUrl);
pythonPath = yield tc.downloadTool(downloadUrl, fileName, AUTH);
core.info('Extract downloaded archive');
let pythonExtractedFolder;
if (utils_1.IS_WINDOWS) {
Expand Down Expand Up @@ -91938,7 +91940,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
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;
/* eslint no-unsafe-finally: "off" */
const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
Expand Down Expand Up @@ -92198,6 +92200,20 @@ function getNextPageUrl(response) {
return null;
}
exports.getNextPageUrl = getNextPageUrl;
/**
* Add temporary fix for Windows
* On Windows, it is necessary to retain the .zip extension for proper extraction.
* because the tc.extractZip() failure due to tc.downloadTool() not adding .zip extension.
* Related issue: https://github.com/actions/toolkit/issues/1179
* Related issue: https://github.com/actions/setup-python/issues/819
*/
function getDownloadFileName(downloadUrl) {
const tempDir = process.env.RUNNER_TEMP || '.';
return exports.IS_WINDOWS
? path.join(tempDir, path.basename(downloadUrl))
: undefined;
}
exports.getDownloadFileName = getDownloadFileName;


/***/ }),
Expand Down
6 changes: 4 additions & 2 deletions src/install-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
createSymlinkInFolder,
isNightlyKeyword,
writeExactPyPyVersionFile,
getBinaryDirectory
getBinaryDirectory,
getDownloadFileName
} from './utils';

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

try {
const pypyPath = await tc.downloadTool(downloadUrl);
const fileName = getDownloadFileName(downloadUrl);
const pypyPath = await tc.downloadTool(downloadUrl, fileName);

core.info('Extracting downloaded archive...');
if (IS_WINDOWS) {
Expand Down
5 changes: 3 additions & 2 deletions src/install-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec';
import * as httpm from '@actions/http-client';
import {ExecOptions} from '@actions/exec/lib/interfaces';
import {IS_WINDOWS, IS_LINUX} from './utils';
import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';

const TOKEN = core.getInput('token');
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
Expand Down Expand Up @@ -98,7 +98,8 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
core.info(`Download from "${downloadUrl}"`);
let pythonPath = '';
try {
pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
const fileName = getDownloadFileName(downloadUrl);
pythonPath = await tc.downloadTool(downloadUrl, fileName, AUTH);
core.info('Extract downloaded archive');
let pythonExtractedFolder;
if (IS_WINDOWS) {
Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,17 @@ export function getNextPageUrl<T>(response: ifm.TypedResponse<T>) {
}
return null;
}

/**
* Add temporary fix for Windows
* On Windows, it is necessary to retain the .zip extension for proper extraction.
* because the tc.extractZip() failure due to tc.downloadTool() not adding .zip extension.
* Related issue: https://github.com/actions/toolkit/issues/1179
* Related issue: https://github.com/actions/setup-python/issues/819
*/
export function getDownloadFileName(downloadUrl: string): string | undefined {
const tempDir = process.env.RUNNER_TEMP || '.';
return IS_WINDOWS
? path.join(tempDir, path.basename(downloadUrl))
: undefined;
}

0 comments on commit 036a523

Please sign in to comment.