Skip to content

Commit

Permalink
Add warning for empty cache paths (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-shibanov authored Apr 6, 2023
1 parent d1244c8 commit 7a4f344
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions __tests__/cache-save.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('run', () => {
describe('Validate unchanged cache is not saved', () => {
it('should not save cache for pip', async () => {
inputs['cache'] = 'pip';
inputs['python-version'] = '3.10.0';

await run();

Expand All @@ -103,6 +104,7 @@ describe('run', () => {

it('should not save cache for pipenv', async () => {
inputs['cache'] = 'pipenv';
inputs['python-version'] = '3.10.0';

await run();

Expand All @@ -121,6 +123,7 @@ describe('run', () => {
describe('action saves the cache', () => {
it('saves cache from pip', async () => {
inputs['cache'] = 'pip';
inputs['python-version'] = '3.10.0';
getStateSpy.mockImplementation((name: string) => {
if (name === State.CACHE_MATCHED_KEY) {
return requirementsHash;
Expand All @@ -147,6 +150,7 @@ describe('run', () => {

it('saves cache from pipenv', async () => {
inputs['cache'] = 'pipenv';
inputs['python-version'] = '3.10.0';
getStateSpy.mockImplementation((name: string) => {
if (name === State.CACHE_MATCHED_KEY) {
return pipFileLockHash;
Expand All @@ -173,6 +177,7 @@ describe('run', () => {

it('saves cache from poetry', async () => {
inputs['cache'] = 'poetry';
inputs['python-version'] = '3.10.0';
getStateSpy.mockImplementation((name: string) => {
if (name === State.CACHE_MATCHED_KEY) {
return poetryLockHash;
Expand All @@ -199,6 +204,7 @@ describe('run', () => {

it('saves with -1 cacheId , should not fail workflow', async () => {
inputs['cache'] = 'poetry';
inputs['python-version'] = '3.10.0';
getStateSpy.mockImplementation((name: string) => {
if (name === State.STATE_CACHE_PRIMARY_KEY) {
return poetryLockHash;
Expand Down Expand Up @@ -227,6 +233,7 @@ describe('run', () => {

it('saves with error from toolkit, should not fail the workflow', async () => {
inputs['cache'] = 'npm';
inputs['python-version'] = '3.10.0';
getStateSpy.mockImplementation((name: string) => {
if (name === State.STATE_CACHE_PRIMARY_KEY) {
return poetryLockHash;
Expand Down
7 changes: 6 additions & 1 deletion dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59628,7 +59628,12 @@ function run() {
exports.run = run;
function saveCache(packageManager) {
return __awaiter(this, void 0, void 0, function* () {
const cachePaths = JSON.parse(core.getState(cache_distributor_1.State.CACHE_PATHS));
const cachePathState = core.getState(cache_distributor_1.State.CACHE_PATHS);
if (!cachePathState) {
core.warning('Cache paths are empty. Please check the previous logs and make sure that the python version is specified');
return;
}
const cachePaths = JSON.parse(cachePathState);
core.debug(`paths for caching are ${cachePaths.join(', ')}`);
if (!isCacheDirectoryExists(cachePaths)) {
throw new Error(`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePaths.join(', ')}`);
Expand Down
11 changes: 10 additions & 1 deletion src/cache-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ export async function run() {
}

async function saveCache(packageManager: string) {
const cachePaths = JSON.parse(core.getState(State.CACHE_PATHS)) as string[];
const cachePathState = core.getState(State.CACHE_PATHS);

if (!cachePathState) {
core.warning(
'Cache paths are empty. Please check the previous logs and make sure that the python version is specified'
);
return;
}

const cachePaths = JSON.parse(cachePathState) as string[];

core.debug(`paths for caching are ${cachePaths.join(', ')}`);

Expand Down

0 comments on commit 7a4f344

Please sign in to comment.