Compare commits

...

5 Commits

Author SHA1 Message Date
Kryštof Korb 2a5d944c67
Merge 04e00cd600 into 9c76e71650 2024-10-22 13:55:08 +05:45
aparnajyothi-y 9c76e71650
Bump pillow from 7.2 to 10.2.0 in /__tests__/data (#956)
* Update e2e-cache.yml

* Update basic-validation.yml

* Pyinstaller upgrade to 5.13.1

* pyinstaller-update

* Update basic-validation.yml

* Update e2e-cache.yml

* fix-db-alert-164-165-166

* upgrade pillow
2024-10-21 15:39:11 -05:00
John Wesley Walker III f4c5a1183d
Revise `isGhes` logic (#963)
* Revise `isGhes` logic

* ran `npm run format`

* add unit test

* ran `npm run format`
2024-10-21 11:42:17 -05:00
Kryštof Korb 04e00cd600 Fix typos 2024-01-04 00:45:19 +01:00
Kryštof Korb bd1ce022fe Enhance reading from .python-version 2024-01-04 00:33:23 +01:00
5 changed files with 101 additions and 15 deletions

View File

@ -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

View File

@ -10,9 +10,10 @@ import {
validatePythonVersionFormatForPyPy,
isCacheFeatureAvailable,
getVersionInputFromFile,
getVersionInputFromPlainFile,
getVersionsInputFromPlainFile,
getVersionInputFromTomlFile,
getNextPageUrl,
isGhes,
IS_WINDOWS,
getDownloadFileName
} from '../src/utils';
@ -93,7 +94,7 @@ const tempDir = path.join(
);
describe('Version from file test', () => {
it.each([getVersionInputFromPlainFile, getVersionInputFromFile])(
it.each([getVersionsInputFromPlainFile, getVersionInputFromFile])(
'Version from plain file test',
async _fn => {
await io.mkdirP(tempDir);
@ -104,6 +105,28 @@ describe('Version from file test', () => {
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersionFileContent]);
}
);
it.each([getVersionsInputFromPlainFile, getVersionInputFromFile])(
'Versions from multiline plain file test',
async _fn => {
await io.mkdirP(tempDir);
const pythonVersionFileName = 'python-version.file';
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
const pythonVersionFileContent = '3.8\r\n3.7';
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
expect(_fn(pythonVersionFilePath)).toEqual(['3.8', '3.7']);
}
);
it.each([getVersionsInputFromPlainFile, getVersionInputFromFile])(
'Version from complex plain file test',
async _fn => {
await io.mkdirP(tempDir);
const pythonVersionFileName = 'python-version.file';
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
const pythonVersionFileContent = '3.10/envs/virtualenv\r# 3.9\n3.8\r\n3.7\r\n 3.6 \r\n';
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
expect(_fn(pythonVersionFilePath)).toEqual(['3.10', '3.8', '3.7', '3.6']);
}
);
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
'Version from standard pyproject.toml test',
async _fn => {
@ -195,3 +218,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();
});
});

6
dist/setup/index.js vendored
View File

@ -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() {

View File

@ -11,7 +11,7 @@ import {
logWarning,
IS_MAC,
getVersionInputFromFile,
getVersionInputFromPlainFile
getVersionsInputFromPlainFile
} from './utils';
function isPyPyVersion(versionSpec: string) {
@ -35,7 +35,7 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
function resolveVersionInputFromDefaultFile(): string[] {
const couples: [string, (versionFile: string) => string[]][] = [
['.python-version', getVersionInputFromPlainFile]
['.python-version', getVersionsInputFromPlainFile]
];
for (const [versionFile, _fn] of couples) {
logWarning(

View File

@ -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 {
@ -222,7 +228,7 @@ function extractValue(obj: any, keys: string[]): string | undefined {
* If none is present, returns an empty list.
*/
export function getVersionInputFromTomlFile(versionFile: string): string[] {
core.debug(`Trying to resolve version form ${versionFile}`);
core.debug(`Trying to resolve version from ${versionFile}`);
let pyprojectFile = fs.readFileSync(versionFile, 'utf8');
// Normalize the line endings in the pyprojectFile
@ -263,13 +269,28 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
}
/**
* Python version extracted from a plain text file.
* Python versions extracted from a plain text file.
* - Resolves multiple versions from multiple lines.
* - Handles pyenv-virtualenv pointers (e.g. `3.10/envs/virtualenv`).
* - Ignores empty lines and lines starting with `#`
* - Trims whitespace.
*/
export function getVersionInputFromPlainFile(versionFile: string): string[] {
core.debug(`Trying to resolve version form ${versionFile}`);
const version = fs.readFileSync(versionFile, 'utf8').trim();
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
export function getVersionsInputFromPlainFile(versionFile: string): string[] {
core.debug(`Trying to resolve versions from ${versionFile}`);
const content = fs.readFileSync(versionFile, 'utf8').trim();
const lines = content.split(/\r\n|\r|\n/);
const versions = lines
.map(line => {
if (line.startsWith('#') || line.trim() === '') {
return undefined;
}
let version: string = line.trim();
version = version.split('/')[0];
return version;
})
.filter(version => version !== undefined) as string[];
core.info(`Resolved ${versionFile} as ${versions.join(', ')}`);
return versions;
}
/**
@ -279,7 +300,7 @@ export function getVersionInputFromFile(versionFile: string): string[] {
if (versionFile.endsWith('.toml')) {
return getVersionInputFromTomlFile(versionFile);
} else {
return getVersionInputFromPlainFile(versionFile);
return getVersionsInputFromPlainFile(versionFile);
}
}