Skip to content

Commit 7a4f344

Browse files
Add warning for empty cache paths (#642)
1 parent d1244c8 commit 7a4f344

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

__tests__/cache-save.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe('run', () => {
8787
describe('Validate unchanged cache is not saved', () => {
8888
it('should not save cache for pip', async () => {
8989
inputs['cache'] = 'pip';
90+
inputs['python-version'] = '3.10.0';
9091

9192
await run();
9293

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

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

107109
await run();
108110

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

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

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

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

228234
it('saves with error from toolkit, should not fail the workflow', async () => {
229235
inputs['cache'] = 'npm';
236+
inputs['python-version'] = '3.10.0';
230237
getStateSpy.mockImplementation((name: string) => {
231238
if (name === State.STATE_CACHE_PRIMARY_KEY) {
232239
return poetryLockHash;

dist/cache-save/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -59628,7 +59628,12 @@ function run() {
5962859628
exports.run = run;
5962959629
function saveCache(packageManager) {
5963059630
return __awaiter(this, void 0, void 0, function* () {
59631-
const cachePaths = JSON.parse(core.getState(cache_distributor_1.State.CACHE_PATHS));
59631+
const cachePathState = core.getState(cache_distributor_1.State.CACHE_PATHS);
59632+
if (!cachePathState) {
59633+
core.warning('Cache paths are empty. Please check the previous logs and make sure that the python version is specified');
59634+
return;
59635+
}
59636+
const cachePaths = JSON.parse(cachePathState);
5963259637
core.debug(`paths for caching are ${cachePaths.join(', ')}`);
5963359638
if (!isCacheDirectoryExists(cachePaths)) {
5963459639
throw new Error(`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePaths.join(', ')}`);

src/cache-save.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ export async function run() {
1717
}
1818

1919
async function saveCache(packageManager: string) {
20-
const cachePaths = JSON.parse(core.getState(State.CACHE_PATHS)) as string[];
20+
const cachePathState = core.getState(State.CACHE_PATHS);
21+
22+
if (!cachePathState) {
23+
core.warning(
24+
'Cache paths are empty. Please check the previous logs and make sure that the python version is specified'
25+
);
26+
return;
27+
}
28+
29+
const cachePaths = JSON.parse(cachePathState) as string[];
2130

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

0 commit comments

Comments
 (0)