Skip to content

Commit 796531a

Browse files
Merge pull request #1080 from akv-platform/fix-delete-cache
Fix delete cache
2 parents 184e7af + 8986f62 commit 796531a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ You can find more information about the required permissions under the correspon
2929
## Statefulness
3030
3131
If the action ends because of [operations-per-run](#operations-per-run) then the next run will start from the first
32-
unprocessed issue skipping the issues proceeded during the previous run(s). The state is reset when all the issues are
33-
proceeded. This should be considered for scheduling workflow runs.
32+
unprocessed issue skipping the issues processed during the previous run(s). The state is reset when all the issues are
33+
processed. This should be considered for scheduling workflow runs.
3434
3535
The saved state lifetime is the same as the
3636
[actions cache](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy)

dist/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu
16361636
}
16371637
catch (error) {
16381638
if (error.status) {
1639-
core.debug(`Cache ${cacheKey} does not exist`);
1639+
core.warning(`Error delete ${cacheKey}: [${error.status}] ${error.message || 'Unknown reason'}`);
16401640
}
16411641
else {
16421642
throw error;
@@ -1650,7 +1650,10 @@ class StateCacheStorage {
16501650
const filePath = path_1.default.join(tmpDir, STATE_FILE);
16511651
fs_1.default.writeFileSync(filePath, serializedState);
16521652
try {
1653-
yield resetCacheWithOctokit(CACHE_KEY);
1653+
const cacheExists = yield checkIfCacheExists(CACHE_KEY);
1654+
if (cacheExists) {
1655+
yield resetCacheWithOctokit(CACHE_KEY);
1656+
}
16541657
const fileSize = fs_1.default.statSync(filePath).size;
16551658
if (fileSize === 0) {
16561659
core.info(`the state will be removed`);

src/classes/state/state-cache-storage.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ const resetCacheWithOctokit = async (cacheKey: string): Promise<void> => {
5454
);
5555
} catch (error) {
5656
if (error.status) {
57-
core.debug(`Cache ${cacheKey} does not exist`);
57+
core.warning(
58+
`Error delete ${cacheKey}: [${error.status}] ${
59+
error.message || 'Unknown reason'
60+
}`
61+
);
5862
} else {
5963
throw error;
6064
}
@@ -67,7 +71,10 @@ export class StateCacheStorage implements IStateStorage {
6771
fs.writeFileSync(filePath, serializedState);
6872

6973
try {
70-
await resetCacheWithOctokit(CACHE_KEY);
74+
const cacheExists = await checkIfCacheExists(CACHE_KEY);
75+
if (cacheExists) {
76+
await resetCacheWithOctokit(CACHE_KEY);
77+
}
7178
const fileSize = fs.statSync(filePath).size;
7279

7380
if (fileSize === 0) {

0 commit comments

Comments
 (0)