mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-29 14:59:55 +02:00
Include keys in getCacheEntry request
This commit is contained in:
parent
bd756c16ae
commit
072d513f28
6 changed files with 19 additions and 37 deletions
|
@ -1,34 +1,18 @@
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
import * as testUtils from "../src/utils/testUtils";
|
||||||
import { getCacheVersion } from "../src/cacheHttpClient";
|
import { getCacheVersion } from "../src/cacheHttpClient";
|
||||||
|
import { Inputs } from "../src/constants";
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
testUtils.clearInputs();
|
testUtils.clearInputs();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getCacheVersion with no restore keys returns version", async () => {
|
test("getCacheVersion with path input returns version", async () => {
|
||||||
testUtils.setInputs({
|
testUtils.setInput(Inputs.Path, "node_modules");
|
||||||
path: "node-test",
|
|
||||||
key: "node_modules"
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = getCacheVersion();
|
const result = getCacheVersion();
|
||||||
|
|
||||||
expect(result).toEqual(
|
expect(result).toEqual(
|
||||||
"ee9d5dc2e8e2df8e32f62c367796abefc134790584015d8e1207523c9085e87e"
|
"b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985"
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getCacheVersion with restore keys returns version", async () => {
|
|
||||||
testUtils.setInputs({
|
|
||||||
path: "node-test",
|
|
||||||
key: "node_modules",
|
|
||||||
restoreKeys: ["node-", "node"]
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = getCacheVersion();
|
|
||||||
|
|
||||||
expect(result).toEqual(
|
|
||||||
"b8596b1e42c34a25be7b43c7b91892ed3ba81cba1e075365f408b35dbfabb61b"
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ test("restore with cache found", async () => {
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(getCacheMock).toHaveBeenCalledWith();
|
expect(getCacheMock).toHaveBeenCalledWith([key]);
|
||||||
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
expect(downloadCacheMock).toHaveBeenCalledWith(
|
||||||
|
@ -307,7 +307,7 @@ test("restore with a pull request event and cache found", async () => {
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(getCacheMock).toHaveBeenCalledWith();
|
expect(getCacheMock).toHaveBeenCalledWith([key]);
|
||||||
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
expect(downloadCacheMock).toHaveBeenCalledWith(
|
||||||
|
@ -374,7 +374,7 @@ test("restore with cache found for restore key", async () => {
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(getCacheMock).toHaveBeenCalledWith();
|
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey]);
|
||||||
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
expect(setCacheStateMock).toHaveBeenCalledWith(cacheEntry);
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1);
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
expect(downloadCacheMock).toHaveBeenCalledWith(
|
||||||
|
|
8
dist/restore/index.js
vendored
8
dist/restore/index.js
vendored
|
@ -2237,8 +2237,6 @@ function createHttpClient() {
|
||||||
function getCacheVersion() {
|
function getCacheVersion() {
|
||||||
// Add salt to cache version to support breaking changes in cache entry
|
// Add salt to cache version to support breaking changes in cache entry
|
||||||
const components = [
|
const components = [
|
||||||
core.getInput(constants_1.Inputs.Key, { required: true }),
|
|
||||||
core.getInput(constants_1.Inputs.RestoreKeys, { required: false }),
|
|
||||||
core.getInput(constants_1.Inputs.Path, { required: true }),
|
core.getInput(constants_1.Inputs.Path, { required: true }),
|
||||||
versionSalt
|
versionSalt
|
||||||
];
|
];
|
||||||
|
@ -2248,12 +2246,12 @@ function getCacheVersion() {
|
||||||
.digest("hex");
|
.digest("hex");
|
||||||
}
|
}
|
||||||
exports.getCacheVersion = getCacheVersion;
|
exports.getCacheVersion = getCacheVersion;
|
||||||
function getCacheEntry() {
|
function getCacheEntry(keys) {
|
||||||
var _a;
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const httpClient = createHttpClient();
|
const httpClient = createHttpClient();
|
||||||
const version = getCacheVersion();
|
const version = getCacheVersion();
|
||||||
const resource = `cache?version=${version}`;
|
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
||||||
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -4588,7 +4586,7 @@ function run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const cacheEntry = yield cacheHttpClient.getCacheEntry();
|
const cacheEntry = yield cacheHttpClient.getCacheEntry(keys);
|
||||||
if (!((_a = cacheEntry) === null || _a === void 0 ? void 0 : _a.archiveLocation)) {
|
if (!((_a = cacheEntry) === null || _a === void 0 ? void 0 : _a.archiveLocation)) {
|
||||||
core.info(`Cache not found for input keys: ${keys.join(", ")}`);
|
core.info(`Cache not found for input keys: ${keys.join(", ")}`);
|
||||||
return;
|
return;
|
||||||
|
|
6
dist/save/index.js
vendored
6
dist/save/index.js
vendored
|
@ -2237,8 +2237,6 @@ function createHttpClient() {
|
||||||
function getCacheVersion() {
|
function getCacheVersion() {
|
||||||
// Add salt to cache version to support breaking changes in cache entry
|
// Add salt to cache version to support breaking changes in cache entry
|
||||||
const components = [
|
const components = [
|
||||||
core.getInput(constants_1.Inputs.Key, { required: true }),
|
|
||||||
core.getInput(constants_1.Inputs.RestoreKeys, { required: false }),
|
|
||||||
core.getInput(constants_1.Inputs.Path, { required: true }),
|
core.getInput(constants_1.Inputs.Path, { required: true }),
|
||||||
versionSalt
|
versionSalt
|
||||||
];
|
];
|
||||||
|
@ -2248,12 +2246,12 @@ function getCacheVersion() {
|
||||||
.digest("hex");
|
.digest("hex");
|
||||||
}
|
}
|
||||||
exports.getCacheVersion = getCacheVersion;
|
exports.getCacheVersion = getCacheVersion;
|
||||||
function getCacheEntry() {
|
function getCacheEntry(keys) {
|
||||||
var _a;
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const httpClient = createHttpClient();
|
const httpClient = createHttpClient();
|
||||||
const version = getCacheVersion();
|
const version = getCacheVersion();
|
||||||
const resource = `cache?version=${version}`;
|
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
||||||
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -84,8 +84,6 @@ function createHttpClient(): HttpClient {
|
||||||
export function getCacheVersion(): string {
|
export function getCacheVersion(): string {
|
||||||
// Add salt to cache version to support breaking changes in cache entry
|
// Add salt to cache version to support breaking changes in cache entry
|
||||||
const components = [
|
const components = [
|
||||||
core.getInput(Inputs.Key, { required: true }),
|
|
||||||
core.getInput(Inputs.RestoreKeys, { required: false }),
|
|
||||||
core.getInput(Inputs.Path, { required: true }),
|
core.getInput(Inputs.Path, { required: true }),
|
||||||
versionSalt
|
versionSalt
|
||||||
];
|
];
|
||||||
|
@ -96,10 +94,14 @@ export function getCacheVersion(): string {
|
||||||
.digest("hex");
|
.digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCacheEntry(): Promise<ArtifactCacheEntry | null> {
|
export async function getCacheEntry(
|
||||||
|
keys: string[]
|
||||||
|
): Promise<ArtifactCacheEntry | null> {
|
||||||
const httpClient = createHttpClient();
|
const httpClient = createHttpClient();
|
||||||
const version = getCacheVersion();
|
const version = getCacheVersion();
|
||||||
const resource = `cache?version=${version}`;
|
const resource = `cache?keys=${encodeURIComponent(
|
||||||
|
keys.join(",")
|
||||||
|
)}&version=${version}`;
|
||||||
|
|
||||||
const response = await httpClient.getJson<ArtifactCacheEntry>(
|
const response = await httpClient.getJson<ArtifactCacheEntry>(
|
||||||
getCacheApiUrl(resource)
|
getCacheApiUrl(resource)
|
||||||
|
|
|
@ -54,7 +54,7 @@ async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cacheEntry = await cacheHttpClient.getCacheEntry();
|
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
|
||||||
if (!cacheEntry?.archiveLocation) {
|
if (!cacheEntry?.archiveLocation) {
|
||||||
core.info(`Cache not found for input keys: ${keys.join(", ")}`);
|
core.info(`Cache not found for input keys: ${keys.join(", ")}`);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue