mirror of
https://github.com/actions/setup-python.git
synced 2026-06-23 08:12:48 +00:00
Normalize RHEL OS detection and improve cache key consistency
This commit is contained in:
parent
9c2781a11e
commit
f1ee88690f
@ -190,19 +190,12 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
|||||||
|
|
||||||
restoredKeys.forEach(restoredKey => {
|
restoredKeys.forEach(restoredKey => {
|
||||||
if (restoredKey) {
|
if (restoredKey) {
|
||||||
if (process.platform === 'linux' && packageManager === 'pip') {
|
const osSegment =
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
process.platform === 'linux' ? '-20.04-Ubuntu' : '';
|
||||||
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}-20.04-Ubuntu-python-${pythonVersion}-${packageManager}-${fileHash}`
|
const versionSuffix = packageManager === 'poetry' ? '-v2' : '';
|
||||||
);
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
} else if (packageManager === 'poetry') {
|
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${pythonVersion}-${packageManager}${versionSuffix}-${fileHash}`
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
);
|
||||||
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}-python-${pythonVersion}-${packageManager}-v2-${fileHash}`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
|
||||||
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${process.arch}-python-${pythonVersion}-${packageManager}-${fileHash}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
|
|||||||
13
dist/cache-save/index.js
vendored
13
dist/cache-save/index.js
vendored
@ -51257,10 +51257,15 @@ class CacheDistributor {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
const osInfo = await (0, utils_1.getLinuxInfo)();
|
const osInfo = await (0, utils_1.getLinuxInfo)();
|
||||||
const osVersion = osInfo.osName === 'rhel'
|
// lsb_release reports RHEL as "RedHatEnterpriseLinux" while /etc/os-release
|
||||||
|
// reports it as "rhel"; normalize both to "rhel" so the key is consistent.
|
||||||
|
const normalizedName = osInfo.osName.toLowerCase();
|
||||||
|
const isRhel = normalizedName === 'rhel' || normalizedName.includes('redhat');
|
||||||
|
const osName = isRhel ? 'rhel' : osInfo.osName;
|
||||||
|
const osVersion = isRhel
|
||||||
? osInfo.osVersion.split('.')[0]
|
? osInfo.osVersion.split('.')[0]
|
||||||
: osInfo.osVersion;
|
: osInfo.osVersion;
|
||||||
return `-${osVersion}-${osInfo.osName}`;
|
return `-${osVersion}-${osName}`;
|
||||||
}
|
}
|
||||||
async restoreCache() {
|
async restoreCache() {
|
||||||
const { primaryKey, restoreKey } = await this.computeKeys();
|
const { primaryKey, restoreKey } = await this.computeKeys();
|
||||||
@ -51605,8 +51610,8 @@ async function getLinuxInfo() {
|
|||||||
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
|
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
|
||||||
return { osName, osVersion };
|
return { osName, osVersion };
|
||||||
}
|
}
|
||||||
catch {
|
catch (err) {
|
||||||
core.debug('lsb_release command not found. Falling back to /etc/os-release.');
|
core.debug(`lsb_release failed (${err.message}). Falling back to /etc/os-release.`);
|
||||||
const osReleaseContent = fs_1.default.readFileSync('/etc/os-release', 'utf8');
|
const osReleaseContent = fs_1.default.readFileSync('/etc/os-release', 'utf8');
|
||||||
const osInfo = {};
|
const osInfo = {};
|
||||||
osReleaseContent.split('\n').forEach(line => {
|
osReleaseContent.split('\n').forEach(line => {
|
||||||
|
|||||||
13
dist/setup/index.js
vendored
13
dist/setup/index.js
vendored
@ -53839,10 +53839,15 @@ class CacheDistributor {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
const osInfo = await (0, utils_1.getLinuxInfo)();
|
const osInfo = await (0, utils_1.getLinuxInfo)();
|
||||||
const osVersion = osInfo.osName === 'rhel'
|
// lsb_release reports RHEL as "RedHatEnterpriseLinux" while /etc/os-release
|
||||||
|
// reports it as "rhel"; normalize both to "rhel" so the key is consistent.
|
||||||
|
const normalizedName = osInfo.osName.toLowerCase();
|
||||||
|
const isRhel = normalizedName === 'rhel' || normalizedName.includes('redhat');
|
||||||
|
const osName = isRhel ? 'rhel' : osInfo.osName;
|
||||||
|
const osVersion = isRhel
|
||||||
? osInfo.osVersion.split('.')[0]
|
? osInfo.osVersion.split('.')[0]
|
||||||
: osInfo.osVersion;
|
: osInfo.osVersion;
|
||||||
return `-${osVersion}-${osInfo.osName}`;
|
return `-${osVersion}-${osName}`;
|
||||||
}
|
}
|
||||||
async restoreCache() {
|
async restoreCache() {
|
||||||
const { primaryKey, restoreKey } = await this.computeKeys();
|
const { primaryKey, restoreKey } = await this.computeKeys();
|
||||||
@ -55821,8 +55826,8 @@ async function getLinuxInfo() {
|
|||||||
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
|
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
|
||||||
return { osName, osVersion };
|
return { osName, osVersion };
|
||||||
}
|
}
|
||||||
catch {
|
catch (err) {
|
||||||
core.debug('lsb_release command not found. Falling back to /etc/os-release.');
|
core.debug(`lsb_release failed (${err.message}). Falling back to /etc/os-release.`);
|
||||||
const osReleaseContent = fs_1.default.readFileSync('/etc/os-release', 'utf8');
|
const osReleaseContent = fs_1.default.readFileSync('/etc/os-release', 'utf8');
|
||||||
const osInfo = {};
|
const osInfo = {};
|
||||||
osReleaseContent.split('\n').forEach(line => {
|
osReleaseContent.split('\n').forEach(line => {
|
||||||
|
|||||||
@ -33,12 +33,17 @@ abstract class CacheDistributor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const osInfo = await getLinuxInfo();
|
const osInfo = await getLinuxInfo();
|
||||||
const osVersion =
|
// lsb_release reports RHEL as "RedHatEnterpriseLinux" while /etc/os-release
|
||||||
osInfo.osName === 'rhel'
|
// reports it as "rhel"; normalize both to "rhel" so the key is consistent.
|
||||||
? osInfo.osVersion.split('.')[0]
|
const normalizedName = osInfo.osName.toLowerCase();
|
||||||
: osInfo.osVersion;
|
const isRhel =
|
||||||
|
normalizedName === 'rhel' || normalizedName.includes('redhat');
|
||||||
|
const osName = isRhel ? 'rhel' : osInfo.osName;
|
||||||
|
const osVersion = isRhel
|
||||||
|
? osInfo.osVersion.split('.')[0]
|
||||||
|
: osInfo.osVersion;
|
||||||
|
|
||||||
return `-${osVersion}-${osInfo.osName}`;
|
return `-${osVersion}-${osName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async restoreCache() {
|
public async restoreCache() {
|
||||||
|
|||||||
@ -185,9 +185,9 @@ export async function getLinuxInfo() {
|
|||||||
const [osName, osVersion] = stdout.trim().split('\n');
|
const [osName, osVersion] = stdout.trim().split('\n');
|
||||||
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
|
core.debug(`OS Name: ${osName}, Version: ${osVersion}`);
|
||||||
return {osName, osVersion};
|
return {osName, osVersion};
|
||||||
} catch {
|
} catch (err) {
|
||||||
core.debug(
|
core.debug(
|
||||||
'lsb_release command not found. Falling back to /etc/os-release.'
|
`lsb_release failed (${(err as Error).message}). Falling back to /etc/os-release.`
|
||||||
);
|
);
|
||||||
|
|
||||||
const osReleaseContent = fs.readFileSync('/etc/os-release', 'utf8');
|
const osReleaseContent = fs.readFileSync('/etc/os-release', 'utf8');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user