8000 Merge pull request #122 from nix-community/118-bug-cant-save-a-cache · nix-community/cache-nix-action@135667e · GitHub
[go: up one dir, main page]

Skip to content

Commit 135667e

Browse files
authored
Merge pull request #122 from nix-community/118-bug-cant-save-a-cache
Fix saving a cache
2 parents f68581e + e29de90 commit 135667e

File tree

8 files changed

+801
-263
lines changed

8 files changed

+801
-263
lines changed

dist/restore-only/index.js

Lines changed: 192 additions & 60 deletions
Large diffs are not rendered by default.

dist/restore/index.js

Lines changed: 192 additions & 60 deletions
Large diffs are not rendered by default.

dist/save-only/index.js

Lines changed: 200 additions & 65 deletions
Large diffs are not rendered by default.

dist/save/index.js

Lines changed: 200 additions & 65 deletions
Large diffs are not rendered by default.

src/saveImpl.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as utils from "./utils/action";
1212
import { cache } from "./utils/cacheBackend";
1313
import { collectGarbage } from "./utils/collectGarbage";
1414
import { purgeCacheByKey, purgeCaches } from "./utils/purge";
15+
import { TarCommandModifiers } from "actions/toolkit/packages/cache/src/options";
1516

1617
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
1718
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
@@ -84,11 +85,11 @@ export async function saveImpl(
8485
Not saving a new cache.
8586
`
8687
);
87-
88+
8889
// Since we don't save a cache
89-
// it's probably safe to set the value
90-
// to something other than -1
91-
// so that the warning
90+
// it's probably safe to set the value
91+
// to something other than -1
92+
// so that the warning
9293
// in the try block in saveOnlyRun
9394
// is not printed
9495
cacheId = 0;
@@ -99,7 +100,10 @@ export async function saveImpl(
99100

100101
utils.info(`Saving a new cache with the key "${primaryKey}".`);
101102

102-
const extraTarArgs = await utils.prepareExcludeFromFile(false);
103+
let tarCommandModifiers = new TarCommandModifiers();
104+
105+
tarCommandModifiers.createArgs =
106+
await utils.prepareExcludeFromFile(false);
103107

104108
// can throw
105109
cacheId = await cache.saveCache(
@@ -109,7 +113,7 @@ export async function saveImpl(
109113
uploadChunkSize: inputs.uploadChunkSize
110114
},
111115
undefined,
112-
extraTarArgs
116+
tarCommandModifiers
113117
);
114118

115119
utils.info(

src/utils/action.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { devNull } from "os";
88
import { Inputs, RefKey } from "../constants";
99
import * as inputs from "../inputs";
1010
import { cache, cacheUtils } from "./cacheBackend";
11+
import { TarCommandModifiers } from "actions/toolkit/packages/cache/src/options";
1112

1213
const myDedent = dedent.withOptions({});
1314

@@ -99,8 +100,7 @@ export async function prepareExcludeFromFile(forRestore: boolean) {
99100
const tmp = await cacheUtils.createTempDirectory();
100101
const excludeFromFile = `${tmp}/paths`;
101102
fs.writeFileSync(excludeFromFile, excludePaths.join("\n"));
102-
const extraTarArgs = ["--exclude-from", excludeFromFile];
103-
return extraTarArgs;
103+
return ["--exclude-from", excludeFromFile];
104104
}
105105

106106
export async function restoreCache({
@@ -112,10 +112,10 @@ export async function restoreCache({
112112
restoreKeys: string[];
113113
lookupOnly: boolean;
114114
}) {
115-
let extraTarArgs: string[] = [];
115+
let tarCommandModifiers = new TarCommandModifiers();
116116

117117
if (< 1E0A span class=pl-s1>inputs.nix && !lookupOnly) {
118-
extraTarArgs = await prepareExcludeFromFile(true);
118+
tarCommandModifiers.extractArgs = await prepareExcludeFromFile(true);
119119

120120
info(`::group::Logs produced while restoring a cache.`);
121121
}
@@ -128,7 +128,7 @@ export async function restoreCache({
128128
restoreKeys,
129129
{ lookupOnly },
130130
false,
131-
extraTarArgs
131+
tarCommandModifiers
132132
);
133133

134134
if (inputs.nix && !lookupOnly) {

0 commit comments

Comments
 (0)
0