Unverified Commit d606e039 authored by David Hadka's avatar David Hadka Committed by GitHub
Browse files

Merge pull request #421 from actions/dhadka/ghes

Caching action should no-op on GHES
parents d33b5077 d3e4f218
Loading
Loading
Loading
Loading
+18
Changes for __tests__/actionUtils.test.ts: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,24 @@ afterEach(() => {
    delete process.env[RefKey];
});

test("isGhes returns true if server url is not github.com", () => {
    try {
        process.env["GITHUB_SERVER_URL"] = "http://example.com";
        expect(actionUtils.isGhes()).toBe(true);
    } finally {
        process.env["GITHUB_SERVER_URL"] = undefined;
    }
});

test("isGhes returns true when server url is github.com", () => {
    try {
        process.env["GITHUB_SERVER_URL"] = "http://github.com";
        expect(actionUtils.isGhes()).toBe(false);
    } finally {
        process.env["GITHUB_SERVER_URL"] = undefined;
    }
});

test("isExactKeyMatch with undefined cache key returns false", () => {
    const key = "linux-rust";
    const cacheKey = undefined;
+19
Changes for __tests__/restore.test.ts: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ beforeAll(() => {
beforeEach(() => {
    process.env[Events.Key] = Events.Push;
    process.env[RefKey] = "refs/heads/feature-branch";

    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
});

afterEach(() => {
@@ -53,6 +55,23 @@ test("restore with invalid event outputs warning", async () => {
    expect(failedMock).toHaveBeenCalledTimes(0);
});

test("restore on GHES should no-op", async () => {
    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);

    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
    const restoreCacheMock = jest.spyOn(cache, "restoreCache");
    const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");

    await run();

    expect(restoreCacheMock).toHaveBeenCalledTimes(0);
    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
    expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
    expect(logWarningMock).toHaveBeenCalledWith(
        "Cache action is not supported on GHES"
    );
});

test("restore with no path should fail", async () => {
    const failedMock = jest.spyOn(core, "setFailed");
    const restoreCacheMock = jest.spyOn(cache, "restoreCache");
+16
Changes for __tests__/save.test.ts: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ beforeAll(() => {
beforeEach(() => {
    process.env[Events.Key] = Events.Push;
    process.env[RefKey] = "refs/heads/feature-branch";

    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
});

afterEach(() => {
@@ -91,6 +93,20 @@ test("save with no primary key in state outputs warning", async () => {
    expect(failedMock).toHaveBeenCalledTimes(0);
});

test("save on GHES should no-op", async () => {
    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);

    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
    const saveCacheMock = jest.spyOn(cache, "saveCache");

    await run();

    expect(saveCacheMock).toHaveBeenCalledTimes(0);
    expect(logWarningMock).toHaveBeenCalledWith(
        "Cache action is not supported on GHES"
    );
});

test("save with exact match returns early", async () => {
    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
+11 −1
Changes for dist/restore/index.js: 11 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -31296,9 +31296,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0;
exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
const core = __importStar(__webpack_require__(470));
const constants_1 = __webpack_require__(694);
function isGhes() {
    const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
    return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
}
exports.isGhes = isGhes;
function isExactKeyMatch(key, cacheKey) {
    return !!(cacheKey &&
        cacheKey.localeCompare(key, undefined, {
@@ -39989,6 +39994,11 @@ const utils = __importStar(__webpack_require__(443));
function run() {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            if (utils.isGhes()) {
                utils.logWarning("Cache action is not supported on GHES");
                utils.setCacheHitOutput(false);
                return;
            }
            // Validate inputs, this can cause task failure
            if (!utils.isValidEvent()) {
                utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
+10 −1
Changes for dist/save/index.js: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -31296,9 +31296,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0;
exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
const core = __importStar(__webpack_require__(470));
const constants_1 = __webpack_require__(694);
function isGhes() {
    const ghUrl = new URL(process.env["GITHUB_SERVER_URL"] || "https://github.com");
    return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
}
exports.isGhes = isGhes;
function isExactKeyMatch(key, cacheKey) {
    return !!(cacheKey &&
        cacheKey.localeCompare(key, undefined, {
@@ -38325,6 +38330,10 @@ const utils = __importStar(__webpack_require__(443));
function run() {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            if (utils.isGhes()) {
                utils.logWarning("Cache action is not supported on GHES");
                return;
            }
            if (!utils.isValidEvent()) {
                utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
                return;
Loading