mirror of
https://github.com/actions/cache.git
synced 2024-11-22 01:41:26 +01:00
Merge pull request #421 from actions/dhadka/ghes
Caching action should no-op on GHES
This commit is contained in:
commit
d606e039ae
8 changed files with 3338 additions and 3248 deletions
|
@ -17,6 +17,24 @@ afterEach(() => {
|
||||||
delete process.env[RefKey];
|
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", () => {
|
test("isExactKeyMatch with undefined cache key returns false", () => {
|
||||||
const key = "linux-rust";
|
const key = "linux-rust";
|
||||||
const cacheKey = undefined;
|
const cacheKey = undefined;
|
||||||
|
|
|
@ -32,6 +32,8 @@ beforeAll(() => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
|
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -53,6 +55,23 @@ test("restore with invalid event outputs warning", async () => {
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
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 () => {
|
test("restore with no path should fail", async () => {
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||||
|
|
|
@ -44,6 +44,8 @@ beforeAll(() => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
|
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -91,6 +93,20 @@ test("save with no primary key in state outputs warning", async () => {
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
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 () => {
|
test("save with exact match returns early", async () => {
|
||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
3258
dist/restore/index.js
vendored
3258
dist/restore/index.js
vendored
File diff suppressed because it is too large
Load diff
3257
dist/save/index.js
vendored
3257
dist/save/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -6,6 +6,12 @@ import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
if (utils.isGhes()) {
|
||||||
|
utils.logWarning("Cache action is not supported on GHES");
|
||||||
|
utils.setCacheHitOutput(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate inputs, this can cause task failure
|
// Validate inputs, this can cause task failure
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(
|
utils.logWarning(
|
||||||
|
|
|
@ -6,6 +6,11 @@ import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
if (utils.isGhes()) {
|
||||||
|
utils.logWarning("Cache action is not supported on GHES");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!utils.isValidEvent()) {
|
if (!utils.isValidEvent()) {
|
||||||
utils.logWarning(
|
utils.logWarning(
|
||||||
`Event Validation Error: The event type ${
|
`Event Validation Error: The event type ${
|
||||||
|
|
|
@ -2,6 +2,13 @@ import * as core from "@actions/core";
|
||||||
|
|
||||||
import { Outputs, RefKey, State } from "../constants";
|
import { Outputs, RefKey, State } from "../constants";
|
||||||
|
|
||||||
|
export function isGhes(): boolean {
|
||||||
|
const ghUrl = new URL(
|
||||||
|
process.env["GITHUB_SERVER_URL"] || "https://github.com"
|
||||||
|
);
|
||||||
|
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
|
||||||
|
}
|
||||||
|
|
||||||
export function isExactKeyMatch(key: string, cacheKey?: string): boolean {
|
export function isExactKeyMatch(key: string, cacheKey?: string): boolean {
|
||||||
return !!(
|
return !!(
|
||||||
cacheKey &&
|
cacheKey &&
|
||||||
|
|
Loading…
Reference in a new issue