This commit is contained in:
26
action.yaml
26
action.yaml
@ -1,33 +1,33 @@
|
||||
name: 'Upload to Screeps'
|
||||
description: 'This action uploads code to the Screeps server.'
|
||||
name: Upload to Screeps
|
||||
description: This action uploads code to the Screeps server.
|
||||
inputs:
|
||||
protocol:
|
||||
description: 'The protocol to use (default: https).'
|
||||
required: false
|
||||
default: 'https'
|
||||
default: https
|
||||
hostname:
|
||||
description: 'The hostname of the Screeps server (default: screeps.com).'
|
||||
required: false
|
||||
default: 'screeps.com'
|
||||
default: screeps.com
|
||||
port:
|
||||
description: 'The port to use (default: 443).'
|
||||
required: false
|
||||
default: '443'
|
||||
path:
|
||||
description: 'The path for the API.'
|
||||
description: The path for the API.
|
||||
required: false
|
||||
default: '/'
|
||||
default: /
|
||||
token:
|
||||
description: 'Authentication token for Screeps.'
|
||||
description: Authentication token for Screeps.
|
||||
required: true
|
||||
username:
|
||||
description: 'Username for Screeps account. Used if no token is provided.'
|
||||
description: Username for Screeps account. Used if no token is provided.
|
||||
required: false
|
||||
password:
|
||||
description: 'Password for Screeps account. Used if no token is provided.'
|
||||
description: Password for Screeps account. Used if no token is provided.
|
||||
required: false
|
||||
prefix:
|
||||
description: 'Directory prefix for file paths.'
|
||||
description: Directory prefix for file paths.
|
||||
required: false
|
||||
pattern:
|
||||
description: 'Glob pattern to match files (default: *.js).'
|
||||
@ -36,7 +36,7 @@ inputs:
|
||||
branch:
|
||||
description: 'Branch in Screeps to which the code will be uploaded (default: default).'
|
||||
required: false
|
||||
default: 'default'
|
||||
default: default
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'index.js'
|
||||
using: node12
|
||||
main: index.js
|
||||
|
33
index.js
33
index.js
@ -1,8 +1,8 @@
|
||||
const { ScreepsAPI } = require('screeps-api');
|
||||
const { ScreepsAPI } = require("screeps-api");
|
||||
const core = require("@actions/core");
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
const path = require("path");
|
||||
|
||||
/**
|
||||
* Reads files matching a glob pattern into a dictionary.
|
||||
@ -23,9 +23,8 @@ function readFilesIntoDict(pattern, prefix) {
|
||||
let fileDict = {};
|
||||
let readPromises = [];
|
||||
|
||||
files.forEach(file => {
|
||||
let readPromise = fs.promises.readFile(file, 'utf8')
|
||||
.then(content => {
|
||||
files.forEach((file) => {
|
||||
let readPromise = fs.promises.readFile(file, "utf8").then((content) => {
|
||||
// Remove the prefix from the filename and drop the file suffix
|
||||
let key = file;
|
||||
if (prefix && file.startsWith(prefix)) {
|
||||
@ -91,24 +90,24 @@ async function postCode() {
|
||||
|
||||
const files_to_push = await readFilesIntoDict(pattern, prefix);
|
||||
|
||||
Object.keys(files_to_push).forEach(key => {
|
||||
Object.keys(files_to_push).forEach((key) => {
|
||||
core.info(`Key: ${key}`);
|
||||
});
|
||||
|
||||
core.info(files_to_push);
|
||||
|
||||
const login_arguments = {
|
||||
"token": token,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"protocol": protocol,
|
||||
"hostname": hostname,
|
||||
"port": port,
|
||||
"path": path,
|
||||
token: token,
|
||||
username: username,
|
||||
password: password,
|
||||
protocol: protocol,
|
||||
hostname: hostname,
|
||||
port: port,
|
||||
path: path,
|
||||
};
|
||||
|
||||
core.info(`Trying to upload the following files to ${branch}:`)
|
||||
Object.keys(login_arguments).forEach(key => {
|
||||
core.info(`Trying to upload the following files to ${branch}:`);
|
||||
Object.keys(login_arguments).forEach((key) => {
|
||||
core.info(`Key: ${key}`);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user