Skip to content

Commit

Permalink
Merge pull request #421 from actions/dhadka/ghes
Browse files Browse the repository at this point in the history
Caching action should no-op on GHES
  • Loading branch information
David Hadka authored and GitHub committed Sep 30, 2020
2 parents d33b507 + d3e4f21 commit d606e03
Show file tree
Hide file tree
Showing 8 changed files with 3,338 additions and 3,248 deletions.
18 changes: 18 additions & 0 deletions __tests__/actionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions __tests__/restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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");
Expand Down
16 changes: 16 additions & 0 deletions __tests__/save.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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");
Expand Down
Loading

0 comments on commit d606e03

Please sign in to comment.