First draft of this application.
Some checks failed
Lint / pre-commit Linting (push) Failing after 54s
Some checks failed
Lint / pre-commit Linting (push) Failing after 54s
This commit is contained in:
parent
20d547fd4d
commit
3c9c228e9b
88
index.js
Normal file
88
index.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
const { ScreepsAPI } = require('screeps-api');
|
||||||
|
const core = require("@actions/core");
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const glob = require('glob');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function readFilesIntoDict(pattern, prefix) {
|
||||||
|
// Prepend the prefix to the glob pattern
|
||||||
|
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
glob(globPattern, (err, files) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileDict = {};
|
||||||
|
let readPromises = [];
|
||||||
|
|
||||||
|
files.forEach(file => {
|
||||||
|
let readPromise = fs.promises.readFile(file, 'utf8')
|
||||||
|
.then(content => {
|
||||||
|
// Correctly remove the prefix from the filename
|
||||||
|
const key = prefix && file.startsWith(prefix) ? file.slice(prefix.length) : file;
|
||||||
|
fileDict[key] = content;
|
||||||
|
});
|
||||||
|
|
||||||
|
readPromises.push(readPromise);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use Promise.all to ensure all files are read before resolving
|
||||||
|
Promise.all(readPromises)
|
||||||
|
.then(() => resolve(fileDict))
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function postCode() {
|
||||||
|
const protocol = core.getInput("protocol") || "https";
|
||||||
|
const hostname = core.getInput("hostname") || "screeps.com";
|
||||||
|
const port = core.getInput("port") || "443";
|
||||||
|
const path = core.getInput("path") || "/";
|
||||||
|
|
||||||
|
const token = core.getInput("token") || undefined;
|
||||||
|
const username = core.getInput("username") || undefined;
|
||||||
|
const password = core.getInput("password") || undefined;
|
||||||
|
|
||||||
|
const prefix = core.getInput("prefix");
|
||||||
|
|
||||||
|
const pattern = core.getInput("pattern") || "*.js";
|
||||||
|
const branch = core.getInput("branch") || "default";
|
||||||
|
|
||||||
|
const files_to_push = readFilesIntoDict(pattern, prefix);
|
||||||
|
|
||||||
|
const login_arguemnts = {
|
||||||
|
"token": token,
|
||||||
|
"username": username,
|
||||||
|
"passowrd": password,
|
||||||
|
"protocol": protocol,
|
||||||
|
"hostname": hostname,
|
||||||
|
"port": port,
|
||||||
|
"path": path,
|
||||||
|
};
|
||||||
|
if (!token) {
|
||||||
|
if (!username && !password) {
|
||||||
|
core.error("Neither token nor password and username are defined.")
|
||||||
|
} else if (username && !password) {
|
||||||
|
core.error("It seems like you would like to login via username but no username seems to be defined.");
|
||||||
|
} else if (!username && password) {
|
||||||
|
core.error("It seems like you would like to login via username but no password seems to be defined.");
|
||||||
|
}
|
||||||
|
} else if (username && password) {
|
||||||
|
core.error("In addition to a token both username and password are defined.");
|
||||||
|
} else if (username) {
|
||||||
|
core.error("In addition to a token the username is defined.");
|
||||||
|
} else if (password) {
|
||||||
|
core.error("In addition to a token the passwrd is defined.")
|
||||||
|
}
|
||||||
|
core.log(JSON.stringify(login_arguemnts, null, 2));
|
||||||
|
const api = new ScreepsAPI(login_arguemnts);
|
||||||
|
api.code.set(branch, files_to_push)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
postCode();
|
1
package-lock.json
generated
1
package-lock.json
generated
@ -9,6 +9,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
|
"glob": "^7.1.6",
|
||||||
"screeps-api": "^1.16.0"
|
"screeps-api": "^1.16.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
10
package.json
10
package.json
@ -1,11 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "gitea-act-create-pr",
|
"name": "screeps-deploy-action",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Gitea PR Creation Action",
|
"description": "Deploys screeps code to the official game or an pirvate server.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"screeps-api": "^1.16.0"
|
"screeps-api": "^1.16.0",
|
||||||
|
"glob": "^7.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user