feat: add rollback_on_failure feature
This commit is contained in:
@@ -6,6 +6,7 @@ This repository is maintained by Gemini.
|
||||
|
||||
* **Test-Driven Development (TDD):** Wherever possible, Test-Driven Development principles should be followed. Write tests before writing the code they are intended to validate.
|
||||
* **Pre-commit Hooks:** Ensure that `pre-commit` hooks are installed and active before making any commits. This can be done by running `pre-commit install` in your local repository.
|
||||
* **Note for Gemini:** Git commits trigger pre-commit hooks, which can take several seconds (or minutes) to complete. Checking the command status for git commit is only appropriate every 120s.
|
||||
|
||||
## Repository Comparison
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ inputs:
|
||||
description: 'Print a progress update every N ticks when log_to_file=true (default: 10).'
|
||||
required: false
|
||||
default: '10'
|
||||
rollback_on_failure:
|
||||
description: 'Automatically rollback to previous code if the monitor detects failures. Requires monitor > 0. (default: false)'
|
||||
required: false
|
||||
default: 'false'
|
||||
outputs:
|
||||
saw_traceback:
|
||||
description: true if a JS traceback was detected during monitoring.
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -179,22 +179,55 @@ export async function postCode() {
|
||||
return;
|
||||
}
|
||||
let api = new ScreepsAPI(login_arguments);
|
||||
if (token) {
|
||||
|
||||
if (!token) {
|
||||
core.info(`Logging in as user ${username}`);
|
||||
try {
|
||||
await api.auth(username, password, login_arguments);
|
||||
} catch (err) {
|
||||
core.error(`Authentication error: ${err}`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
let oldCode = null;
|
||||
let rollbackOnFailure = false;
|
||||
try {
|
||||
rollbackOnFailure = core.getBooleanInput("rollback_on_failure");
|
||||
} catch (e) {
|
||||
// getBooleanInput throws if not 'true' or 'false', ignore
|
||||
}
|
||||
|
||||
if (rollbackOnFailure) {
|
||||
core.info(
|
||||
`Downloading existing code from branch ${branch} for potential rollback...`,
|
||||
);
|
||||
try {
|
||||
const getResponse = await api.code.get(branch);
|
||||
if (getResponse && getResponse.ok && getResponse.modules) {
|
||||
oldCode = getResponse.modules;
|
||||
core.info(
|
||||
`Successfully downloaded existing code (modules: ${Object.keys(oldCode).join(", ")})`,
|
||||
);
|
||||
} else {
|
||||
core.warning(
|
||||
`Failed to download existing code, rollback will not be possible.`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
core.warning(
|
||||
`Error downloading existing code: ${err.message}. Rollback will not be possible.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await api.code.set(branch, files_to_push);
|
||||
core.info(JSON.stringify(response, null, 2));
|
||||
core.info(`Code set successfully to ${branch}`);
|
||||
} else {
|
||||
core.info(`Logging in as user ${username}`);
|
||||
await Promise.resolve()
|
||||
.then(() => api.auth(username, password, login_arguments))
|
||||
.then(() => api.code.set(branch, files_to_push))
|
||||
.then(() => {
|
||||
core.info(`Code set successfully to ${branch}`);
|
||||
})
|
||||
.catch((err) => {
|
||||
} catch (err) {
|
||||
core.error(`Upload error: ${err}`);
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
// Console monitoring (optional)
|
||||
@@ -215,6 +248,28 @@ 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;
|
||||
|
||||
if (shouldFail && rollbackOnFailure && oldCode) {
|
||||
core.info(
|
||||
"Action failed based on monitor configuration. Rolling back to previous code...",
|
||||
);
|
||||
try {
|
||||
await api.code.set(branch, oldCode);
|
||||
core.info(
|
||||
`Successfully rolled back to previous code on branch ${branch}.`,
|
||||
);
|
||||
} catch (err) {
|
||||
core.error(`Rollback failed: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
applyOnAction(
|
||||
core.getInput("on_traceback"),
|
||||
result.sawTraceback,
|
||||
|
||||
Reference in New Issue
Block a user