Compare commits

..

1 Commits

Author SHA1 Message Date
b8204782bb Merge pull request #329 from actions/aiyan/v2-release-doc
Update readme and examples to use v2
2020-05-26 15:35:50 -04:00
8 changed files with 27 additions and 95 deletions

View File

@ -2,16 +2,9 @@ import * as core from "@actions/core";
import { Events, Outputs, RefKey, State } from "../src/constants";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
jest.mock("@actions/core");
beforeAll(() => {
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
return jest.requireActual("@actions/core").getInput(name, options);
});
});
afterEach(() => {
delete process.env[Events.Key];
delete process.env[RefKey];
@ -164,33 +157,3 @@ test("isValidEvent returns true for event that has a ref", () => {
expect(isValidEvent).toBe(true);
});
test("getInputAsArray returns empty array if not required and missing", () => {
expect(actionUtils.getInputAsArray("foo")).toEqual([]);
});
test("getInputAsArray throws error if required and missing", () => {
expect(() =>
actionUtils.getInputAsArray("foo", { required: true })
).toThrowError();
});
test("getInputAsArray handles single line correctly", () => {
testUtils.setInput("foo", "bar");
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar"]);
});
test("getInputAsArray handles multiple lines correctly", () => {
testUtils.setInput("foo", "bar\nbaz");
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
});
test("getInputAsArray handles different new lines correctly", () => {
testUtils.setInput("foo", "bar\r\nbaz");
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
});
test("getInputAsArray handles empty lines correctly", () => {
testUtils.setInput("foo", "\n\nbar\n\nbaz\n\n");
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
});

View File

@ -20,13 +20,6 @@ beforeAll(() => {
const actualUtils = jest.requireActual("../src/utils/actionUtils");
return actualUtils.isValidEvent();
});
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
(name, options) => {
const actualUtils = jest.requireActual("../src/utils/actionUtils");
return actualUtils.getInputAsArray(name, options);
}
);
});
beforeEach(() => {

View File

@ -19,14 +19,6 @@ beforeAll(() => {
return jest.requireActual("../src/utils/actionUtils").getCacheState();
});
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
(name, options) => {
return jest
.requireActual("../src/utils/actionUtils")
.getInputAsArray(name, options);
}
);
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
(key, cacheResult) => {
return jest

22
dist/restore/index.js vendored
View File

@ -5306,7 +5306,7 @@ 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.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0;
const core = __importStar(__webpack_require__(470));
const constants_1 = __webpack_require__(694);
function isExactKeyMatch(key, cacheKey) {
@ -5350,14 +5350,6 @@ function isValidEvent() {
return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]);
}
exports.isValidEvent = isValidEvent;
function getInputAsArray(name, options) {
return core
.getInput(name, options)
.split("\n")
.map(s => s.trim())
.filter(x => x !== "");
}
exports.getInputAsArray = getInputAsArray;
/***/ }),
@ -6843,10 +6835,14 @@ function run() {
}
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
required: true
});
const restoreKeys = core
.getInput(constants_1.Inputs.RestoreKeys)
.split("\n")
.filter(x => x !== "");
const cachePaths = core
.getInput(constants_1.Inputs.Path, { required: true })
.split("\n")
.filter(x => x !== "");
try {
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys);
if (!cacheKey) {

17
dist/save/index.js vendored
View File

@ -5306,7 +5306,7 @@ 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.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0;
const core = __importStar(__webpack_require__(470));
const constants_1 = __webpack_require__(694);
function isExactKeyMatch(key, cacheKey) {
@ -5350,14 +5350,6 @@ function isValidEvent() {
return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]);
}
exports.isValidEvent = isValidEvent;
function getInputAsArray(name, options) {
return core
.getInput(name, options)
.split("\n")
.map(s => s.trim())
.filter(x => x !== "");
}
exports.getInputAsArray = getInputAsArray;
/***/ }),
@ -6608,9 +6600,10 @@ function run() {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
return;
}
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
required: true
});
const cachePaths = core
.getInput(constants_1.Inputs.Path, { required: true })
.split("\n")
.filter(x => x !== "");
try {
yield cache.saveCache(cachePaths, primaryKey);
}

View File

@ -19,10 +19,15 @@ async function run(): Promise<void> {
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CachePrimaryKey, primaryKey);
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const restoreKeys = core
.getInput(Inputs.RestoreKeys)
.split("\n")
.filter(x => x !== "");
const cachePaths = core
.getInput(Inputs.Path, { required: true })
.split("\n")
.filter(x => x !== "");
try {
const cacheKey = await cache.restoreCache(

View File

@ -31,9 +31,10 @@ async function run(): Promise<void> {
return;
}
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const cachePaths = core
.getInput(Inputs.Path, { required: true })
.split("\n")
.filter(x => x !== "");
try {
await cache.saveCache(cachePaths, primaryKey);

View File

@ -45,14 +45,3 @@ export function logWarning(message: string): void {
export function isValidEvent(): boolean {
return RefKey in process.env && Boolean(process.env[RefKey]);
}
export function getInputAsArray(
name: string,
options?: core.InputOptions
): string[] {
return core
.getInput(name, options)
.split("\n")
.map(s => s.trim())
.filter(x => x !== "");
}