mirror of
https://github.com/actions/setup-python.git
synced 2026-01-20 04:38:56 +08:00
add unit and e2e tests
This commit is contained in:
parent
c98dcdec10
commit
b321c7b928
14 changed files with 825 additions and 42 deletions
|
|
@ -9,7 +9,7 @@ export enum State {
|
|||
|
||||
abstract class CacheDistributor {
|
||||
protected CACHE_KEY_PREFIX = 'setup-python';
|
||||
constructor(protected toolName: string, protected cacheDependencyPath: string) {}
|
||||
constructor(protected packageManager: string, protected cacheDependencyPath: string) {}
|
||||
|
||||
protected abstract getCacheGlobalDirectories(): Promise<string[]>;
|
||||
protected abstract computeKeys(): Promise<{
|
||||
|
|
@ -42,7 +42,7 @@ abstract class CacheDistributor {
|
|||
core.saveState(State.CACHE_MATCHED_KEY, matchedKey);
|
||||
core.info(`Cache restored from key: ${matchedKey}`);
|
||||
} else {
|
||||
core.info(`${this.toolName} cache is not found`);
|
||||
core.info(`${this.packageManager} cache is not found`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class PipCache extends CacheDistributor {
|
|||
'pip cache dir'
|
||||
);
|
||||
|
||||
if (stderr) {
|
||||
if (exitCode && stderr) {
|
||||
throw new Error(
|
||||
`Could not get cache folder path for pip package manager`
|
||||
);
|
||||
|
|
@ -29,15 +29,15 @@ class PipCache extends CacheDistributor {
|
|||
resolvedPath = path.join(os.homedir(), resolvedPath.slice(1));
|
||||
}
|
||||
|
||||
core.info(`global cache directory path is ${resolvedPath}`);
|
||||
core.debug(`global cache directory path is ${resolvedPath}`);
|
||||
|
||||
return [resolvedPath];
|
||||
}
|
||||
|
||||
protected async computeKeys() {
|
||||
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.toolName}-${hash}`;
|
||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.toolName}`;
|
||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
|
||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
|
||||
|
||||
return {
|
||||
primaryKey,
|
||||
|
|
|
|||
|
|
@ -8,21 +8,19 @@ import CacheDistributor from './cache-distributor';
|
|||
class PipenvCache extends CacheDistributor {
|
||||
constructor(
|
||||
private pythonVersion: string,
|
||||
protected patterns: string = 'Pipfile.lock'
|
||||
protected patterns: string = '**/Pipfile.lock'
|
||||
) {
|
||||
super('pipenv', patterns);
|
||||
}
|
||||
|
||||
private getVirtualenvsPath() {
|
||||
if (process.platform === 'win32') {
|
||||
return '.virtualenvs';
|
||||
} else {
|
||||
return '.local/share/virtualenvs';
|
||||
}
|
||||
}
|
||||
|
||||
protected async getCacheGlobalDirectories() {
|
||||
const resolvedPath = path.join(os.homedir(), this.getVirtualenvsPath());
|
||||
let virtualEnvRelativePath;
|
||||
if (process.platform === 'win32') {
|
||||
virtualEnvRelativePath = '.virtualenvs';
|
||||
} else {
|
||||
virtualEnvRelativePath = '.local/share/virtualenvs';
|
||||
}
|
||||
const resolvedPath = path.join(os.homedir(), virtualEnvRelativePath);
|
||||
core.debug(`global cache directory path is ${resolvedPath}`);
|
||||
|
||||
return [resolvedPath];
|
||||
|
|
@ -30,7 +28,7 @@ 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.toolName}-${hash}`;
|
||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||
const restoreKey = undefined;
|
||||
return {
|
||||
primaryKey,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import * as cache from '@actions/cache';
|
|||
import fs from 'fs';
|
||||
import {State} from './cache-distributions/cache-distributor';
|
||||
|
||||
async function run() {
|
||||
export async function run() {
|
||||
try {
|
||||
const cache = core.getInput('cache');
|
||||
if (cache) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
import fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue