refactor: migrate to screeps-api v2 and update actions to node 22
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ScreepsAPI } from "screeps-api";
|
||||
import { ScreepsHttpClient } from "screeps-api";
|
||||
import * as core from "@actions/core";
|
||||
import fs from "fs";
|
||||
import { glob } from "glob";
|
||||
@@ -180,12 +180,16 @@ export async function postCode() {
|
||||
core.error(errorMessage);
|
||||
return;
|
||||
}
|
||||
let api = new ScreepsAPI(login_arguments);
|
||||
let api = new ScreepsHttpClient(login_arguments);
|
||||
|
||||
if (!token) {
|
||||
core.info(`Logging in as user ${username}`);
|
||||
try {
|
||||
await api.auth(username, password, login_arguments);
|
||||
if (typeof api.authSignin === "function") {
|
||||
await api.authSignin(username, password);
|
||||
} else {
|
||||
await api.auth(username, password, login_arguments);
|
||||
}
|
||||
} catch (err) {
|
||||
core.error(`Authentication error: ${err}`);
|
||||
throw err;
|
||||
@@ -205,7 +209,9 @@ export async function postCode() {
|
||||
`Downloading existing code from branch ${branch} for potential rollback...`,
|
||||
);
|
||||
try {
|
||||
const getResponse = await api.code.get(branch);
|
||||
const getResponse = await (api.userCodeGet
|
||||
? api.userCodeGet(branch)
|
||||
: api.code.get(branch));
|
||||
if (getResponse && getResponse.ok && getResponse.modules) {
|
||||
oldCode = getResponse.modules;
|
||||
core.info(
|
||||
@@ -226,7 +232,9 @@ export async function postCode() {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await api.code.set(branch, files_to_push);
|
||||
const response = await (api.userCodeSet
|
||||
? api.userCodeSet({ branch, modules: files_to_push })
|
||||
: api.code.set(branch, files_to_push));
|
||||
core.info(JSON.stringify(response, null, 2));
|
||||
core.info(`Code set successfully to ${branch}`);
|
||||
} catch (err) {
|
||||
@@ -279,7 +287,11 @@ export async function postCode() {
|
||||
"Action failed based on monitor configuration. Rolling back to previous code...",
|
||||
);
|
||||
try {
|
||||
await api.code.set(branch, oldCode);
|
||||
if (typeof api.userCodeSet === "function") {
|
||||
await api.userCodeSet({ branch, modules: oldCode });
|
||||
} else {
|
||||
await api.code.set(branch, oldCode);
|
||||
}
|
||||
core.info(
|
||||
`Successfully rolled back to previous code on branch ${branch}.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user