Skip to content

Commit

Permalink
Move existence check to cache-save
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Jul 14, 2021
1 parent d278e78 commit 399982b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/cache-save.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as cache from '@actions/cache';
import fs from 'fs';
import {State} from './constants';
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';

Expand All @@ -26,6 +27,13 @@ const cachePackages = async (packageManager: string) => {
packageManagerInfo,
packageManager
);

if (!fs.existsSync(cachePath)) {
throw new Error(
`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePath}`
);
}

if (primaryKey === state) {
core.info(
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
Expand Down
7 changes: 0 additions & 7 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import fs from 'fs';
import os from 'os';
import path from 'path';

Expand Down Expand Up @@ -98,11 +97,5 @@ export const getCacheDirectoryPath = async (

core.debug(`${packageManager} path is ${stdOut}`);

if (!fs.existsSync(stdOut)) {
throw new Error(
`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${stdOut}`
);
}

return stdOut;
};

0 comments on commit 399982b

Please sign in to comment.