1 Commits

9 changed files with 912 additions and 758 deletions
+3 -3
View File
@@ -9,10 +9,10 @@ jobs:
name: pre-commit Linting
runs-on: pi
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
- run: pip install pre-commit
shell: bash
- name: Pre Commit
run: SKIP=no-commit-to-branch pre-commit run -a --hook-stage pre-commit --hook-stage manual
run: SKIP=no-commit-to-branch pre-commit run -a
shell: bash
+2 -2
View File
@@ -9,8 +9,8 @@ jobs:
name: Run Tests
runs-on: pi
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
- run: npm install
+2 -23
View File
@@ -1,4 +1,3 @@
default_stages: [pre-commit, manual]
exclude: ^(dist|node_modules)/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -16,7 +15,6 @@ repos:
args: [--autofix, --no-sort-keys, --no-ensure-ascii]
- id: check-merge-conflict
- id: no-commit-to-branch
stages: [pre-commit]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.16.0
@@ -31,37 +29,18 @@ repos:
types_or: [css, javascript]
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.37.2
rev: 0.36.2
hooks:
- id: check-renovate
- id: check-github-actions
stages: [manual]
- id: check-github-workflows
stages: [manual]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: end-of-file-fixer
exclude: (.txt$|.ipynb$|README.md$)
exclude: (.txt$|.ipynb$|README.md$|readme.mde$)
- id: trailing-whitespace
exclude: (.txt$|README.md$)
- id: mixed-line-ending
args: [--fix=lf]
- repo: local
hooks:
- id: build
name: rebuild-distribution
entry: npm run build
language: system
files: ^(index\.js|monitor\.js|package\.json|package-lock\.json)$
pass_filenames: false
stages: [pre-commit]
- id: add-dist
name: stage-distribution
entry: git add dist/
language: system
files: ^(index\.js|monitor\.js|package\.json|package-lock\.json)$
pass_filenames: false
stages: [pre-commit]
+6 -6
View File
@@ -1,13 +1,13 @@
import {
const {
validateAuthentication,
replacePlaceholders,
readReplaceAndWriteFiles,
readFilesIntoDict,
} from "../index.js";
import fs from "fs";
import path from "path";
import os from "os";
import { glob } from "glob";
} = require("../index");
const fs = require("fs");
const path = require("path");
const os = require("os");
const { glob } = require("glob");
describe("validateAuthentication", () => {
it("should return null when only token is provided", () => {
+5 -6
View File
File diff suppressed because one or more lines are too long
-3
View File
@@ -1,3 +0,0 @@
{
"type": "module"
}
+19 -13
View File
@@ -1,9 +1,8 @@
import { ScreepsAPI } from "screeps-api";
import * as core from "@actions/core";
import fs from "fs";
import { glob } from "glob";
import path from "path";
import { fileURLToPath } from "url";
const { ScreepsAPI } = require("screeps-api");
const core = require("@actions/core");
const fs = require("fs");
const { glob } = require("glob");
const path = require("path");
/**
* Replaces specific placeholder strings within the provided content with corresponding dynamic values.
@@ -18,7 +17,7 @@ import { fileURLToPath } from "url";
* @param {string} content - The string content in which placeholders are to be replaced.
* @returns {string} The content with placeholders replaced by their respective dynamic values.
*/
export function replacePlaceholders(content, hostname) {
function replacePlaceholders(content, hostname) {
const deployTime = new Date().toISOString();
return content
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
@@ -38,7 +37,7 @@ export function replacePlaceholders(content, hostname) {
* @param {string} [prefix] - An optional directory prefix to prepend to the glob pattern. This allows searching within a specific directory.
* @returns {Promise<string[]>} A promise that resolves with an array of file paths that were processed, or rejects with an error if the process fails.
*/
export async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
const files = await glob(globPattern);
@@ -59,7 +58,7 @@ export async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
* @param {string} prefix - Directory prefix for file paths.
* @returns {Promise<Object>} - Promise resolving to a dictionary of file contents keyed by filenames.
*/
export async function readFilesIntoDict(pattern, prefix) {
async function readFilesIntoDict(pattern, prefix) {
// Prepend the prefix to the glob pattern
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
const files = await glob(globPattern);
@@ -89,7 +88,7 @@ export async function readFilesIntoDict(pattern, prefix) {
* @param {string} password - The password.
* @returns {string|null} - Returns an error message if validation fails, otherwise null.
*/
export function validateAuthentication(token, username, password) {
function validateAuthentication(token, username, password) {
if (token) {
if (username || password) {
return "Token is defined along with username and/or password.";
@@ -111,7 +110,7 @@ export function validateAuthentication(token, username, password) {
/**
* Posts code to Screeps server.
*/
export async function postCode() {
async function postCode() {
const protocol = core.getInput("protocol") || "https";
const hostname = core.getInput("hostname") || "screeps.com";
const port = core.getInput("port") || "443";
@@ -176,7 +175,14 @@ export async function postCode() {
}
}
const __filename = fileURLToPath(import.meta.url);
if (process.argv[1] === __filename) {
if (require.main === module) {
postCode();
}
module.exports = {
validateAuthentication,
replacePlaceholders,
postCode,
readReplaceAndWriteFiles,
readFilesIntoDict,
};
+874 -700
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -2,7 +2,6 @@
"name": "screeps-deploy-action",
"version": "0.1.1",
"description": "Deploys screeps code to the official game or an pirvate server.",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node index.js",
@@ -10,7 +9,7 @@
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
},
"dependencies": {
"@actions/core": "^3.0.0",
"@actions/core": "^2.0.0",
"glob": "^13.0.0",
"screeps-api": "^1.7.2"
},