mirror of
https://github.com/actions/cache.git
synced 2026-07-06 12:35:55 +00:00
Compare commits
7 Commits
11a6324cc7
...
4043ab8d77
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4043ab8d77 | ||
|
|
debc4e75e7 | ||
|
|
c3e37a8dd8 | ||
|
|
4c79718f6b | ||
|
|
ed8571e5e3 | ||
|
|
df9df7396d | ||
|
|
d69c349a03 |
@ -2,7 +2,7 @@ name: 'Publish Immutable Action Version'
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [released]
|
types: [published]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
|
|||||||
BIN
.licenses/NOTICE
generated
Normal file
BIN
.licenses/NOTICE
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/exec.dep.yml
generated
BIN
.licenses/npm/@actions/exec.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/action.dep.yml
generated
BIN
.licenses/npm/@octokit/action.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@octokit/plugin-paginate-rest.dep.yml
generated
BIN
.licenses/npm/@octokit/plugin-paginate-rest.dep.yml
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@protobuf-ts/plugin-framework.dep.yml
generated
BIN
.licenses/npm/@protobuf-ts/plugin-framework.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@protobuf-ts/plugin.dep.yml
generated
BIN
.licenses/npm/@protobuf-ts/plugin.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@protobuf-ts/protoc.dep.yml
generated
BIN
.licenses/npm/@protobuf-ts/protoc.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@protobuf-ts/runtime-rpc.dep.yml
generated
BIN
.licenses/npm/@protobuf-ts/runtime-rpc.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@protobuf-ts/runtime.dep.yml
generated
BIN
.licenses/npm/@protobuf-ts/runtime.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/agent-base-6.0.2.dep.yml
generated
Normal file
BIN
.licenses/npm/agent-base-6.0.2.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/before-after-hook.dep.yml
generated
BIN
.licenses/npm/before-after-hook.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/camel-case.dep.yml
generated
Normal file
BIN
.licenses/npm/camel-case.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/commander.dep.yml
generated
Normal file
BIN
.licenses/npm/commander.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/concat-map.dep.yml
generated
BIN
.licenses/npm/concat-map.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/deprecation.dep.yml
generated
BIN
.licenses/npm/deprecation.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/dot-object.dep.yml
generated
Normal file
BIN
.licenses/npm/dot-object.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/event-target-shim.dep.yml
generated
BIN
.licenses/npm/event-target-shim.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/events.dep.yml
generated
BIN
.licenses/npm/events.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/fs.realpath.dep.yml
generated
Normal file
BIN
.licenses/npm/fs.realpath.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/glob.dep.yml
generated
Normal file
BIN
.licenses/npm/glob.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/https-proxy-agent-5.0.1.dep.yml
generated
Normal file
BIN
.licenses/npm/https-proxy-agent-5.0.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/inflight.dep.yml
generated
Normal file
BIN
.licenses/npm/inflight.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/inherits.dep.yml
generated
Normal file
BIN
.licenses/npm/inherits.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/lodash.dep.yml
generated
Normal file
BIN
.licenses/npm/lodash.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/lower-case.dep.yml
generated
Normal file
BIN
.licenses/npm/lower-case.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/minimatch.dep.yml
generated
BIN
.licenses/npm/minimatch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/no-case.dep.yml
generated
Normal file
BIN
.licenses/npm/no-case.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/pascal-case.dep.yml
generated
Normal file
BIN
.licenses/npm/pascal-case.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/path-is-absolute.dep.yml
generated
Normal file
BIN
.licenses/npm/path-is-absolute.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/path-to-regexp.dep.yml
generated
Normal file
BIN
.licenses/npm/path-to-regexp.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/prettier.dep.yml
generated
Normal file
BIN
.licenses/npm/prettier.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/sax.dep.yml
generated
BIN
.licenses/npm/sax.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/semver.dep.yml
generated
BIN
.licenses/npm/semver.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/ts-poet.dep.yml
generated
Normal file
BIN
.licenses/npm/ts-poet.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/tslib-1.14.1.dep.yml
generated
BIN
.licenses/npm/tslib-1.14.1.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/twirp-ts.dep.yml
generated
Normal file
BIN
.licenses/npm/twirp-ts.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/typescript.dep.yml
generated
BIN
.licenses/npm/typescript.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/whatwg-url.dep.yml
generated
BIN
.licenses/npm/whatwg-url.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/yaml.dep.yml
generated
Normal file
BIN
.licenses/npm/yaml.dep.yml
generated
Normal file
Binary file not shown.
@ -7,6 +7,5 @@
|
|||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"arrowParens": "avoid",
|
"arrowParens": "avoid",
|
||||||
"parser": "typescript",
|
"parser": "typescript"
|
||||||
"endOfLine": "lf"
|
|
||||||
}
|
}
|
||||||
12
RELEASES.md
12
RELEASES.md
@ -1,17 +1,5 @@
|
|||||||
# Releases
|
# Releases
|
||||||
|
|
||||||
### 4.2.3
|
|
||||||
|
|
||||||
- Bump `@actions/cache` to v4.0.3 (obfuscates SAS token in debug logs for cache entries)
|
|
||||||
|
|
||||||
### 4.2.2
|
|
||||||
|
|
||||||
- Bump `@actions/cache` to v4.0.2
|
|
||||||
|
|
||||||
### 4.2.1
|
|
||||||
|
|
||||||
- Bump `@actions/cache` to v4.0.1
|
|
||||||
|
|
||||||
### 4.2.0
|
### 4.2.0
|
||||||
|
|
||||||
TLDR; The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.
|
TLDR; The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.
|
||||||
|
|||||||
5939
dist/restore-only/index.js
vendored
5939
dist/restore-only/index.js
vendored
File diff suppressed because one or more lines are too long
5939
dist/restore/index.js
vendored
5939
dist/restore/index.js
vendored
File diff suppressed because one or more lines are too long
5939
dist/save-only/index.js
vendored
5939
dist/save-only/index.js
vendored
File diff suppressed because one or more lines are too long
5939
dist/save/index.js
vendored
5939
dist/save/index.js
vendored
File diff suppressed because one or more lines are too long
1764
package-lock.json
generated
1764
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "4.2.3",
|
"version": "4.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Cache dependencies and build outputs",
|
"description": "Cache dependencies and build outputs",
|
||||||
"main": "dist/restore/index.js",
|
"main": "dist/restore/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/restore-only src/restoreOnly.ts && ncc build -o dist/save-only src/saveOnly.ts",
|
"build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/restore-only src/restoreOnly.ts && ncc build -o dist/save-only src/saveOnly.ts",
|
||||||
"test": "tsc --noEmit && jest --coverage",
|
"test": "tsc --noEmit && jest --coverage",
|
||||||
"lint": "eslint src/**/*.ts --cache __tests__/*.ts --cache",
|
"lint": "eslint **/*.ts --cache",
|
||||||
"format": "prettier --write **/**/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/**/*.ts"
|
"format-check": "prettier --check **/*.ts"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,11 +23,11 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^4.0.3",
|
"@actions/cache": "^4.0.0",
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/io": "^1.1.2",
|
"@actions/io": "^1.1.2",
|
||||||
"@octokit/action": "^5.0.6"
|
"@octokit/action": "^4.0.10"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.5.2",
|
"@types/jest": "^27.5.2",
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import * as cache from "@actions/cache";
|
import * as cache from "@actions/cache";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { Octokit } from "@octokit/action";
|
import { RequestError } from "@octokit/request-error"
|
||||||
import { RequestError } from "@octokit/request-error";
|
import { OctokitResponse } from "@octokit/types"
|
||||||
|
|
||||||
import { RefKey } from "../constants";
|
import { RefKey } from "../constants";
|
||||||
|
const { Octokit } = require("@octokit/action");
|
||||||
|
|
||||||
export function isGhes(): boolean {
|
export function isGhes(): boolean {
|
||||||
const ghUrl = new URL(
|
const ghUrl = new URL(
|
||||||
@ -32,69 +33,54 @@ export function logWarning(message: string): void {
|
|||||||
core.info(`${warningPrefix}${message}`);
|
core.info(`${warningPrefix}${message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteCacheByKey(
|
export async function deleteCacheByKey(key: string, owner: string, repo: string) : Promise <number | void> {
|
||||||
key: string,
|
|
||||||
owner: string,
|
|
||||||
repo: string
|
|
||||||
): Promise<number | void> {
|
|
||||||
const octokit = new Octokit();
|
const octokit = new Octokit();
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
const gitRef = process.env[RefKey];
|
const gitRef = process.env[RefKey];
|
||||||
const cacheEntry = await octokit.rest.actions.getActionsCacheList({
|
let cacheEntry = await octokit.rest.actions.getActionsCacheList({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
key: key,
|
key: key,
|
||||||
ref: gitRef
|
ref: gitRef
|
||||||
});
|
});
|
||||||
const {
|
const { data: {
|
||||||
data: { total_count, actions_caches }
|
total_count,
|
||||||
|
actions_caches
|
||||||
|
}
|
||||||
} = cacheEntry;
|
} = cacheEntry;
|
||||||
if (total_count !== 1 || total_count !== actions_caches.length) {
|
if (total_count !== 1 || total_count !== actions_caches.length) { // leave all find logic to the actual cache implementation. We just want to make sure we're returned a single element so we don't accidentally delete an entry that belongs to a different gitref.
|
||||||
// leave all find logic to the actual cache implementation. We just want to make sure we're returned a single element so we don't accidentally delete an entry that belongs to a different gitref.
|
|
||||||
if (total_count > 1) {
|
if (total_count > 1) {
|
||||||
exports.logWarning(
|
exports.logWarning(`More than one cache entry found for key ${key}`);
|
||||||
`More than one cache entry found for key ${key}`
|
}
|
||||||
);
|
else if (total_count === 0 || actions_caches.length === 0) {
|
||||||
} else if (total_count === 0 || actions_caches.length === 0) {
|
exports.logWarning(`No cache entries for key ${key} belong to gitref ${gitRef}.`);
|
||||||
exports.logWarning(
|
|
||||||
`No cache entries for key ${key} belong to gitref ${gitRef}.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// This situation is likely never actually going to come up.
|
// This situation is likely never actually going to come up.
|
||||||
// Istanbul is being dumb and I can't ignore this path.
|
// Istanbul is being dumb and I can't ignore this path.
|
||||||
else if (total_count !== actions_caches.length) {
|
else if (total_count !== actions_caches.length) {
|
||||||
exports.logWarning(
|
exports.logWarning(`Reported cache entry matches for ${key} does not match length of 'actions_caches' array in API response.`);
|
||||||
`Reported cache entry matches for ${key} does not match length of 'actions_caches' array in API response.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
core.info(`Skip trying to delete cache entry for key ${key}.`);
|
core.info(`Skip trying to delete cache entry for key ${key}.`)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const id = actions_caches[0].id;
|
let id = actions_caches[0].id;
|
||||||
if (id) {
|
|
||||||
response = await octokit.rest.actions.deleteActionsCacheById({
|
response = await octokit.rest.actions.deleteActionsCacheById({
|
||||||
owner: owner,
|
owner: owner,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
cache_id: id
|
cache_id: id
|
||||||
});
|
});
|
||||||
if (response.status === 204) {
|
if (response.status === 204) {
|
||||||
core.info(
|
core.info(`Succesfully deleted cache with key: ${key}, id: ${id}`);
|
||||||
`Succesfully deleted cache with key: ${key}, id: ${id}`
|
|
||||||
);
|
|
||||||
return 204;
|
return 204;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof RequestError) {
|
if (e instanceof RequestError) {
|
||||||
const err = e as RequestError;
|
let err = e as RequestError;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
let errData = err.response?.data as any | undefined;
|
||||||
const errMessage = (err.response?.data as any).message;
|
exports.logWarning(`Github API reported error: ${err.name} '${err.status}: ${errData?.message}'`);
|
||||||
exports.logWarning(
|
|
||||||
`Github API reported error: ${err.name} '${err.status}: ${errMessage}'`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
core.info(`Couldn't delete cache entry for key ${key}.`);
|
core.info(`Couldn't delete cache entry for key ${key}.`)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,14 @@
|
|||||||
/* istanbul ignore file */
|
/* istanbul ignore file */
|
||||||
|
|
||||||
|
import { Inputs } from "../constants";
|
||||||
import { rest } from "msw";
|
import { rest } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { setupServer } from "msw/node";
|
||||||
|
import nock from "nock";
|
||||||
|
|
||||||
import { Inputs } from "../constants";
|
export const successCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
|
export const wrongRefCacheKey = "Linux-latest-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
export const successCacheKey =
|
export const failureCacheKey = "Windows-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
"Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
export const passThroughCacheKey = "macOS-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
export const wrongRefCacheKey =
|
|
||||||
"Linux-latest-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
|
||||||
export const failureCacheKey =
|
|
||||||
"Windows-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
|
||||||
export const passThroughCacheKey =
|
|
||||||
"macOS-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
|
||||||
const successCacheId = 1337;
|
const successCacheId = 1337;
|
||||||
const failureCacheId = 69;
|
const failureCacheId = 69;
|
||||||
|
|
||||||
@ -65,57 +61,39 @@ export function clearInputs(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const mockServer = setupServer(
|
export const mockServer = setupServer(
|
||||||
rest.delete(
|
rest.delete('https://api.github.com/repos/owner/repo/actions/caches/', (req, res, ctx) => {
|
||||||
"https://api.github.com/repos/owner/repo/actions/caches/",
|
return res(ctx.status(422),
|
||||||
(req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.status(422),
|
|
||||||
ctx.json({
|
ctx.json({
|
||||||
message:
|
message: "Invalid request.\n\nMissing required query parameter key",
|
||||||
"Invalid request.\n\nMissing required query parameter key",
|
documentation_url: "https://docs.github.com/rest/actions/cache#delete-github-actions-caches-for-a-repository-using-a-cache-key",
|
||||||
documentation_url:
|
|
||||||
"https://docs.github.com/rest/actions/cache#delete-github-actions-caches-for-a-repository-using-a-cache-key"
|
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
}
|
}),
|
||||||
),
|
rest.delete('https://api.github.com/repos/owner/repo/actions/caches/:id', (req, res, ctx) => {
|
||||||
rest.delete(
|
|
||||||
"https://api.github.com/repos/owner/repo/actions/caches/:id",
|
|
||||||
(req, res, ctx) => {
|
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (parseInt(id as string) === failureCacheId) {
|
if (parseInt(id as string) === failureCacheId) {
|
||||||
return res(
|
return res(ctx.status(404),
|
||||||
ctx.status(404),
|
|
||||||
ctx.json({
|
ctx.json({
|
||||||
message: "Not Found",
|
message: "Not Found",
|
||||||
documentation_url:
|
documentation_url: "https://docs.github.com/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id"
|
||||||
"https://docs.github.com/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id"
|
}));
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return res(ctx.status(204));
|
return res(ctx.status(204));
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
// This endpoint always returns 200/OK, what we're checking here is whether we can get a unique cache ID, to avoid deleting the wrong entry.
|
// This endpoint always returns 200/OK, what we're checking here is whether we can get a unique cache ID, to avoid deleting the wrong entry.
|
||||||
rest.get(
|
rest.get('https://api.github.com/repos/owner/repo/actions/caches', (req, res, ctx) => {
|
||||||
"https://api.github.com/repos/owner/repo/actions/caches",
|
let key : string = req.url?.searchParams?.get('key') || '';
|
||||||
(req, res, ctx) => {
|
let ref : string = req.url?.searchParams?.get('ref') || '';
|
||||||
const key: string = req.url?.searchParams?.get("key") || "";
|
if (key === '' || ref === '') {
|
||||||
const ref: string = req.url?.searchParams?.get("ref") || "";
|
return res(ctx.status(200),
|
||||||
if (key === "" || ref === "") {
|
|
||||||
return res(
|
|
||||||
ctx.status(200),
|
|
||||||
ctx.json({
|
ctx.json({
|
||||||
total_count: 2,
|
total_count: 2,
|
||||||
actions_caches: [
|
actions_caches: [{
|
||||||
{
|
|
||||||
id: 15,
|
id: 15,
|
||||||
ref: "refs/heads/main",
|
ref: "refs/heads/main",
|
||||||
key: failureCacheKey,
|
key: failureCacheKey,
|
||||||
version:
|
version: "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
||||||
"73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
last_accessed_at: "2022-12-29T22:06:42.683333300Z",
|
||||||
last_accessed_at:
|
|
||||||
"2022-12-29T22:06:42.683333300Z",
|
|
||||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||||
size_in_bytes: 6057793
|
size_in_bytes: 6057793
|
||||||
},
|
},
|
||||||
@ -123,51 +101,39 @@ export const mockServer = setupServer(
|
|||||||
id: 16,
|
id: 16,
|
||||||
ref: "refs/heads/another-feature-branch",
|
ref: "refs/heads/another-feature-branch",
|
||||||
key: failureCacheKey,
|
key: failureCacheKey,
|
||||||
version:
|
version: "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
||||||
"73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
last_accessed_at: "2022-12-29T22:06:42.683333300Z",
|
||||||
last_accessed_at:
|
|
||||||
"2022-12-29T22:06:42.683333300Z",
|
|
||||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||||
size_in_bytes: 6057793
|
size_in_bytes: 6057793
|
||||||
}
|
}]
|
||||||
]
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// This is the behavior seen when search doesn't find anything, but it is seen both when no key matches, as well as when the key matches but the entry belongs to another (likely the base) branch.
|
// This is the behavior seen when search doesn't find anything, but it is seen both when no key matches, as well as when the key matches but the entry belongs to another (likely the base) branch.
|
||||||
else if (key === wrongRefCacheKey) {
|
else if (key === wrongRefCacheKey) {
|
||||||
return res(
|
return res(ctx.status(200),
|
||||||
ctx.status(200),
|
|
||||||
ctx.json({
|
ctx.json({
|
||||||
total_count: 0,
|
total_count: 0,
|
||||||
actions_caches: []
|
actions_caches: []
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else if (key === successCacheKey || key === failureCacheKey) {
|
}
|
||||||
return res(
|
else if (key === successCacheKey || key === failureCacheKey) {
|
||||||
ctx.status(200),
|
return res(ctx.status(200),
|
||||||
ctx.json({
|
ctx.json({
|
||||||
total_count: 1,
|
total_count: 1,
|
||||||
actions_caches: [
|
actions_caches: [{
|
||||||
{
|
id: (key === successCacheKey ? successCacheId : failureCacheId),
|
||||||
id:
|
|
||||||
key === successCacheKey
|
|
||||||
? successCacheId
|
|
||||||
: failureCacheId,
|
|
||||||
ref: ref,
|
ref: ref,
|
||||||
key: key,
|
key: key,
|
||||||
version:
|
version: "93a0f912fdb70083e929c1bf564bca2050be1c4e0932f7f9e78465ddcfbcc8f6",
|
||||||
"93a0f912fdb70083e929c1bf564bca2050be1c4e0932f7f9e78465ddcfbcc8f6",
|
last_accessed_at: "2022-12-29T22:06:42.683333300Z",
|
||||||
last_accessed_at:
|
|
||||||
"2022-12-29T22:06:42.683333300Z",
|
|
||||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||||
size_in_bytes: 6057793
|
size_in_bytes: 6057793
|
||||||
}
|
}]
|
||||||
]
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return req.passthrough();
|
return req.passthrough();
|
||||||
}
|
})
|
||||||
)
|
|
||||||
);
|
);
|
||||||
@ -38,8 +38,9 @@ From `v3.2.3` cache is cross-os compatible when `enableCrossOsArchive` input is
|
|||||||
|
|
||||||
## Force deletion of caches overriding default cache eviction policy
|
## Force deletion of caches overriding default cache eviction policy
|
||||||
|
|
||||||
Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing.
|
Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. In order to achieve this, [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) can be used to delete caches for specific branches.
|
||||||
|
|
||||||
|
This workflow uses `gh-actions-cache` to delete all the caches created by a branch.
|
||||||
<details>
|
<details>
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
@ -60,23 +61,29 @@ jobs:
|
|||||||
actions: write
|
actions: write
|
||||||
contents: read
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
run: |
|
run: |
|
||||||
|
gh extension install actions/gh-actions-cache
|
||||||
|
|
||||||
|
REPO=${{ github.repository }}
|
||||||
|
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
|
||||||
|
|
||||||
echo "Fetching list of cache key"
|
echo "Fetching list of cache key"
|
||||||
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
|
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
|
||||||
|
|
||||||
## Setting this to not fail the workflow while deleting cache keys.
|
## Setting this to not fail the workflow while deleting cache keys.
|
||||||
set +e
|
set +e
|
||||||
echo "Deleting caches..."
|
echo "Deleting caches..."
|
||||||
for cacheKey in $cacheKeysForPR
|
for cacheKey in $cacheKeysForPR
|
||||||
do
|
do
|
||||||
gh cache delete $cacheKey
|
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
|
||||||
done
|
done
|
||||||
echo "Done"
|
echo "Done"
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
GH_REPO: ${{ github.repository }}
|
|
||||||
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user