Add linux os release info to primary key

This commit is contained in:
panticmilos 2022-07-18 17:16:35 +02:00
parent c474c82340
commit f22ce50675
6 changed files with 137 additions and 18 deletions

View file

@ -7,7 +7,7 @@ import * as path from 'path';
import os from 'os';
import CacheDistributor from './cache-distributor';
import {IS_WINDOWS} from '../utils';
import {getLinuxOSReleaseInfo, IS_LINUX, IS_WINDOWS} from '../utils';
class PipCache extends CacheDistributor {
constructor(
@ -57,8 +57,19 @@ class PipCache extends CacheDistributor {
protected async computeKeys() {
const hash = await glob.hashFiles(this.cacheDependencyPath);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
let primaryKey = '';
let restoreKey = '';
if (IS_LINUX) {
console.log('here');
const osRelease = await getLinuxOSReleaseInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`;
} else {
console.log('here2');
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
}
return {
primaryKey,

View file

@ -2,6 +2,7 @@ import * as glob from '@actions/glob';
import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils';
import CacheDistributor from './cache-distributor';
@ -31,9 +32,17 @@ class PipenvCache extends CacheDistributor {
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const hash = await glob.hashFiles(this.cacheDependencyPath);
let primaryKey = '';
const restoreKey = undefined;
if (IS_LINUX) {
const osRelease = await getLinuxOSReleaseInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
} else {
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
}
return {
primaryKey,
restoreKey

View file

@ -1,7 +1,7 @@
import * as glob from '@actions/glob';
import * as os from 'os';
import * as path from 'path';
import * as exec from '@actions/exec';
import {getLinuxOSReleaseInfo, IS_LINUX} from '../utils';
import CacheDistributor from './cache-distributor';
@ -32,9 +32,17 @@ class PoetryCache extends CacheDistributor {
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const hash = await glob.hashFiles(this.cacheDependencyPath);
let primaryKey = '';
const restoreKey = undefined;
if (IS_LINUX) {
const osRelease = await getLinuxOSReleaseInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
} else {
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
}
return {
primaryKey,
restoreKey

View file

@ -3,6 +3,7 @@ import * as core from '@actions/core';
import fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
import * as exec from '@actions/exec';
export const IS_WINDOWS = process.platform === 'win32';
export const IS_LINUX = process.platform === 'linux';
@ -119,3 +120,20 @@ export function isCacheFeatureAvailable(): boolean {
return true;
}
export async function getLinuxOSReleaseInfo() {
const versionId = await exec.getExecOutput('lsb_release', ['-a'], {
silent: true
});
let osVersion = '';
let osRelease = '';
versionId.stdout.split('\n').forEach(elem => {
if (elem.includes('Distributor')) osVersion = elem.split(':')[1].trim();
if (elem.includes('Release')) osRelease = elem.split(':')[1].trim();
});
core.info(osRelease);
core.info(osVersion);
return `${osVersion}-${osRelease}`;
}