mirror of https://github.com/actions/setup-python
Compare commits
4 Commits
e979013902
...
9b0321d058
Author | SHA1 | Date |
---|---|---|
Daniel Bowring | 9b0321d058 | |
aparnajyothi-y | 9c76e71650 | |
John Wesley Walker III | f4c5a1183d | |
Daniel Bowring | 9e32ee01fa |
|
@ -30,7 +30,7 @@ pdf2image==1.12.1
|
|||
|
||||
pefile==2021.9.3; python_full_version >= '3.6.0'
|
||||
|
||||
pillow==7.2
|
||||
pillow>=10.2.0
|
||||
|
||||
pygments==2.6.1
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
getVersionInputFromPlainFile,
|
||||
getVersionInputFromTomlFile,
|
||||
getNextPageUrl,
|
||||
isGhes,
|
||||
IS_WINDOWS,
|
||||
getDownloadFileName
|
||||
} from '../src/utils';
|
||||
|
@ -128,6 +129,30 @@ describe('Version from file test', () => {
|
|||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
||||
}
|
||||
);
|
||||
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
|
||||
'Version from mise .mise.toml test',
|
||||
async _fn => {
|
||||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = '.mise.toml';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersion = '3.7.0';
|
||||
const pythonVersionFileContent = `[tools]\npython = "${pythonVersion}"`;
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
||||
}
|
||||
);
|
||||
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
|
||||
'Version from mise verbose .mise.toml test',
|
||||
async _fn => {
|
||||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = '.mise.toml';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersion = '3.7.0';
|
||||
const pythonVersionFileContent = `[tools]\npython = { version="${pythonVersion}", virtualenv=".venv" }`;
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
||||
}
|
||||
);
|
||||
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
|
||||
'Version undefined',
|
||||
async _fn => {
|
||||
|
@ -195,3 +220,41 @@ describe('getDownloadFileName', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('isGhes', () => {
|
||||
const pristineEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
process.env = {...pristineEnv};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env = pristineEnv;
|
||||
});
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => {
|
||||
delete process.env['GITHUB_SERVER_URL'];
|
||||
expect(isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
||||
expect(isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com';
|
||||
expect(isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost';
|
||||
expect(isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com';
|
||||
expect(isGhes()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -92017,7 +92017,11 @@ function validatePythonVersionFormatForPyPy(version) {
|
|||
exports.validatePythonVersionFormatForPyPy = validatePythonVersionFormatForPyPy;
|
||||
function isGhes() {
|
||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||
const isGitHubHost = hostname === 'GITHUB.COM';
|
||||
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST');
|
||||
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
|
||||
}
|
||||
exports.isGhes = isGhes;
|
||||
function isCacheFeatureAvailable() {
|
||||
|
@ -92090,6 +92094,9 @@ function getOSInfo() {
|
|||
});
|
||||
}
|
||||
exports.getOSInfo = getOSInfo;
|
||||
function isString(value) {
|
||||
return typeof value === 'string' || value instanceof String;
|
||||
}
|
||||
/**
|
||||
* Extract a value from an object by following the keys path provided.
|
||||
* If the value is present, it is returned. Otherwise undefined is returned.
|
||||
|
@ -92100,9 +92107,12 @@ function extractValue(obj, keys) {
|
|||
if (keys.length > 1 && value !== undefined) {
|
||||
return extractValue(value, keys.slice(1));
|
||||
}
|
||||
else {
|
||||
else if (isString(value)) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
|
@ -92122,19 +92132,26 @@ function getVersionInputFromTomlFile(versionFile) {
|
|||
// Normalize the line endings in the pyprojectFile
|
||||
pyprojectFile = pyprojectFile.replace(/\r\n/g, '\n');
|
||||
const pyprojectConfig = toml.parse(pyprojectFile);
|
||||
let keys = [];
|
||||
let keyPaths = [];
|
||||
if ('project' in pyprojectConfig) {
|
||||
// standard project metadata (PEP 621)
|
||||
keys = ['project', 'requires-python'];
|
||||
keyPaths = [['project', 'requires-python']];
|
||||
}
|
||||
else {
|
||||
keyPaths = [
|
||||
// python poetry
|
||||
keys = ['tool', 'poetry', 'dependencies', 'python'];
|
||||
['tool', 'poetry', 'dependencies', 'python'],
|
||||
// mise
|
||||
['tools', 'python'],
|
||||
['tools', 'python', 'version']
|
||||
];
|
||||
}
|
||||
const versions = [];
|
||||
const version = extractValue(pyprojectConfig, keys);
|
||||
if (version !== undefined) {
|
||||
versions.push(version);
|
||||
for (const keys of keyPaths) {
|
||||
const value = extractValue(pyprojectConfig, keys);
|
||||
if (value !== undefined) {
|
||||
versions.push(value);
|
||||
}
|
||||
}
|
||||
core.info(`Extracted ${versions} from ${versionFile}`);
|
||||
const rawVersions = Array.from(versions, version => version.split(',').join(' '));
|
||||
|
|
38
src/utils.ts
38
src/utils.ts
|
@ -116,7 +116,13 @@ export function isGhes(): boolean {
|
|||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||
const isGitHubHost = hostname === 'GITHUB.COM';
|
||||
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST');
|
||||
|
||||
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
|
||||
}
|
||||
|
||||
export function isCacheFeatureAvailable(): boolean {
|
||||
|
@ -196,6 +202,10 @@ export async function getOSInfo() {
|
|||
}
|
||||
}
|
||||
|
||||
function isString(value: unknown): value is string {
|
||||
return typeof value === 'string' || value instanceof String;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a value from an object by following the keys path provided.
|
||||
* If the value is present, it is returned. Otherwise undefined is returned.
|
||||
|
@ -205,8 +215,10 @@ function extractValue(obj: any, keys: string[]): string | undefined {
|
|||
const value = obj[keys[0]];
|
||||
if (keys.length > 1 && value !== undefined) {
|
||||
return extractValue(value, keys.slice(1));
|
||||
} else {
|
||||
} else if (isString(value)) {
|
||||
return value;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
|
@ -229,19 +241,29 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
|
|||
pyprojectFile = pyprojectFile.replace(/\r\n/g, '\n');
|
||||
|
||||
const pyprojectConfig = toml.parse(pyprojectFile);
|
||||
let keys = [];
|
||||
|
||||
let keyPaths = [];
|
||||
|
||||
if ('project' in pyprojectConfig) {
|
||||
// standard project metadata (PEP 621)
|
||||
keys = ['project', 'requires-python'];
|
||||
keyPaths = [['project', 'requires-python']];
|
||||
} else {
|
||||
keyPaths = [
|
||||
// python poetry
|
||||
keys = ['tool', 'poetry', 'dependencies', 'python'];
|
||||
['tool', 'poetry', 'dependencies', 'python'],
|
||||
// mise
|
||||
['tools', 'python'],
|
||||
['tools', 'python', 'version']
|
||||
];
|
||||
}
|
||||
|
||||
const versions = [];
|
||||
const version = extractValue(pyprojectConfig, keys);
|
||||
if (version !== undefined) {
|
||||
versions.push(version);
|
||||
|
||||
for (const keys of keyPaths) {
|
||||
const value = extractValue(pyprojectConfig, keys);
|
||||
if (value !== undefined) {
|
||||
versions.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
core.info(`Extracted ${versions} from ${versionFile}`);
|
||||
|
|
Loading…
Reference in New Issue