refactor: apply PR feedback for rollback feature
This commit is contained in:
@@ -118,17 +118,19 @@ export function validateAuthentication(token, username, password) {
|
||||
* @param {'ignore'|'warn'|'fail'} action
|
||||
* @param {boolean} flag - Only acts when true
|
||||
* @param {string} message - Passed to core.warning / core.setFailed
|
||||
* @returns {boolean} - Returns true if the action was 'fail' and the flag was true.
|
||||
*/
|
||||
export function applyOnAction(action, flag, message) {
|
||||
if (!flag) return;
|
||||
if (!flag) return false;
|
||||
if (action === "warn") {
|
||||
core.warning(message);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (action === "fail") {
|
||||
core.setFailed(message);
|
||||
return true;
|
||||
}
|
||||
// 'ignore' → no-op
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,14 +212,16 @@ export async function postCode() {
|
||||
`Successfully downloaded existing code (modules: ${Object.keys(oldCode).join(", ")})`,
|
||||
);
|
||||
} else {
|
||||
core.warning(
|
||||
`Failed to download existing code, rollback will not be possible.`,
|
||||
core.setFailed(
|
||||
`Failed to download existing code, but rollback_on_failure is enabled. Aborting deployment.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
core.warning(
|
||||
`Error downloading existing code: ${err.message}. Rollback will not be possible.`,
|
||||
core.setFailed(
|
||||
`Error downloading existing code: ${err.message}. Aborting deployment.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,13 +252,23 @@ export async function postCode() {
|
||||
core.setOutput("saw_error_log", String(result.sawErrorLog));
|
||||
core.setOutput("saw_warning_log", String(result.sawWarningLog));
|
||||
|
||||
let shouldFail = false;
|
||||
if (core.getInput("on_traceback") === "fail" && result.sawTraceback)
|
||||
shouldFail = true;
|
||||
if (core.getInput("on_error_log") === "fail" && result.sawErrorLog)
|
||||
shouldFail = true;
|
||||
if (core.getInput("on_warning_log") === "fail" && result.sawWarningLog)
|
||||
shouldFail = true;
|
||||
const fail1 = applyOnAction(
|
||||
core.getInput("on_traceback") || "fail",
|
||||
result.sawTraceback,
|
||||
"Screeps console: traceback detected",
|
||||
);
|
||||
const fail2 = applyOnAction(
|
||||
core.getInput("on_error_log") || "warn",
|
||||
result.sawErrorLog,
|
||||
"Screeps console: error log output detected",
|
||||
);
|
||||
const fail3 = applyOnAction(
|
||||
core.getInput("on_warning_log") || "ignore",
|
||||
result.sawWarningLog,
|
||||
"Screeps console: warning log output detected",
|
||||
);
|
||||
|
||||
const shouldFail = fail1 || fail2 || fail3;
|
||||
|
||||
if (shouldFail && rollbackOnFailure && oldCode) {
|
||||
core.info(
|
||||
@@ -269,22 +283,6 @@ export async function postCode() {
|
||||
core.error(`Rollback failed: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
applyOnAction(
|
||||
core.getInput("on_traceback"),
|
||||
result.sawTraceback,
|
||||
"Screeps console: traceback detected",
|
||||
);
|
||||
applyOnAction(
|
||||
core.getInput("on_error_log"),
|
||||
result.sawErrorLog,
|
||||
"Screeps console: error log output detected",
|
||||
);
|
||||
applyOnAction(
|
||||
core.getInput("on_warning_log"),
|
||||
result.sawWarningLog,
|
||||
"Screeps console: warning log output detected",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user