Update warnings behavior

This commit is contained in:
Josh Gross 2019-11-20 13:19:40 -05:00
parent d9fe1b81f9
commit c48b49d8ee
8 changed files with 82 additions and 40 deletions

View file

@ -10,13 +10,14 @@ async function run(): Promise<void> {
try {
// Validate inputs, this can cause task failure
if (!utils.isValidEvent()) {
core.setFailed(
utils.logWarning(
`Event Validation Error: The event type ${
process.env[Events.Key]
} is not supported. Only ${utils
.getSupportedEvents()
.join(", ")} events are supported at this time.`
);
return;
}
const cachePath = utils.resolvePath(
@ -118,7 +119,7 @@ async function run(): Promise<void> {
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
);
} catch (error) {
core.warning(error.message);
utils.logWarning(error.message);
utils.setCacheHitOutput(false);
}
} catch (error) {

View file

@ -3,17 +3,28 @@ import { exec } from "@actions/exec";
import * as io from "@actions/io";
import * as path from "path";
import * as cacheHttpClient from "./cacheHttpClient";
import { Inputs, State } from "./constants";
import { Events, Inputs, State } from "./constants";
import * as utils from "./utils/actionUtils";
async function run(): Promise<void> {
try {
if (!utils.isValidEvent()) {
utils.logWarning(
`Event Validation Error: The event type ${
process.env[Events.Key]
} is not supported. Only ${utils
.getSupportedEvents()
.join(", ")} events are supported at this time.`
);
return;
}
const state = utils.getCacheState();
// Inputs are re-evaluted before the post action, so we want the original key used for restore
const primaryKey = core.getState(State.CacheKey);
if (!primaryKey) {
core.warning(`Error retrieving key from state.`);
utils.logWarning(`Error retrieving key from state.`);
return;
}
@ -58,7 +69,7 @@ async function run(): Promise<void> {
const archiveFileSize = utils.getArchiveFileSize(archivePath);
core.debug(`File Size: ${archiveFileSize}`);
if (archiveFileSize > fileSizeLimit) {
core.warning(
utils.logWarning(
`Cache size of ~${Math.round(
archiveFileSize / (1024 * 1024)
)} MB (${archiveFileSize} B) is over the 400MB limit, not saving cache.`
@ -68,7 +79,7 @@ async function run(): Promise<void> {
await cacheHttpClient.saveCache(primaryKey, archivePath);
} catch (error) {
core.warning(error.message);
utils.logWarning(error.message);
}
}

View file

@ -77,6 +77,11 @@ export function getCacheState(): ArtifactCacheEntry | undefined {
return undefined;
}
export function logWarning(message: string) {
const warningPrefix = "[warning]";
core.info(`${warningPrefix}${message}`);
}
export function resolvePath(filePath: string): string {
if (filePath[0] === "~") {
const home = os.homedir();