6 Commits

Author SHA1 Message Date
8ca9c67979 fix(ci): upgrade node to v22 and update docs to reflect vitest usage
Some checks failed
Test / Run Tests (push) Failing after 13m41s
Lint / pre-commit Linting (push) Failing after 14m12s
2025-12-28 04:54:26 +00:00
48f7596789 Merge branch 'main' into add-testing
Some checks failed
Lint / pre-commit Linting (push) Successful in 1m33s
Test / Run Tests (push) Failing after 2m5s
2025-12-28 05:24:28 +01:00
ae87ee6e35 feat: add coverage support for testing and update .gitignore
Some checks failed
Lint / pre-commit Linting (push) Successful in 1m16s
Test / Run Tests (push) Failing after 8m3s
2025-12-27 21:31:19 +00:00
6ff8731e50 chore: remove cached Prettier files from .gitignore
Some checks failed
Lint / pre-commit Linting (push) Successful in 1m12s
Test / Run Tests (push) Failing after 1m41s
2025-12-27 18:57:46 +00:00
b7136de5e2 Merge remote-tracking branch 'origin/main' into add-testing
Some checks failed
Lint / pre-commit Linting (push) Successful in 1m26s
Test / Run Tests (push) Failing after 1m48s
2025-12-27 18:54:57 +00:00
a2b753417a Add testing script and vitest as a dev dependency in package.json
Some checks failed
Lint / pre-commit Linting (push) Successful in 1m52s
Test / Run Tests (push) Failing after 8m40s
2025-12-23 16:42:07 +01:00
12 changed files with 57419 additions and 338 deletions

View File

@@ -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"
} }
} }
}, },

View File

@@ -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

View File

@@ -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
View File

@@ -1 +0,0 @@
* text=auto eol=lf

View File

@@ -10,9 +10,9 @@ jobs:
runs-on: pi runs-on: pi
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions/setup-node@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
View File

@@ -1075,6 +1075,4 @@ FodyWeavers.xsd
*.vsix *.vsix
/node_modules/ /node_modules/
/node_modules/.cache/
/coverage/ /coverage/
!/dist/

View File

@@ -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]

View File

@@ -1,9 +1,4 @@
const { const { validateAuthentication, replacePlaceholders } = require("../index");
validateAuthentication,
replacePlaceholders,
readReplaceAndWriteFiles,
readFilesIntoDict,
} = require("../index");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const os = require("os"); const os = require("os");
@@ -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;

56822
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -174,15 +174,9 @@ async function postCode() {
}); });
} }
} }
postCode();
if (require.main === module) {
postCode();
}
module.exports = { module.exports = {
validateAuthentication, validateAuthentication,
replacePlaceholders, replacePlaceholders,
postCode,
readReplaceAndWriteFiles,
readFilesIntoDict,
}; };

807
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,11 +6,11 @@
"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": "^2.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": {