Skip to content

Commit 2c7477f

Browse files
committed
Fix tests, generate dist
1 parent 87696e8 commit 2c7477f

File tree

6 files changed

+96
-32
lines changed

6 files changed

+96
-32
lines changed

__tests__/actionUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ test("getInputAsArray returns empty array if not required and missing", () => {
197197
test("getInputAsArray throws error if required and missing", () => {
198198
expect(() =>
199199
actionUtils.getInputAsArray("foo", { required: true })
200-
).toThrowError();
200+
).toThrow();
201201
});
202202

203203
test("getInputAsArray handles single line correctly", () => {
@@ -270,7 +270,7 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
270270
test("getInputAsInt throws if required and value missing", () => {
271271
expect(() =>
272272
actionUtils.getInputAsInt("undefined", { required: true })
273-
).toThrowError();
273+
).toThrow();
274274
});
275275

276276
test("isCacheFeatureAvailable for ac enabled", () => {

__tests__/trivyDBUtils.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ test("fixPermissions runs sudo chown", async () => {
7070
});
7171
exec.mockReturnValueOnce("");
7272
await trivyDBUtils.fixPermissions();
73-
expect(exec).nthCalledWith(1, `sh -c "type sudo 2>&1 >/dev/null"`);
74-
expect(exec).nthCalledWith(2, "sudo chown -R $(stat . -c %u:%g) .trivy");
73+
expect(exec).toHaveBeenNthCalledWith(
74+
1,
75+
`sh -c "type sudo 2>&1 >/dev/null"`
76+
);
77+
expect(exec).toHaveBeenNthCalledWith(
78+
2,
79+
"sudo chown -R $(stat . -c %u:%g) .trivy"
80+
);
7581
});
7682

7783
test("fixPermissions runs without sudo chown", async () => {
@@ -81,6 +87,12 @@ test("fixPermissions runs without sudo chown", async () => {
8187
});
8288
exec.mockRejectedValueOnce(new Error("exit 127"));
8389
await trivyDBUtils.fixPermissions();
84-
expect(exec).nthCalledWith(1, `sh -c "type sudo 2>&1 >/dev/null"`);
85-
expect(exec).nthCalledWith(2, "chown -R $(stat . -c %u:%g) .trivy");
90+
expect(exec).toHaveBeenNthCalledWith(
91+
1,
92+
`sh -c "type sudo 2>&1 >/dev/null"`
93+
);
94+
expect(exec).toHaveBeenNthCalledWith(
95+
2,
96+
"chown -R $(stat . -c %u:%g) .trivy"
97+
);
8698
});

dist/restore/index.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3939
});
4040
};
4141
Object.defineProperty(exports, "__esModule", ({ value: true }));
42-
exports.saveCache = exports.restoreCache = exports.isFeatureAvailable = exports.ReserveCacheError = exports.ValidationError = void 0;
42+
exports.saveCache = exports.restoreCache = exports.isFeatureAvailable = exports.FinalizeCacheError = exports.ReserveCacheError = exports.ValidationError = void 0;
4343
const core = __importStar(__nccwpck_require__(7484));
4444
const path = __importStar(__nccwpck_require__(6928));
4545
const utils = __importStar(__nccwpck_require__(680));
4646
const cacheHttpClient = __importStar(__nccwpck_require__(5552));
4747
const cacheTwirpClient = __importStar(__nccwpck_require__(6819));
4848
const config_1 = __nccwpck_require__(7606);
4949
const tar_1 = __nccwpck_require__(5321);
50-
const constants_1 = __nccwpck_require__(8287);
5150
const http_client_1 = __nccwpck_require__(4844);
5251
class ValidationError extends Error {
5352
constructor(message) {
@@ -65,6 +64,14 @@ class ReserveCacheError extends Error {
6564
}
6665
}
6766
exports.ReserveCacheError = ReserveCacheError;
67+
class FinalizeCacheError extends Error {
68+
constructor(message) {
69+
super(message);
70+
this.name = 'FinalizeCacheError';
71+
Object.setPrototypeOf(this, FinalizeCacheError.prototype);
72+
}
73+
}
74+
exports.FinalizeCacheError = FinalizeCacheError;
6875
function checkPaths(paths) {
6976
if (!paths || paths.length === 0) {
7077
throw new ValidationError(`Path Validation Error: At least one directory or file path is required`);
@@ -441,10 +448,6 @@ function saveCacheV2(paths, key, options, enableCrossOsArchive = false) {
441448
}
442449
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath);
443450
core.debug(`File Size: ${archiveFileSize}`);
444-
// For GHES, this check will take place in ReserveCache API with enterprise file size limit
445-
if (archiveFileSize > constants_1.CacheFileSizeLimit && !(0, config_1.isGhes)()) {
446-
throw new Error(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.`);
447-
}
448451
// Set the archive size in the options, will be used to display the upload progress
449452
options.archiveSizeBytes = archiveFileSize;
450453
core.debug('Reserving Cache');
@@ -457,7 +460,10 @@ function saveCacheV2(paths, key, options, enableCrossOsArchive = false) {
457460
try {
458461
const response = yield twirpClient.CreateCacheEntry(request);
459462
if (!response.ok) {
460-
throw new Error('Response was not ok');
463+
if (response.message) {
464+
core.warning(`Cache reservation failed: ${response.message}`);
465+
}
466+
throw new Error(response.message || 'Response was not ok');
461467
}
462468
signedUploadUrl = response.signedUploadUrl;
463469
}
@@ -475,6 +481,9 @@ function saveCacheV2(paths, key, options, enableCrossOsArchive = false) {
475481
const finalizeResponse = yield twirpClient.FinalizeCacheEntryUpload(finalizeRequest);
476482
core.debug(`FinalizeCacheEntryUploadResponse: ${finalizeResponse.ok}`);
477483
if (!finalizeResponse.ok) {
484+
if (finalizeResponse.message) {
485+
throw new FinalizeCacheError(finalizeResponse.message);
486+
}
478487
throw new Error(`Unable to finalize cache with key ${key}, another job may be finalizing this cache.`);
479488
}
480489
cacheId = parseInt(finalizeResponse.entryId);
@@ -487,6 +496,9 @@ function saveCacheV2(paths, key, options, enableCrossOsArchive = false) {
487496
else if (typedError.name === ReserveCacheError.name) {
488497
core.info(`Failed to save: ${typedError.message}`);
489498
}
499+
else if (typedError.name === FinalizeCacheError.name) {
500+
core.warning(typedError.message);
501+
}
490502
else {
491503
// Log server errors (5xx) as errors, all other errors as warnings
492504
if (typedError instanceof http_client_1.HttpClientError &&
@@ -598,11 +610,12 @@ class CreateCacheEntryResponse$Type extends runtime_5.MessageType {
598610
constructor() {
599611
super("github.actions.results.api.v1.CreateCacheEntryResponse", [
600612
{ no: 1, name: "ok", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
601-
{ no: 2, name: "signed_upload_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
613+
{ no: 2, name: "signed_upload_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
614+
{ no: 3, name: "message", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
602615
]);
603616
}
604617
create(value) {
605-
const message = { ok: false, signedUploadUrl: "" };
618+
const message = { ok: false, signedUploadUrl: "", message: "" };
606619
globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this });
607620
if (value !== undefined)
608621
(0, runtime_3.reflectionMergePartial)(this, message, value);
@@ -619,6 +632,9 @@ class CreateCacheEntryResponse$Type extends runtime_5.MessageType {
619632
case /* string signed_upload_url */ 2:
620633
message.signedUploadUrl = reader.string();
621634
break;
635+
case /* string message */ 3:
636+
message.message = reader.string();
637+
break;
622638
default:
623639
let u = options.readUnknownField;
624640
if (u === "throw")
@@ -637,6 +653,9 @@ class CreateCacheEntryResponse$Type extends runtime_5.MessageType {
637653
/* string signed_upload_url = 2; */
638654
if (message.signedUploadUrl !== "")
639655
writer.tag(2, runtime_1.WireType.LengthDelimited).string(message.signedUploadUrl);
656+
/* string message = 3; */
657+
if (message.message !== "")
658+
writer.tag(3, runtime_1.WireType.LengthDelimited).string(message.message);
640659
let u = options.writeUnknownFields;
641660
if (u !== false)
642661
(u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
@@ -720,11 +739,12 @@ class FinalizeCacheEntryUploadResponse$Type extends runtime_5.MessageType {
720739
constructor() {
721740
super("github.actions.results.api.v1.FinalizeCacheEntryUploadResponse", [
722741
{ no: 1, name: "ok", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
723-
{ no: 2, name: "entry_id", kind: "scalar", T: 3 /*ScalarType.INT64*/ }
742+
{ no: 2, name: "entry_id", kind: "scalar", T: 3 /*ScalarType.INT64*/ },
743+
{ no: 3, name: "message", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
724744
]);
725745
}
726746
create(value) {
727-
const message = { ok: false, entryId: "0" };
747+
const message = { ok: false, entryId: "0", message: "" };
728748
globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this });
729749
if (value !== undefined)
730750
(0, runtime_3.reflectionMergePartial)(this, message, value);
@@ -741,6 +761,9 @@ class FinalizeCacheEntryUploadResponse$Type extends runtime_5.MessageType {
741761
case /* int64 entry_id */ 2:
742762
message.entryId = reader.int64().toString();
743763
break;
764+
case /* string message */ 3:
765+
message.message = reader.string();
766+
break;
744767
default:
745768
let u = options.readUnknownField;
746769
if (u === "throw")
@@ -759,6 +782,9 @@ class FinalizeCacheEntryUploadResponse$Type extends runtime_5.MessageType {
759782
/* int64 entry_id = 2; */
760783
if (message.entryId !== "0")
761784
writer.tag(2, runtime_1.WireType.Varint).int64(message.entryId);
785+
/* string message = 3; */
786+
if (message.message !== "")
787+
writer.tag(3, runtime_1.WireType.LengthDelimited).string(message.message);
762788
let u = options.writeUnknownFields;
763789
if (u !== false)
764790
(u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
@@ -90104,7 +90130,7 @@ module.exports = parseParams
9010490130
/***/ ((module) => {
9010590131

9010690132
"use strict";
90107-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@actions/cache","version":"4.0.5","preview":true,"description":"Actions cache lib","keywords":["github","actions","cache"],"homepage":"https://github.com/actions/toolkit/tree/main/packages/cache","license":"MIT","main":"lib/cache.js","types":"lib/cache.d.ts","directories":{"lib":"lib","test":"__tests__"},"files":["lib","!.DS_Store"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/actions/toolkit.git","directory":"packages/cache"},"scripts":{"audit-moderate":"npm install && npm audit --json --audit-level=moderate > audit.json","test":"echo \\"Error: run tests from root\\" && exit 1","tsc":"tsc"},"bugs":{"url":"https://github.com/actions/toolkit/issues"},"dependencies":{"@actions/core":"^1.11.1","@actions/exec":"^1.0.1","@actions/glob":"^0.1.0","@protobuf-ts/runtime-rpc":"^2.11.1","@actions/http-client":"^2.1.1","@actions/io":"^1.0.1","@azure/abort-controller":"^1.1.0","@azure/ms-rest-js":"^2.6.0","@azure/storage-blob":"^12.13.0","semver":"^6.3.1"},"devDependencies":{"@types/node":"^22.13.9","@types/semver":"^6.0.0","@protobuf-ts/plugin":"^2.9.4","typescript":"^5.2.2"}}');
90133+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@actions/cache","version":"4.1.0","preview":true,"description":"Actions cache lib","keywords":["github","actions","cache"],"homepage":"https://github.com/actions/toolkit/tree/main/packages/cache","license":"MIT","main":"lib/cache.js","types":"lib/cache.d.ts","directories":{"lib":"lib","test":"__tests__"},"files":["lib","!.DS_Store"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/actions/toolkit.git","directory":"packages/cache"},"scripts":{"audit-moderate":"npm install && npm audit --json --audit-level=moderate > audit.json","test":"echo \\"Error: run tests from root\\" && exit 1","tsc":"tsc"},"bugs":{"url":"https://github.com/actions/toolkit/issues"},"dependencies":{"@actions/core":"^1.11.1","@actions/exec":"^1.0.1","@actions/glob":"^0.1.0","@protobuf-ts/runtime-rpc":"^2.11.1","@actions/http-client":"^2.1.1","@actions/io":"^1.0.1","@azure/abort-controller":"^1.1.0","@azure/ms-rest-js":"^2.6.0","@azure/storage-blob":"^12.13.0","semver":"^6.3.1"},"devDependencies":{"@types/node":"^22.13.9","@types/semver":"^6.0.0","@protobuf-ts/plugin":"^2.9.4","typescript":"^5.2.2"}}');
9010890134

9010990135
/***/ }),
9011090136

dist/restore/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)