4
0
Fork 0
mirror of https://github.com/actions/setup-python.git synced 2025-11-07 05:26:56 +00:00

Compare commits

..

1 commit

Author SHA1 Message Date
Dar
3d4d9f90c2
Merge 21f18ee46a into bba65e51ff 2025-10-20 23:28:03 +01:00
8 changed files with 925 additions and 878 deletions

View file

@ -106,7 +106,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] os: [ubuntu-latest, macos-latest, macos-13]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- name: Setup GraalPy and check latest - name: Setup GraalPy and check latest

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@ import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as finder from '../src/find-graalpy'; import * as finder from '../src/find-graalpy';
import {IGraalPyManifestRelease} from '../src/utils'; import {IGraalPyManifestRelease, IS_WINDOWS} from '../src/utils';
import manifestData from './data/graalpy.json'; import manifestData from './data/graalpy.json';
@ -19,6 +19,9 @@ const architecture = 'x64';
const toolDir = path.join(__dirname, 'runner', 'tools'); const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp'); const tempDir = path.join(__dirname, 'runner', 'temp');
/* GraalPy doesn't have a windows release yet */
const describeSkipOnWindows = IS_WINDOWS ? describe.skip : describe;
describe('parseGraalPyVersion', () => { describe('parseGraalPyVersion', () => {
it.each([ it.each([
['graalpy-23', '23'], ['graalpy-23', '23'],
@ -105,7 +108,7 @@ describe('findGraalPyToolCache', () => {
}); });
}); });
describe('findGraalPyVersion', () => { describeSkipOnWindows('findGraalPyVersion', () => {
let getBooleanInputSpy: jest.SpyInstance; let getBooleanInputSpy: jest.SpyInstance;
let warningSpy: jest.SpyInstance; let warningSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance; let debugSpy: jest.SpyInstance;
@ -355,13 +358,13 @@ describe('findGraalPyVersion', () => {
it('found and install successfully, pre-release fallback', async () => { it('found and install successfully, pre-release fallback', async () => {
spyCacheDir = jest.spyOn(tc, 'cacheDir'); spyCacheDir = jest.spyOn(tc, 'cacheDir');
spyCacheDir.mockImplementation(() => spyCacheDir.mockImplementation(() =>
path.join(toolDir, 'GraalPy', '24.1', architecture) path.join(toolDir, 'GraalPy', '23.1', architecture)
); );
spyChmodSync = jest.spyOn(fs, 'chmodSync'); spyChmodSync = jest.spyOn(fs, 'chmodSync');
spyChmodSync.mockImplementation(() => undefined); spyChmodSync.mockImplementation(() => undefined);
await expect( await expect(
finder.findGraalPyVersion( finder.findGraalPyVersion(
'graalpy24.1', 'graalpy23.1',
architecture, architecture,
false, false,
false, false,
@ -369,7 +372,7 @@ describe('findGraalPyVersion', () => {
) )
).rejects.toThrow(); ).rejects.toThrow();
await expect( await expect(
finder.findGraalPyVersion('graalpy24.1', architecture, false, false, true) finder.findGraalPyVersion('graalpy23.1', architecture, false, false, true)
).resolves.toEqual('24.1.0-ea.9'); ).resolves.toEqual('23.1.0-a.1');
}); });
}); });

View file

@ -21,21 +21,24 @@ const architecture = 'x64';
const toolDir = path.join(__dirname, 'runner', 'tools'); const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp'); const tempDir = path.join(__dirname, 'runner', 'temp');
/* GraalPy doesn't have a windows release yet */
const describeSkipOnWindows = IS_WINDOWS ? describe.skip : describe;
describe('graalpyVersionToSemantic', () => { describe('graalpyVersionToSemantic', () => {
it.each([ it.each([
['graalpy-24.1.0-ea.09', '24.1.0-ea.9'], ['23.0.0a1', '23.0.0a1'],
['graal-23.0.0', '23.0.0'], ['23.0.0', '23.0.0'],
['vm-23.0.x', '23.0.x'], ['23.0.x', '23.0.x'],
['graal-23.x', '23.x'] ['23.x', '23.x']
])('%s -> %s', (input, expected) => { ])('%s -> %s', (input, expected) => {
expect(installer.graalPyTagToVersion(input)).toEqual(expected); expect(installer.graalPyTagToVersion(input)).toEqual(expected);
}); });
}); });
describe('findRelease', () => { describeSkipOnWindows('findRelease', () => {
const result = JSON.stringify(manifestData); const result = JSON.stringify(manifestData);
const releases = JSON.parse(result) as IGraalPyManifestRelease[]; const releases = JSON.parse(result) as IGraalPyManifestRelease[];
const extension = IS_WINDOWS ? 'zip' : 'tar.gz'; const extension = 'tar.gz';
const arch = installer.toGraalPyArchitecture(architecture); const arch = installer.toGraalPyArchitecture(architecture);
const platform = installer.toGraalPyPlatform(process.platform); const platform = installer.toGraalPyPlatform(process.platform);
const extensionName = `${platform}-${arch}.${extension}`; const extensionName = `${platform}-${arch}.${extension}`;
@ -44,8 +47,8 @@ describe('findRelease', () => {
browser_download_url: `https://github.com/oracle/graalpython/releases/download/graal-23.0.0/graalpython-23.0.0-${extensionName}` browser_download_url: `https://github.com/oracle/graalpython/releases/download/graal-23.0.0/graalpython-23.0.0-${extensionName}`
}; };
const filesRC1: IGraalPyManifestAsset = { const filesRC1: IGraalPyManifestAsset = {
name: `graalpy-24.1.0-ea.09-${extensionName}`, name: `graalpython-23.1.0a1-${extensionName}`,
browser_download_url: `https://github.com/graalvm/graal-languages-ea-builds/releases/download/graalpy-24.1.0-ea.09/graalpy-24.1.0-ea.09-${extensionName}` browser_download_url: `https://github.com/oracle/graalpython/releases/download/graal-23.1.0a1/graalpython-23.1.0a1-${extensionName}`
}; };
let warningSpy: jest.SpyInstance; let warningSpy: jest.SpyInstance;
@ -81,15 +84,15 @@ describe('findRelease', () => {
}); });
it('Preview version of GraalPy is found', () => { it('Preview version of GraalPy is found', () => {
const graalpyVersion = installer.graalPyTagToVersion('vm-24.1.0-ea.09'); const graalpyVersion = installer.graalPyTagToVersion('vm-23.1.0a1');
expect( expect(
installer.findRelease(releases, graalpyVersion, architecture, false) installer.findRelease(releases, graalpyVersion, architecture, false)
).toMatchObject({ ).toMatchObject({
foundAsset: { foundAsset: {
name: `graalpy-24.1.0-ea.09-${extensionName}`, name: `graalpython-23.1.0a1-${extensionName}`,
browser_download_url: `https://github.com/graalvm/graal-languages-ea-builds/releases/download/graalpy-24.1.0-ea.09/graalpy-24.1.0-ea.09-${extensionName}` browser_download_url: `https://github.com/oracle/graalpython/releases/download/graal-23.1.0a1/graalpython-23.1.0a1-${extensionName}`
}, },
resolvedGraalPyVersion: '24.1.0-ea.9' resolvedGraalPyVersion: '23.1.0-a.1'
}); });
}); });
@ -104,7 +107,7 @@ describe('findRelease', () => {
}); });
it('GraalPy version matches semver (pre-release)', () => { it('GraalPy version matches semver (pre-release)', () => {
const graalpyVersion = '24.1.x'; const graalpyVersion = '23.1.x';
expect( expect(
installer.findRelease(releases, graalpyVersion, architecture, false) installer.findRelease(releases, graalpyVersion, architecture, false)
).toBeNull(); ).toBeNull();
@ -112,12 +115,12 @@ describe('findRelease', () => {
installer.findRelease(releases, graalpyVersion, architecture, true) installer.findRelease(releases, graalpyVersion, architecture, true)
).toMatchObject({ ).toMatchObject({
foundAsset: filesRC1, foundAsset: filesRC1,
resolvedGraalPyVersion: '24.1.0-ea.9' resolvedGraalPyVersion: '23.1.0-a.1'
}); });
}); });
}); });
describe('installGraalPy', () => { describeSkipOnWindows('installGraalPy', () => {
let tcFind: jest.SpyInstance; let tcFind: jest.SpyInstance;
let warningSpy: jest.SpyInstance; let warningSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance; let debugSpy: jest.SpyInstance;
@ -229,20 +232,20 @@ describe('installGraalPy', () => {
it('found and install GraalPy, pre-release fallback', async () => { it('found and install GraalPy, pre-release fallback', async () => {
spyCacheDir = jest.spyOn(tc, 'cacheDir'); spyCacheDir = jest.spyOn(tc, 'cacheDir');
spyCacheDir.mockImplementation(() => spyCacheDir.mockImplementation(() =>
path.join(toolDir, 'GraalPy', '24.1.0', architecture) path.join(toolDir, 'GraalPy', '23.1.0', architecture)
); );
spyChmodSync = jest.spyOn(fs, 'chmodSync'); spyChmodSync = jest.spyOn(fs, 'chmodSync');
spyChmodSync.mockImplementation(() => undefined); spyChmodSync.mockImplementation(() => undefined);
await expect( await expect(
installer.installGraalPy('24.1.x', architecture, false, undefined) installer.installGraalPy('23.1.x', architecture, false, undefined)
).rejects.toThrow(); ).rejects.toThrow();
await expect( await expect(
installer.installGraalPy('24.1.x', architecture, true, undefined) installer.installGraalPy('23.1.x', architecture, true, undefined)
).resolves.toEqual({ ).resolves.toEqual({
installDir: path.join(toolDir, 'GraalPy', '24.1.0', architecture), installDir: path.join(toolDir, 'GraalPy', '23.1.0', architecture),
resolvedGraalPyVersion: '24.1.0-ea.9' resolvedGraalPyVersion: '23.1.0-a.1'
}); });
expect(spyHttpClient).toHaveBeenCalled(); expect(spyHttpClient).toHaveBeenCalled();

36
dist/setup/index.js vendored
View file

@ -96769,8 +96769,8 @@ async function findGraalPyVersion(versionSpec, architecture, updateEnvironment,
const pipDir = utils_1.IS_WINDOWS ? 'Scripts' : 'bin'; const pipDir = utils_1.IS_WINDOWS ? 'Scripts' : 'bin';
const _binDir = path.join(installDir, pipDir); const _binDir = path.join(installDir, pipDir);
const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : ''; const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : '';
const pythonPath = path.join(_binDir, `python${binaryExtension}`); const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`);
const pythonLocation = path.join(installDir, 'bin'); const pythonLocation = (0, utils_1.getBinaryDirectory)(installDir);
if (updateEnvironment) { if (updateEnvironment) {
core.exportVariable('pythonLocation', installDir); core.exportVariable('pythonLocation', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython // https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
@ -97315,12 +97315,7 @@ async function installGraalPy(graalpyVersion, architecture, allowPreReleases, re
try { try {
const graalpyPath = await tc.downloadTool(downloadUrl, undefined, AUTH); const graalpyPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
core.info('Extracting downloaded archive...'); core.info('Extracting downloaded archive...');
if (utils_1.IS_WINDOWS) { downloadDir = await tc.extractTar(graalpyPath);
downloadDir = await tc.extractZip(graalpyPath);
}
else {
downloadDir = await tc.extractTar(graalpyPath);
}
// root folder in archive can have unpredictable name so just take the first folder // root folder in archive can have unpredictable name so just take the first folder
// downloadDir is unique folder under TEMP and can't contain any other folders // downloadDir is unique folder under TEMP and can't contain any other folders
const archiveName = fs_1.default.readdirSync(downloadDir)[0]; const archiveName = fs_1.default.readdirSync(downloadDir)[0];
@ -97329,7 +97324,7 @@ async function installGraalPy(graalpyVersion, architecture, allowPreReleases, re
if (!(0, utils_1.isNightlyKeyword)(resolvedGraalPyVersion)) { if (!(0, utils_1.isNightlyKeyword)(resolvedGraalPyVersion)) {
installDir = await tc.cacheDir(toolDir, 'GraalPy', resolvedGraalPyVersion, architecture); installDir = await tc.cacheDir(toolDir, 'GraalPy', resolvedGraalPyVersion, architecture);
} }
const binaryPath = path.join(installDir, 'bin'); const binaryPath = (0, utils_1.getBinaryDirectory)(installDir);
await createGraalPySymlink(binaryPath, resolvedGraalPyVersion); await createGraalPySymlink(binaryPath, resolvedGraalPyVersion);
await installPip(binaryPath); await installPip(binaryPath);
return { installDir, resolvedGraalPyVersion }; return { installDir, resolvedGraalPyVersion };
@ -97357,9 +97352,6 @@ async function getAvailableGraalPyVersions() {
if (AUTH) { if (AUTH) {
headers.authorization = AUTH; headers.authorization = AUTH;
} }
/*
Get releases first.
*/
let url = 'https://api.github.com/repos/oracle/graalpython/releases'; let url = 'https://api.github.com/repos/oracle/graalpython/releases';
const result = []; const result = [];
do { do {
@ -97370,19 +97362,6 @@ async function getAvailableGraalPyVersions() {
result.push(...response.result); result.push(...response.result);
url = (0, utils_1.getNextPageUrl)(response); url = (0, utils_1.getNextPageUrl)(response);
} while (url); } while (url);
/*
Add pre-release builds.
*/
url =
'https://api.github.com/repos/graalvm/graal-languages-ea-builds/releases';
do {
const response = await http.getJson(url, headers);
if (!response.result) {
throw new Error(`Unable to retrieve the list of available GraalPy versions from '${url}'`);
}
result.push(...response.result);
url = (0, utils_1.getNextPageUrl)(response);
} while (url);
return result; return result;
} }
async function createGraalPySymlink(graalpyBinaryPath, graalpyVersion) { async function createGraalPySymlink(graalpyBinaryPath, graalpyVersion) {
@ -97402,7 +97381,7 @@ async function installPip(pythonLocation) {
await exec.exec(`${pythonBinary} -m ensurepip --default-pip`); await exec.exec(`${pythonBinary} -m ensurepip --default-pip`);
} }
function graalPyTagToVersion(tag) { function graalPyTagToVersion(tag) {
const versionPattern = /.*-(\d+\.\d+\.\d+(?:\.\d+)?)(?:-((?:ea|a|b|rc))\.0*(\d+))?/; const versionPattern = /.*-(\d+\.\d+\.\d+(?:\.\d+)?)((?:a|b|rc))?(\d*)?/;
const match = tag.match(versionPattern); const match = tag.match(versionPattern);
if (match && match[2]) { if (match && match[2]) {
return `${match[1]}-${match[2]}.${match[3]}`; return `${match[1]}-${match[2]}.${match[3]}`;
@ -97452,9 +97431,8 @@ function toGraalPyArchitecture(architecture) {
function findAsset(item, architecture, platform) { function findAsset(item, architecture, platform) {
const graalpyArch = toGraalPyArchitecture(architecture); const graalpyArch = toGraalPyArchitecture(architecture);
const graalpyPlatform = toGraalPyPlatform(platform); const graalpyPlatform = toGraalPyPlatform(platform);
const graalpyExt = platform == 'win32' ? 'zip' : 'tar.gz';
const found = item.assets.filter(file => file.name.startsWith('graalpy') && const found = item.assets.filter(file => file.name.startsWith('graalpy') &&
file.name.endsWith(`-${graalpyPlatform}-${graalpyArch}.${graalpyExt}`)); file.name.endsWith(`-${graalpyPlatform}-${graalpyArch}.tar.gz`));
/* /*
In the future there could be more variants of GraalPy for a single release. Pick the shortest name, that one is the most likely to be the primary variant. In the future there could be more variants of GraalPy for a single release. Pick the shortest name, that one is the most likely to be the primary variant.
*/ */
@ -98385,7 +98363,7 @@ function getVersionInputFromFile(versionFile) {
} }
} }
/** /**
* Get the directory containing interpreter binary from installation directory of PyPy * Get the directory containing interpreter binary from installation directory of PyPy or GraalPy
* - On Linux and macOS, the Python interpreter is in 'bin'. * - On Linux and macOS, the Python interpreter is in 'bin'.
* - On Windows, it is in the installation root. * - On Windows, it is in the installation root.
*/ */

View file

@ -1,6 +1,11 @@
import * as path from 'path'; import * as path from 'path';
import * as graalpyInstall from './install-graalpy'; import * as graalpyInstall from './install-graalpy';
import {IS_WINDOWS, validateVersion, IGraalPyManifestRelease} from './utils'; import {
IS_WINDOWS,
validateVersion,
IGraalPyManifestRelease,
getBinaryDirectory
} from './utils';
import * as semver from 'semver'; import * as semver from 'semver';
import * as core from '@actions/core'; import * as core from '@actions/core';
@ -57,8 +62,11 @@ export async function findGraalPyVersion(
const pipDir = IS_WINDOWS ? 'Scripts' : 'bin'; const pipDir = IS_WINDOWS ? 'Scripts' : 'bin';
const _binDir = path.join(installDir, pipDir); const _binDir = path.join(installDir, pipDir);
const binaryExtension = IS_WINDOWS ? '.exe' : ''; const binaryExtension = IS_WINDOWS ? '.exe' : '';
const pythonPath = path.join(_binDir, `python${binaryExtension}`); const pythonPath = path.join(
const pythonLocation = path.join(installDir, 'bin'); IS_WINDOWS ? installDir : _binDir,
`python${binaryExtension}`
);
const pythonLocation = getBinaryDirectory(installDir);
if (updateEnvironment) { if (updateEnvironment) {
core.exportVariable('pythonLocation', installDir); core.exportVariable('pythonLocation', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython // https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython

View file

@ -15,6 +15,7 @@ import {
IGraalPyManifestRelease, IGraalPyManifestRelease,
createSymlinkInFolder, createSymlinkInFolder,
isNightlyKeyword, isNightlyKeyword,
getBinaryDirectory,
getNextPageUrl getNextPageUrl
} from './utils'; } from './utils';
@ -63,11 +64,7 @@ export async function installGraalPy(
const graalpyPath = await tc.downloadTool(downloadUrl, undefined, AUTH); const graalpyPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
core.info('Extracting downloaded archive...'); core.info('Extracting downloaded archive...');
if (IS_WINDOWS) { downloadDir = await tc.extractTar(graalpyPath);
downloadDir = await tc.extractZip(graalpyPath);
} else {
downloadDir = await tc.extractTar(graalpyPath);
}
// root folder in archive can have unpredictable name so just take the first folder // root folder in archive can have unpredictable name so just take the first folder
// downloadDir is unique folder under TEMP and can't contain any other folders // downloadDir is unique folder under TEMP and can't contain any other folders
@ -84,7 +81,7 @@ export async function installGraalPy(
); );
} }
const binaryPath = path.join(installDir, 'bin'); const binaryPath = getBinaryDirectory(installDir);
await createGraalPySymlink(binaryPath, resolvedGraalPyVersion); await createGraalPySymlink(binaryPath, resolvedGraalPyVersion);
await installPip(binaryPath); await installPip(binaryPath);
@ -118,9 +115,6 @@ export async function getAvailableGraalPyVersions() {
headers.authorization = AUTH; headers.authorization = AUTH;
} }
/*
Get releases first.
*/
let url: string | null = let url: string | null =
'https://api.github.com/repos/oracle/graalpython/releases'; 'https://api.github.com/repos/oracle/graalpython/releases';
const result: IGraalPyManifestRelease[] = []; const result: IGraalPyManifestRelease[] = [];
@ -136,23 +130,6 @@ export async function getAvailableGraalPyVersions() {
url = getNextPageUrl(response); url = getNextPageUrl(response);
} while (url); } while (url);
/*
Add pre-release builds.
*/
url =
'https://api.github.com/repos/graalvm/graal-languages-ea-builds/releases';
do {
const response: ifm.TypedResponse<IGraalPyManifestRelease[]> =
await http.getJson(url, headers);
if (!response.result) {
throw new Error(
`Unable to retrieve the list of available GraalPy versions from '${url}'`
);
}
result.push(...response.result);
url = getNextPageUrl(response);
} while (url);
return result; return result;
} }
@ -198,8 +175,7 @@ async function installPip(pythonLocation: string) {
} }
export function graalPyTagToVersion(tag: string) { export function graalPyTagToVersion(tag: string) {
const versionPattern = const versionPattern = /.*-(\d+\.\d+\.\d+(?:\.\d+)?)((?:a|b|rc))?(\d*)?/;
/.*-(\d+\.\d+\.\d+(?:\.\d+)?)(?:-((?:ea|a|b|rc))\.0*(\d+))?/;
const match = tag.match(versionPattern); const match = tag.match(versionPattern);
if (match && match[2]) { if (match && match[2]) {
return `${match[1]}-${match[2]}.${match[3]}`; return `${match[1]}-${match[2]}.${match[3]}`;
@ -275,11 +251,10 @@ export function findAsset(
) { ) {
const graalpyArch = toGraalPyArchitecture(architecture); const graalpyArch = toGraalPyArchitecture(architecture);
const graalpyPlatform = toGraalPyPlatform(platform); const graalpyPlatform = toGraalPyPlatform(platform);
const graalpyExt = platform == 'win32' ? 'zip' : 'tar.gz';
const found = item.assets.filter( const found = item.assets.filter(
file => file =>
file.name.startsWith('graalpy') && file.name.startsWith('graalpy') &&
file.name.endsWith(`-${graalpyPlatform}-${graalpyArch}.${graalpyExt}`) file.name.endsWith(`-${graalpyPlatform}-${graalpyArch}.tar.gz`)
); );
/* /*
In the future there could be more variants of GraalPy for a single release. Pick the shortest name, that one is the most likely to be the primary variant. In the future there could be more variants of GraalPy for a single release. Pick the shortest name, that one is the most likely to be the primary variant.

View file

@ -379,7 +379,7 @@ export function getVersionInputFromFile(versionFile: string): string[] {
} }
/** /**
* Get the directory containing interpreter binary from installation directory of PyPy * Get the directory containing interpreter binary from installation directory of PyPy or GraalPy
* - On Linux and macOS, the Python interpreter is in 'bin'. * - On Linux and macOS, the Python interpreter is in 'bin'.
* - On Windows, it is in the installation root. * - On Windows, it is in the installation root.
*/ */