Compare commits

10 Commits

Author SHA1 Message Date
c05341c0a7 Enable minification for build artifact (#60)
All checks were successful
Lint / pre-commit Linting (push) Successful in 1m29s
Test / Run Tests (push) Successful in 6m9s
### **PR Type**
Enhancement

___

### **Description**
- Enable minification in build script.

- Produce minified `dist/index.js` bundle.

___

<details> <summary><h3> File Walkthrough</h3></summary>

<table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Configuration changes</strong></td><td><table>
<tr>
  <td>
    <details>
      <summary><strong>package.json</strong><dd><code>Add minification flag to build script</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

package.json

- Added `-m` flag to build script.

</details>

  </td>
  <td><a href="https://git.horstenkamp.eu/Screeps/screeps-deploy-action/src/branch/build/minify/package.json">+1/-1</a>&nbsp; &nbsp; &nbsp; </td>

</tr>
</table></td></tr><tr><td><strong>Build artifact</strong></td><td><table>
<tr>
  <td>
    <details>
      <summary><strong>index.js</strong><dd><code>Provide minified distribution bundle</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

dist/index.js

- Updated output to minified bundle.

</details>

  </td>
  <td><a href="https://git.horstenkamp.eu/Screeps/screeps-deploy-action/src/branch/build/minify/dist/index.js">+5/-51912</a></td>

</tr>
</table></td></tr></tr></tbody></table>

</details>

___

Reviewed-on: #60
2026-01-04 07:17:33 +01:00
6a098d425e Enable minification for build artifact (#60)
### **PR Type**
Enhancement

___

### **Description**
- Enable minification in build script.

- Produce minified `dist/index.js` bundle.

___

<details> <summary><h3> File Walkthrough</h3></summary>

<table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Configuration changes</strong></td><td><table>
<tr>
  <td>
    <details>
      <summary><strong>package.json</strong><dd><code>Add minification flag to build script</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

package.json

- Added `-m` flag to build script.

</details>

  </td>
  <td><a href="https://git.horstenkamp.eu/Screeps/screeps-deploy-action/src/branch/build/minify/package.json">+1/-1</a>&nbsp; &nbsp; &nbsp; </td>

</tr>
</table></td></tr><tr><td><strong>Build artifact</strong></td><td><table>
<tr>
  <td>
    <details>
      <summary><strong>index.js</strong><dd><code>Provide minified distribution bundle</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

dist/index.js

- Updated output to minified bundle.

</details>

  </td>
  <td><a href="https://git.horstenkamp.eu/Screeps/screeps-deploy-action/src/branch/build/minify/dist/index.js">+5/-51912</a></td>

</tr>
</table></td></tr></tr></tbody></table>

</details>

___

Reviewed-on: #60
2026-01-04 07:17:05 +01:00
4a77ba188a chore(deps): update dependency node to v24 (#59)
All checks were successful
Lint / pre-commit Linting (push) Successful in 2m38s
Test / Run Tests (push) Successful in 3m24s
Co-authored-by: Renovate Bot <renovate@horstenkamp.eu>
Co-committed-by: Renovate Bot <renovate@horstenkamp.eu>
2026-01-04 07:05:42 +01:00
6c7a0961a7 chore(deps): update actions/setup-node action to v6 (#58)
Some checks failed
Lint / pre-commit Linting (push) Has been cancelled
Test / Run Tests (push) Has been cancelled
Co-authored-by: Renovate Bot <renovate@horstenkamp.eu>
Co-committed-by: Renovate Bot <renovate@horstenkamp.eu>
2026-01-04 07:05:31 +01:00
3ff19001a7 chore: Add a unit testing framework (#49)
Some checks are pending
Lint / pre-commit Linting (push) Waiting to run
Test / Run Tests (push) Successful in 1m12s
Add vitest as a unit testing framework

Reviewed-on: #49
2026-01-04 07:02:20 +01:00
a14206d32c chore: enforce linux line endings (#57)
All checks were successful
Lint / pre-commit Linting (push) Successful in 54s
Add .gitattributes and .editorconfig to enforce LF line endings. Update devcontainer settings.

Reviewed-on: #57
2026-01-03 21:57:34 +01:00
8e305f9126 fix(deps): update dependency glob to v13 (#40)
All checks were successful
Lint / pre-commit Linting (push) Successful in 45s
Co-authored-by: Renovate Bot <renovate@horstenkamp.eu>
Co-committed-by: Renovate Bot <renovate@horstenkamp.eu>
2025-12-31 19:12:17 +01:00
a7552f74fa fix(deps): update dependency @actions/core to v2 (#41)
All checks were successful
Lint / pre-commit Linting (push) Successful in 1m3s
Co-authored-by: Renovate Bot <renovate@horstenkamp.eu>
Co-committed-by: Renovate Bot <renovate@horstenkamp.eu>
2025-12-31 19:05:31 +01:00
3f19a64809 fix: pre-commit hooks should now be installable in dev containers (#56)
All checks were successful
Lint / pre-commit Linting (push) Successful in 51s
Reviewed-on: #56
2025-12-31 18:55:42 +01:00
97ecdcbc66 Exclude the dist forlder from pre-commit (#54)
All checks were successful
Lint / pre-commit Linting (push) Successful in 1m12s
Reviewed-on: #54
2025-12-27 21:10:44 +01:00
16 changed files with 3132 additions and 56923 deletions

View File

@@ -20,7 +20,8 @@
], ],
"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

8
.editorconfig Normal file
View File

@@ -0,0 +1,8 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

1
.gitattributes vendored Normal file
View File

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

View File

@@ -0,0 +1,19 @@
name: Test
on:
push:
workflow_dispatch:
jobs:
test:
name: Run Tests
runs-on: pi
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
- run: npm install
shell: bash
- run: npm test
shell: bash

1078
.gitignore vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
exclude: ^node_modules/ exclude: ^(dist|node_modules)/
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0 rev: v6.0.0

13
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "test",
"group": "test",
"problemMatcher": [],
"label": "npm: test",
"detail": "jest"
}
]
}

View File

@@ -1,79 +1,33 @@
# Gemini Code Assistant Guide: `screeps-deploy-action` # Gemini Actions
This document provides a guide for Large Language Models (LLMs) and developers on understanding and interacting with the `screeps-deploy-action` project. This repository is maintained by Gemini.
## Project Overview ## Development Guidelines
`screeps-deploy-action` is a GitHub Action designed to automate the deployment of JavaScript code to the online programming game Screeps. This project is aimed at supporting both GitHub and Gitea workflows, allowing developers to push their code from a Git repository directly to either the official `screeps.com` server or a private server. It utilizes **Gitea Workflows** (located in `.gitea/workflows`), which are largely compatible with GitHub Actions with minor syntax changes, for its continuous integration and deployment needs. * **Test-Driven Development (TDD):** Wherever possible, Test-Driven Development principles should be followed. Write tests before writing the code they are intended to validate.
* **Pre-commit Hooks:** Ensure that `pre-commit` hooks are installed and active before making any commits. This can be done by running `pre-commit install` in your local repository.
The action's core logic is in `index.js`. It uses the `screeps-api` library to communicate with the Screeps server. The action is configured via a workflow file (e.g., `.github/workflows/main.yml`) using inputs defined in `action.yaml`. ## Repository Comparison
### Key Files * On request, this repository should be compared against the rules and guidelines specified in the `README.md` of the reference repository: `https://git.horstenkamp.eu/Philipp/template-git`.
- **`action.yaml`**: The manifest file for the GitHub Action. It defines the inputs, outputs, and execution environment for the action. ## Testing
- **`index.js`**: The main entry point for the action. It contains the core logic for reading files, connecting to the Screeps API, and uploading the code.
- **`package.json`**: Defines the project's metadata and dependencies. The key dependency is `screeps-api`.
- **`README.md`**: Provides user-facing documentation, including setup and usage examples.
## Core Functionality This project uses [Vitest](https://vitest.dev/) for testing. The tests are located in the `__tests__` directory.
The action performs the following steps: To run the tests locally, use the following command:
1. **Reads Inputs**: It reads the configuration provided by the user in their workflow file. This includes server connection details, authentication credentials, and file paths. ```bash
2. **Authentication**: It authenticates with the Screeps server using either a token or a username/password. npm test
3. **File Processing**:
* It reads all `.js` files from the repository matching the provided `pattern`.
* It can optionally perform placeholder replacements (e.g., `{{gitHash}}`, `{{deployTime}}`) in a specified file (`replace_file`) before deployment.
4. **Code Deployment**: It uploads the processed files to the specified `branch` on the Screeps server.
## Usage
To use this action, a developer would create a `.yml` file in their `.github/workflows` directory.
**Example Workflow:**
```yaml
name: Deploy to Screeps
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to screeps.com
uses: ./
with:
token: ${{ secrets.SCREEPS_TOKEN }}
branch: 'default'
pattern: '*.js'
``` ```
### Configuration Inputs ### Testing Pipeline
The action is configured using the `with` key in the workflow step. The available inputs are defined in `action.yaml`: The tests are automatically run on every push and workflow dispatch using a Gitea workflow. The workflow is defined in `.gitea/workflows/test.yaml`. All testing for this repository is done via Gitea workflows, not GitHub workflows.
- **`token`**: (Required) The authentication token for the Screeps API. It is recommended to store this as a secret. The Gitea workflow does the following:
- **`protocol`**: The server protocol (`http` or `https`). Defaults to `https`.
- **`hostname`**: The server hostname. Defaults to `screeps.com`.
- **`port`**: The server port. Defaults to `443`.
- **`path`**: The server path. Defaults to `/`.
- **`username`**: The Screeps username (used if `token` is not provided).
- **`password`**: The Screeps password (used if `token` is not provided).
- **`branch`**: The in-game branch to deploy the code to. Defaults to `default`.
- **`pattern`**: A glob pattern for the files to deploy. Defaults to `*.js`.
- **`replace_file`**: Path to a file where placeholders like `{{gitHash}}` and `{{deployTime}}` should be replaced.
- **`source_map_path`**: Path to a `main.js.map` file for Source Map support.
## Modifying the Code 1. Checks out the code.
2. Sets up Node.js.
When asked to modify the action's behavior, the primary file to edit will almost always be `index.js`. 3. Installs the dependencies using `npm install`.
4. Runs the tests using `npm test`.
- For changes to the action's inputs or outputs, `action.yaml` must also be updated.
- The core deployment logic is within the `postCode` function in `index.js`.
- File reading is handled by `readFilesIntoDict`.
- Placeholder replacement is handled by `readReplaceAndWriteFiles`.
Before making changes, always review the existing code and the `screeps-api` documentation to understand how it interacts with the Screeps server. After making changes, ensure that any associated tests are updated or added.

199
__tests__/index.test.js Normal file
View File

@@ -0,0 +1,199 @@
const {
validateAuthentication,
replacePlaceholders,
readReplaceAndWriteFiles,
readFilesIntoDict,
} = 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", () => {
expect(validateAuthentication("token", null, null)).toBeNull();
});
it("should return an error message when token and username are provided", () => {
expect(validateAuthentication("token", "user", null)).toBe(
"Token is defined along with username and/or password.",
);
});
it("should return an error message when token and password are provided", () => {
expect(validateAuthentication("token", null, "pass")).toBe(
"Token is defined along with username and/or password.",
);
});
it("should return an error message when token, username, and password are provided", () => {
expect(validateAuthentication("token", "user", "pass")).toBe(
"Token is defined along with username and/or password.",
);
});
it("should return an error message when no credentials are provided", () => {
expect(validateAuthentication(null, null, null)).toBe(
"Neither token nor password and username are defined.",
);
});
it("should return an error message when only username is provided", () => {
expect(validateAuthentication(null, "user", null)).toBe(
"Username is defined but no password is provided.",
);
});
it("should return an error message when only password is provided", () => {
expect(validateAuthentication(null, null, "pass")).toBe(
"Password is defined but no username is provided.",
);
});
it("should return null when username and password are provided", () => {
expect(validateAuthentication(null, "user", "pass")).toBeNull();
});
});
describe("replacePlaceholders", () => {
beforeEach(() => {
process.env.GITHUB_SHA = "test-sha";
process.env.GITHUB_REF = "test-ref";
});
it("should replace all placeholders", () => {
const content =
"hash: {{gitHash}}, ref: {{gitRef}}, time: {{deployTime}}, host: {{hostname}}";
const replacedContent = replacePlaceholders(content, "test-host");
expect(replacedContent).toMatch(/hash: test-sha/);
expect(replacedContent).toMatch(/ref: test-ref/);
expect(replacedContent).toMatch(/time: .*/);
expect(replacedContent).toMatch(/host: test-host/);
});
});
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", () => {
let tempDir;
beforeEach(async () => {
tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "glob-test-"));
await fs.promises.mkdir(path.join(tempDir, "lib"), { recursive: true });
await fs.promises.mkdir(path.join(tempDir, "deep", "folder"), {
recursive: true,
});
await fs.promises.writeFile(path.join(tempDir, "main.js"), "content");
await fs.promises.writeFile(path.join(tempDir, "utils.js"), "content");
await fs.promises.writeFile(
path.join(tempDir, "lib", "helper.js"),
"content",
);
await fs.promises.writeFile(
path.join(tempDir, "lib", "data.json"),
"content",
);
await fs.promises.writeFile(
path.join(tempDir, "deep", "folder", "main.js"),
"content",
);
});
afterEach(async () => {
if (tempDir) {
await fs.promises.rm(tempDir, { recursive: true, force: true });
}
});
it("should find all javascript files in the directory", async () => {
// Ensure pattern uses forward slashes for glob
const pattern = path.join(tempDir, "**", "*.js").split(path.sep).join("/");
const files = await glob(pattern);
// Normalize file paths to system separator (backslashes on Windows)
const normalizedFiles = files.map((f) => path.normalize(f));
const expectedFiles = [
path.join(tempDir, "deep", "folder", "main.js"),
path.join(tempDir, "lib", "helper.js"),
path.join(tempDir, "main.js"),
path.join(tempDir, "utils.js"),
].sort();
expect(normalizedFiles.sort()).toEqual(expectedFiles);
});
});

56822
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

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

View File

@@ -1 +0,0 @@
{"8b776b0173f34b8e7d376c35dbd515022335073f":{"files":{"index.js":["ZVPfPRYPn3JntuOZs2WuhZTA+Pg=",true]},"modified":1766795348715}}

View File

@@ -1 +0,0 @@
{"b03bf7d94b68d6efff8cb09552f1880aa62ea1f0":{"files":{"index.js":["Y4JfDP5X7/wr1mlYLpop4yMG/vA=",true],"dist/index.js":["0uW46uAJG8qyUnSoKEh8QWxHJ4A=",true]},"modified":1766842302598}}

1800
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,17 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "node index.js", "start": "node index.js",
"build": "ncc build index.js -o dist --external utf-8-validate --external bufferutil" "test": "vitest run --globals --coverage",
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^2.0.0",
"glob": "^13.0.0", "glob": "^13.0.0",
"screeps-api": "^1.7.2" "screeps-api": "^1.7.2"
}, },
"devDependencies": { "devDependencies": {
"@vercel/ncc": "^0.38.4" "@vercel/ncc": "^0.38.4",
"@vitest/coverage-v8": "^4.0.16",
"vitest": "^4.0.16"
} }
} }