3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-30 07:05:51 +00:00

Fix script invocations, lint and format.

Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
This commit is contained in:
Gregorio Litenstein 2025-04-25 18:44:18 -04:00
parent 8ac3d1967f
commit 11a6324cc7
No known key found for this signature in database
GPG key ID: 4EB52A1A9CE2C63F
8 changed files with 240 additions and 175 deletions

View file

@ -7,5 +7,6 @@
"trailingComma": "none", "trailingComma": "none",
"bracketSpacing": true, "bracketSpacing": true,
"arrowParens": "avoid", "arrowParens": "avoid",
"parser": "typescript" "parser": "typescript",
"endOfLine": "lf"
} }

View file

@ -75634,9 +75634,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0; exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0;
const cache = __importStar(__nccwpck_require__(5116)); const cache = __importStar(__nccwpck_require__(5116));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const action_1 = __nccwpck_require__(8556);
const request_error_1 = __nccwpck_require__(3708); const request_error_1 = __nccwpck_require__(3708);
const constants_1 = __nccwpck_require__(7242); const constants_1 = __nccwpck_require__(7242);
const { Octokit } = __nccwpck_require__(8556);
function isGhes() { function isGhes() {
const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
const hostname = ghUrl.hostname.trimEnd().toUpperCase(); const hostname = ghUrl.hostname.trimEnd().toUpperCase();
@ -75661,18 +75661,19 @@ exports.logWarning = logWarning;
function deleteCacheByKey(key, owner, repo) { function deleteCacheByKey(key, owner, repo) {
var _a; var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = new Octokit(); const octokit = new action_1.Octokit();
let response; let response;
try { try {
const gitRef = process.env[constants_1.RefKey]; const gitRef = process.env[constants_1.RefKey];
let cacheEntry = yield octokit.rest.actions.getActionsCacheList({ const cacheEntry = yield octokit.rest.actions.getActionsCacheList({
owner: owner, owner: owner,
repo: repo, repo: repo,
key: key, key: key,
ref: gitRef ref: gitRef
}); });
const { data: { total_count, actions_caches } } = cacheEntry; const { data: { total_count, actions_caches } } = cacheEntry;
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. 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.
if (total_count > 1) { if (total_count > 1) {
exports.logWarning(`More than one cache entry found for key ${key}`); exports.logWarning(`More than one cache entry found for key ${key}`);
} }
@ -75687,7 +75688,8 @@ function deleteCacheByKey(key, owner, repo) {
core.info(`Skip trying to delete cache entry for key ${key}.`); core.info(`Skip trying to delete cache entry for key ${key}.`);
return; return;
} }
let id = actions_caches[0].id; const id = actions_caches[0].id;
if (id) {
response = yield octokit.rest.actions.deleteActionsCacheById({ response = yield octokit.rest.actions.deleteActionsCacheById({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -75698,11 +75700,13 @@ function deleteCacheByKey(key, owner, repo) {
return 204; return 204;
} }
} }
}
catch (e) { catch (e) {
if (e instanceof request_error_1.RequestError) { if (e instanceof request_error_1.RequestError) {
let err = e; const err = e;
let errData = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data; // eslint-disable-next-line @typescript-eslint/no-explicit-any
exports.logWarning(`Github API reported error: ${err.name} '${err.status}: ${errData === null || errData === void 0 ? void 0 : errData.message}'`); const errMessage = ((_a = err.response) === null || _a === void 0 ? void 0 : _a.data).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;

20
dist/restore/index.js vendored
View file

@ -75634,9 +75634,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0; exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0;
const cache = __importStar(__nccwpck_require__(5116)); const cache = __importStar(__nccwpck_require__(5116));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const action_1 = __nccwpck_require__(8556);
const request_error_1 = __nccwpck_require__(3708); const request_error_1 = __nccwpck_require__(3708);
const constants_1 = __nccwpck_require__(7242); const constants_1 = __nccwpck_require__(7242);
const { Octokit } = __nccwpck_require__(8556);
function isGhes() { function isGhes() {
const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
const hostname = ghUrl.hostname.trimEnd().toUpperCase(); const hostname = ghUrl.hostname.trimEnd().toUpperCase();
@ -75661,18 +75661,19 @@ exports.logWarning = logWarning;
function deleteCacheByKey(key, owner, repo) { function deleteCacheByKey(key, owner, repo) {
var _a; var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = new Octokit(); const octokit = new action_1.Octokit();
let response; let response;
try { try {
const gitRef = process.env[constants_1.RefKey]; const gitRef = process.env[constants_1.RefKey];
let cacheEntry = yield octokit.rest.actions.getActionsCacheList({ const cacheEntry = yield octokit.rest.actions.getActionsCacheList({
owner: owner, owner: owner,
repo: repo, repo: repo,
key: key, key: key,
ref: gitRef ref: gitRef
}); });
const { data: { total_count, actions_caches } } = cacheEntry; const { data: { total_count, actions_caches } } = cacheEntry;
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. 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.
if (total_count > 1) { if (total_count > 1) {
exports.logWarning(`More than one cache entry found for key ${key}`); exports.logWarning(`More than one cache entry found for key ${key}`);
} }
@ -75687,7 +75688,8 @@ function deleteCacheByKey(key, owner, repo) {
core.info(`Skip trying to delete cache entry for key ${key}.`); core.info(`Skip trying to delete cache entry for key ${key}.`);
return; return;
} }
let id = actions_caches[0].id; const id = actions_caches[0].id;
if (id) {
response = yield octokit.rest.actions.deleteActionsCacheById({ response = yield octokit.rest.actions.deleteActionsCacheById({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -75698,11 +75700,13 @@ function deleteCacheByKey(key, owner, repo) {
return 204; return 204;
} }
} }
}
catch (e) { catch (e) {
if (e instanceof request_error_1.RequestError) { if (e instanceof request_error_1.RequestError) {
let err = e; const err = e;
let errData = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data; // eslint-disable-next-line @typescript-eslint/no-explicit-any
exports.logWarning(`Github API reported error: ${err.name} '${err.status}: ${errData === null || errData === void 0 ? void 0 : errData.message}'`); const errMessage = ((_a = err.response) === null || _a === void 0 ? void 0 : _a.data).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;

View file

@ -75672,9 +75672,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0; exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0;
const cache = __importStar(__nccwpck_require__(5116)); const cache = __importStar(__nccwpck_require__(5116));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const action_1 = __nccwpck_require__(8556);
const request_error_1 = __nccwpck_require__(3708); const request_error_1 = __nccwpck_require__(3708);
const constants_1 = __nccwpck_require__(7242); const constants_1 = __nccwpck_require__(7242);
const { Octokit } = __nccwpck_require__(8556);
function isGhes() { function isGhes() {
const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
const hostname = ghUrl.hostname.trimEnd().toUpperCase(); const hostname = ghUrl.hostname.trimEnd().toUpperCase();
@ -75699,18 +75699,19 @@ exports.logWarning = logWarning;
function deleteCacheByKey(key, owner, repo) { function deleteCacheByKey(key, owner, repo) {
var _a; var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = new Octokit(); const octokit = new action_1.Octokit();
let response; let response;
try { try {
const gitRef = process.env[constants_1.RefKey]; const gitRef = process.env[constants_1.RefKey];
let cacheEntry = yield octokit.rest.actions.getActionsCacheList({ const cacheEntry = yield octokit.rest.actions.getActionsCacheList({
owner: owner, owner: owner,
repo: repo, repo: repo,
key: key, key: key,
ref: gitRef ref: gitRef
}); });
const { data: { total_count, actions_caches } } = cacheEntry; const { data: { total_count, actions_caches } } = cacheEntry;
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. 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.
if (total_count > 1) { if (total_count > 1) {
exports.logWarning(`More than one cache entry found for key ${key}`); exports.logWarning(`More than one cache entry found for key ${key}`);
} }
@ -75725,7 +75726,8 @@ function deleteCacheByKey(key, owner, repo) {
core.info(`Skip trying to delete cache entry for key ${key}.`); core.info(`Skip trying to delete cache entry for key ${key}.`);
return; return;
} }
let id = actions_caches[0].id; const id = actions_caches[0].id;
if (id) {
response = yield octokit.rest.actions.deleteActionsCacheById({ response = yield octokit.rest.actions.deleteActionsCacheById({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -75736,11 +75738,13 @@ function deleteCacheByKey(key, owner, repo) {
return 204; return 204;
} }
} }
}
catch (e) { catch (e) {
if (e instanceof request_error_1.RequestError) { if (e instanceof request_error_1.RequestError) {
let err = e; const err = e;
let errData = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data; // eslint-disable-next-line @typescript-eslint/no-explicit-any
exports.logWarning(`Github API reported error: ${err.name} '${err.status}: ${errData === null || errData === void 0 ? void 0 : errData.message}'`); const errMessage = ((_a = err.response) === null || _a === void 0 ? void 0 : _a.data).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;

20
dist/save/index.js vendored
View file

@ -75672,9 +75672,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0; exports.isCacheFeatureAvailable = exports.getInputAsBool = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.deleteCacheByKey = exports.logWarning = exports.isExactKeyMatch = exports.isGhes = void 0;
const cache = __importStar(__nccwpck_require__(5116)); const cache = __importStar(__nccwpck_require__(5116));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const action_1 = __nccwpck_require__(8556);
const request_error_1 = __nccwpck_require__(3708); const request_error_1 = __nccwpck_require__(3708);
const constants_1 = __nccwpck_require__(7242); const constants_1 = __nccwpck_require__(7242);
const { Octokit } = __nccwpck_require__(8556);
function isGhes() { function isGhes() {
const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com"); const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
const hostname = ghUrl.hostname.trimEnd().toUpperCase(); const hostname = ghUrl.hostname.trimEnd().toUpperCase();
@ -75699,18 +75699,19 @@ exports.logWarning = logWarning;
function deleteCacheByKey(key, owner, repo) { function deleteCacheByKey(key, owner, repo) {
var _a; var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = new Octokit(); const octokit = new action_1.Octokit();
let response; let response;
try { try {
const gitRef = process.env[constants_1.RefKey]; const gitRef = process.env[constants_1.RefKey];
let cacheEntry = yield octokit.rest.actions.getActionsCacheList({ const cacheEntry = yield octokit.rest.actions.getActionsCacheList({
owner: owner, owner: owner,
repo: repo, repo: repo,
key: key, key: key,
ref: gitRef ref: gitRef
}); });
const { data: { total_count, actions_caches } } = cacheEntry; const { data: { total_count, actions_caches } } = cacheEntry;
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. 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.
if (total_count > 1) { if (total_count > 1) {
exports.logWarning(`More than one cache entry found for key ${key}`); exports.logWarning(`More than one cache entry found for key ${key}`);
} }
@ -75725,7 +75726,8 @@ function deleteCacheByKey(key, owner, repo) {
core.info(`Skip trying to delete cache entry for key ${key}.`); core.info(`Skip trying to delete cache entry for key ${key}.`);
return; return;
} }
let id = actions_caches[0].id; const id = actions_caches[0].id;
if (id) {
response = yield octokit.rest.actions.deleteActionsCacheById({ response = yield octokit.rest.actions.deleteActionsCacheById({
owner: owner, owner: owner,
repo: repo, repo: repo,
@ -75736,11 +75738,13 @@ function deleteCacheByKey(key, owner, repo) {
return 204; return 204;
} }
} }
}
catch (e) { catch (e) {
if (e instanceof request_error_1.RequestError) { if (e instanceof request_error_1.RequestError) {
let err = e; const err = e;
let errData = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data; // eslint-disable-next-line @typescript-eslint/no-explicit-any
exports.logWarning(`Github API reported error: ${err.name} '${err.status}: ${errData === null || errData === void 0 ? void 0 : errData.message}'`); const errMessage = ((_a = err.response) === null || _a === void 0 ? void 0 : _a.data).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;

View file

@ -7,9 +7,9 @@
"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 **/*.ts --cache", "lint": "eslint src/**/*.ts --cache __tests__/*.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",

View file

@ -1,10 +1,9 @@
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 { RequestError } from "@octokit/request-error" import { Octokit } from "@octokit/action";
import { OctokitResponse } from "@octokit/types" import { RequestError } from "@octokit/request-error";
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(
@ -33,54 +32,69 @@ export function logWarning(message: string): void {
core.info(`${warningPrefix}${message}`); core.info(`${warningPrefix}${message}`);
} }
export async function deleteCacheByKey(key: string, owner: string, repo: string) : Promise <number | void> { export async function deleteCacheByKey(
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];
let cacheEntry = await octokit.rest.actions.getActionsCacheList({ const cacheEntry = await octokit.rest.actions.getActionsCacheList({
owner: owner, owner: owner,
repo: repo, repo: repo,
key: key, key: key,
ref: gitRef ref: gitRef
}); });
const { data: { const {
total_count, data: { total_count, actions_caches }
actions_caches
}
} = cacheEntry; } = cacheEntry;
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. 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.
if (total_count > 1) { if (total_count > 1) {
exports.logWarning(`More than one cache entry found for key ${key}`); exports.logWarning(
} `More than one cache entry found for key ${key}`
else if (total_count === 0 || actions_caches.length === 0) { );
exports.logWarning(`No cache entries for key ${key} belong to gitref ${gitRef}.`); } else if (total_count === 0 || actions_caches.length === 0) {
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(`Reported cache entry matches for ${key} does not match length of 'actions_caches' array in API response.`); exports.logWarning(
`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;
} }
let id = actions_caches[0].id; const 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(`Succesfully deleted cache with key: ${key}, id: ${id}`); core.info(
`Succesfully deleted cache with key: ${key}, id: ${id}`
);
return 204; return 204;
} }
}
} catch (e) { } catch (e) {
if (e instanceof RequestError) { if (e instanceof RequestError) {
let err = e as RequestError; const err = e as RequestError;
let errData = err.response?.data as any | undefined; // eslint-disable-next-line @typescript-eslint/no-explicit-any
exports.logWarning(`Github API reported error: ${err.name} '${err.status}: ${errData?.message}'`); const errMessage = (err.response?.data as any).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;
} }
} }

View file

@ -1,14 +1,18 @@
/* 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";
export const successCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43"; import { Inputs } from "../constants";
export const wrongRefCacheKey = "Linux-latest-node-bb828da54c148048dd17899ba9fda624811cfb43";
export const failureCacheKey = "Windows-node-bb828da54c148048dd17899ba9fda624811cfb43"; export const successCacheKey =
export const passThroughCacheKey = "macOS-node-bb828da54c148048dd17899ba9fda624811cfb43"; "Linux-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;
@ -61,39 +65,57 @@ export function clearInputs(): void {
} }
export const mockServer = setupServer( export const mockServer = setupServer(
rest.delete('https://api.github.com/repos/owner/repo/actions/caches/', (req, res, ctx) => { rest.delete(
return res(ctx.status(422), "https://api.github.com/repos/owner/repo/actions/caches/",
(req, res, ctx) => {
return res(
ctx.status(422),
ctx.json({ ctx.json({
message: "Invalid request.\n\nMissing required query parameter key", message:
documentation_url: "https://docs.github.com/rest/actions/cache#delete-github-actions-caches-for-a-repository-using-a-cache-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"
}) })
) );
}), }
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(ctx.status(404), return res(
ctx.status(404),
ctx.json({ ctx.json({
message: "Not Found", message: "Not Found",
documentation_url: "https://docs.github.com/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id" documentation_url:
})); "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('https://api.github.com/repos/owner/repo/actions/caches', (req, res, ctx) => { rest.get(
let key : string = req.url?.searchParams?.get('key') || ''; "https://api.github.com/repos/owner/repo/actions/caches",
let ref : string = req.url?.searchParams?.get('ref') || ''; (req, res, ctx) => {
if (key === '' || ref === '') { const key: string = req.url?.searchParams?.get("key") || "";
return res(ctx.status(200), const ref: string = req.url?.searchParams?.get("ref") || "";
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: "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0", version:
last_accessed_at: "2022-12-29T22:06:42.683333300Z", "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
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
}, },
@ -101,39 +123,51 @@ 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: "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0", version:
last_accessed_at: "2022-12-29T22:06:42.683333300Z", "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
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(ctx.status(200), return res(
ctx.status(200),
ctx.json({ ctx.json({
total_count: 0, total_count: 0,
actions_caches: [] actions_caches: []
}) })
); );
} } else if (key === successCacheKey || key === failureCacheKey) {
else if (key === successCacheKey || key === failureCacheKey) { return res(
return res(ctx.status(200), 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: "93a0f912fdb70083e929c1bf564bca2050be1c4e0932f7f9e78465ddcfbcc8f6", version:
last_accessed_at: "2022-12-29T22:06:42.683333300Z", "93a0f912fdb70083e929c1bf564bca2050be1c4e0932f7f9e78465ddcfbcc8f6",
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();
}) }
)
); );