Compare commits
6 Commits
main
...
test-fix-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
8ca9c67979
|
|||
| 48f7596789 | |||
|
ae87ee6e35
|
|||
|
6ff8731e50
|
|||
|
b7136de5e2
|
|||
|
a2b753417a
|
@@ -20,8 +20,7 @@
|
|||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
"files.eol": "\n"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ git config --global --add safe.directory $(pwd)
|
|||||||
|
|
||||||
# In your setup.sh or postCreateCommand
|
# In your setup.sh or postCreateCommand
|
||||||
sudo chown -R node:node /home/node/.cache/
|
sudo chown -R node:node /home/node/.cache/
|
||||||
sudo chown -R node:node /workspaces/screeps-deploy-action/.git/hooks
|
|
||||||
# 2. Re-connect Git Hooks
|
# 2. Re-connect Git Hooks
|
||||||
pre-commit install
|
pre-commit install
|
||||||
pre-commit install-hooks
|
pre-commit install-hooks
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
charset = utf-8
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1 +0,0 @@
|
|||||||
* text=auto eol=lf
|
|
||||||
@@ -9,8 +9,8 @@ jobs:
|
|||||||
name: pre-commit Linting
|
name: pre-commit Linting
|
||||||
runs-on: pi
|
runs-on: pi
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
|
- uses: actions/setup-python@v6
|
||||||
- run: pip install pre-commit
|
- run: pip install pre-commit
|
||||||
shell: bash
|
shell: bash
|
||||||
- name: Pre Commit
|
- name: Pre Commit
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ jobs:
|
|||||||
name: Run Tests
|
name: Run Tests
|
||||||
runs-on: pi
|
runs-on: pi
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '22'
|
||||||
- run: npm install
|
- run: npm install
|
||||||
shell: bash
|
shell: bash
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1075,6 +1075,4 @@ FodyWeavers.xsd
|
|||||||
*.vsix
|
*.vsix
|
||||||
|
|
||||||
/node_modules/
|
/node_modules/
|
||||||
/node_modules/.cache/
|
|
||||||
/coverage/
|
/coverage/
|
||||||
!/dist/
|
|
||||||
|
|||||||
@@ -5,20 +5,28 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: check-json
|
- id: check-json
|
||||||
|
- id: check-toml
|
||||||
|
- id: check-xml
|
||||||
- id: check-added-large-files
|
- id: check-added-large-files
|
||||||
args: [--enforce-all]
|
args: [--enforce-all]
|
||||||
exclude: ^dist/index\.js$
|
exclude: ^dist/index\.js$
|
||||||
|
- id: name-tests-test
|
||||||
- id: detect-private-key
|
- id: detect-private-key
|
||||||
- id: check-case-conflict
|
- id: check-case-conflict
|
||||||
- id: check-symlinks
|
- id: check-symlinks
|
||||||
|
- id: check-docstring-first
|
||||||
- id: pretty-format-json
|
- id: pretty-format-json
|
||||||
args: [--autofix, --no-sort-keys, --no-ensure-ascii]
|
args: [--autofix, --no-sort-keys, --no-ensure-ascii]
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- id: no-commit-to-branch
|
- id: no-commit-to-branch
|
||||||
|
|
||||||
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
||||||
rev: v2.16.0
|
rev: v2.15.0
|
||||||
hooks:
|
hooks:
|
||||||
|
- id: pretty-format-ini
|
||||||
|
args: [--autofix]
|
||||||
|
- id: pretty-format-toml
|
||||||
|
args: [--autofix]
|
||||||
- id: pretty-format-yaml
|
- id: pretty-format-yaml
|
||||||
args: [--autofix]
|
args: [--autofix]
|
||||||
|
|
||||||
@@ -29,7 +37,7 @@ repos:
|
|||||||
types_or: [css, javascript]
|
types_or: [css, javascript]
|
||||||
|
|
||||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||||
rev: 0.37.0
|
rev: 0.36.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-renovate
|
- id: check-renovate
|
||||||
- id: check-github-actions
|
- id: check-github-actions
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import {
|
const { validateAuthentication, replacePlaceholders } = require("../index");
|
||||||
validateAuthentication,
|
const fs = require("fs");
|
||||||
replacePlaceholders,
|
const path = require("path");
|
||||||
readReplaceAndWriteFiles,
|
const os = require("os");
|
||||||
readFilesIntoDict,
|
const { glob } = require("glob");
|
||||||
} from "../index.js";
|
|
||||||
import fs from "fs";
|
|
||||||
import path from "path";
|
|
||||||
import os from "os";
|
|
||||||
import { glob } from "glob";
|
|
||||||
|
|
||||||
describe("validateAuthentication", () => {
|
describe("validateAuthentication", () => {
|
||||||
it("should return null when only token is provided", () => {
|
it("should return null when only token is provided", () => {
|
||||||
@@ -72,83 +67,6 @@ describe("replacePlaceholders", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("readReplaceAndWriteFiles", () => {
|
|
||||||
let tempDir;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tempDir = await fs.promises.mkdtemp(
|
|
||||||
path.join(os.tmpdir(), "replace-test-"),
|
|
||||||
);
|
|
||||||
process.env.GITHUB_SHA = "test-sha";
|
|
||||||
process.env.GITHUB_REF = "test-ref";
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
if (tempDir) {
|
|
||||||
await fs.promises.rm(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should find files and replace placeholders", async () => {
|
|
||||||
const fileName = "test.js";
|
|
||||||
const filePath = path.join(tempDir, fileName);
|
|
||||||
const content = "hash: {{gitHash}}, ref: {{gitRef}}, host: {{hostname}}";
|
|
||||||
await fs.promises.writeFile(filePath, content);
|
|
||||||
|
|
||||||
const pattern = "*.js";
|
|
||||||
// We pass tempDir as the prefix so glob searches inside it
|
|
||||||
await readReplaceAndWriteFiles(pattern, tempDir, "test-host");
|
|
||||||
|
|
||||||
const updatedContent = await fs.promises.readFile(filePath, "utf8");
|
|
||||||
|
|
||||||
expect(updatedContent).toContain("hash: test-sha");
|
|
||||||
expect(updatedContent).toContain("ref: test-ref");
|
|
||||||
expect(updatedContent).toContain("host: test-host");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("readFilesIntoDict", () => {
|
|
||||||
let tempDir;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "read-test-"));
|
|
||||||
await fs.promises.mkdir(path.join(tempDir, "subdir"), { recursive: true });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
if (tempDir) {
|
|
||||||
await fs.promises.rm(tempDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should read files into a dictionary with correct keys", async () => {
|
|
||||||
const file1 = "file1.js";
|
|
||||||
const content1 = "content1";
|
|
||||||
await fs.promises.writeFile(path.join(tempDir, file1), content1);
|
|
||||||
|
|
||||||
const file2 = "subdir/file2.js";
|
|
||||||
const content2 = "content2";
|
|
||||||
await fs.promises.writeFile(path.join(tempDir, file2), content2);
|
|
||||||
|
|
||||||
const pattern = "**/*.js";
|
|
||||||
const result = await readFilesIntoDict(pattern, tempDir);
|
|
||||||
|
|
||||||
// Keys should be relative paths without extension
|
|
||||||
// On Windows, the path separator might differ, so we should be careful or just check contents
|
|
||||||
|
|
||||||
// Based on implementation:
|
|
||||||
// key = key.slice(prefix.length);
|
|
||||||
// key = path.basename(key, path.extname(key)); // Drop the file suffix -> THIS IS BUGGY for subdirs?
|
|
||||||
|
|
||||||
// Let's check the implementation of readFilesIntoDict again in index.js
|
|
||||||
// It does: key = path.basename(key, path.extname(key));
|
|
||||||
// This removes the directory part! So subdir/file2.js becomes file2
|
|
||||||
|
|
||||||
expect(result["file1"]).toBe(content1);
|
|
||||||
expect(result["file2"]).toBe(content2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("glob functionality", () => {
|
describe("glob functionality", () => {
|
||||||
let tempDir;
|
let tempDir;
|
||||||
|
|
||||||
|
|||||||
56805
dist/index.js
vendored
56805
dist/index.js
vendored
File diff suppressed because one or more lines are too long
3
dist/package.json
vendored
3
dist/package.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "module"
|
|
||||||
}
|
|
||||||
30
index.js
30
index.js
@@ -1,9 +1,8 @@
|
|||||||
import { ScreepsAPI } from "screeps-api";
|
const { ScreepsAPI } = require("screeps-api");
|
||||||
import * as core from "@actions/core";
|
const core = require("@actions/core");
|
||||||
import fs from "fs";
|
const fs = require("fs");
|
||||||
import { glob } from "glob";
|
const { glob } = require("glob");
|
||||||
import path from "path";
|
const path = require("path");
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces specific placeholder strings within the provided content with corresponding dynamic values.
|
* 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.
|
* @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.
|
* @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();
|
const deployTime = new Date().toISOString();
|
||||||
return content
|
return content
|
||||||
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
|
.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.
|
* @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.
|
* @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 globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||||
const files = await glob(globPattern);
|
const files = await glob(globPattern);
|
||||||
|
|
||||||
@@ -59,7 +58,7 @@ export async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
|||||||
* @param {string} prefix - Directory prefix for file paths.
|
* @param {string} prefix - Directory prefix for file paths.
|
||||||
* @returns {Promise<Object>} - Promise resolving to a dictionary of file contents keyed by filenames.
|
* @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
|
// Prepend the prefix to the glob pattern
|
||||||
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||||
const files = await glob(globPattern);
|
const files = await glob(globPattern);
|
||||||
@@ -89,7 +88,7 @@ export async function readFilesIntoDict(pattern, prefix) {
|
|||||||
* @param {string} password - The password.
|
* @param {string} password - The password.
|
||||||
* @returns {string|null} - Returns an error message if validation fails, otherwise null.
|
* @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 (token) {
|
||||||
if (username || password) {
|
if (username || password) {
|
||||||
return "Token is defined along with username and/or 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.
|
* Posts code to Screeps server.
|
||||||
*/
|
*/
|
||||||
export async function postCode() {
|
async function postCode() {
|
||||||
const protocol = core.getInput("protocol") || "https";
|
const protocol = core.getInput("protocol") || "https";
|
||||||
const hostname = core.getInput("hostname") || "screeps.com";
|
const hostname = core.getInput("hostname") || "screeps.com";
|
||||||
const port = core.getInput("port") || "443";
|
const port = core.getInput("port") || "443";
|
||||||
@@ -175,8 +174,9 @@ export async function postCode() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
postCode();
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
module.exports = {
|
||||||
if (process.argv[1] === __filename) {
|
validateAuthentication,
|
||||||
postCode();
|
replacePlaceholders,
|
||||||
}
|
};
|
||||||
|
|||||||
871
package-lock.json
generated
871
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,16 +2,15 @@
|
|||||||
"name": "screeps-deploy-action",
|
"name": "screeps-deploy-action",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"description": "Deploys screeps code to the official game or an pirvate server.",
|
"description": "Deploys screeps code to the official game or an pirvate server.",
|
||||||
"type": "module",
|
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"test": "vitest run --globals --coverage",
|
"test": "vitest run --globals --coverage",
|
||||||
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
|
"build": "ncc build index.js -o dist --external utf-8-validate --external bufferutil"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^3.0.0",
|
"@actions/core": "^1.11.1",
|
||||||
"glob": "^13.0.0",
|
"glob": "^11.0.1",
|
||||||
"screeps-api": "^1.7.2"
|
"screeps-api": "^1.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user