Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tests #54

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/build.yml

This file was deleted.

65 changes: 65 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test server image

on:
workflow_dispatch:

pull_request:
branches:
- "main"

env:
TEST_TAG: jomik/screeps-server:test

jobs:
release:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [10, 12]
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3
- name: Build
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5
with:
context: .
build-args: |
NODE_VERSION=${{ matrix.node }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.TEST_TAG }}
load: true
- name: Start the container
run: |
docker run --rm -di -p 21025:21025 -p 21028:21028 --env STEAM_KEY --name screeps -v ${CONFIG_FILE}:/screeps/config.yml ${TEST_TAG}
env:
STEAM_KEY: ${{ secrets.STEAM_KEY }}
CONFIG_FILE: ${{ format('{0}/{1}', github.workspace, 'test-config.yml') }}
- name: Wait for container to be healthy
uses: stringbean/docker-healthcheck-action@v3
with:
container: screeps
wait-time: 600
require-status: running
require-healthy: true
- name: Show container logs
if: always()
run: docker container logs screeps
- name: Check that mods are registered
run: |
set -eu
server_data=$(curl http://localhost:21025/api/version | jq -c '.serverData')
echo $server_data | jq -e '.features | any(.name == "screepsmod-auth")'
echo $server_data | jq -e '.features | any(.name == "screepsmod-admin-utils")'
echo $server_data | jq -e '.features | any(.name == "screepsmod-cli")'
- name: Check that bots are registered
run: |
set -eu
bots=$(curl -X POST http://localhost:21028/cli -d "help(bots)" | grep -A 10 "Bot AIs:")
echo $bots | grep 'simplebot' | grep "screepsbot-zeswarm"
- name: Stop container
if: always()
run: docker container stop screeps
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ VOLUME [ "/data" ]
EXPOSE 21025

HEALTHCHECK --start-period=5m --interval=5m --timeout=3s \
CMD wget --no-verbose --tries=1 --spider http://localhost:21025/ || exit 1
CMD wget --no-verbose --tries=1 --spider http://localhost:21025/api/version || exit 1

ENTRYPOINT ["start"]
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mods:
bots:
simplebot: screepsbot-zeswarm

serverOptions:
launcherOptions:
# If set, forward console messages to terminal
logConsole: false
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"js-yaml": "4.1.0"
},
"scripts": {
"bootstrap": "mkdir -p server/mods && cd server && cp -a ../node_modules/@screeps/launcher/init_dist/{.screepsrc,db.json,assets} ./ && cd mods && npm init -y",
"clean": "rm -r server && yarn bootstrap",
"start": "CONFIG_FILE=../config.yml SERVER_DIR=./server/ ./screeps-start.js",
"cli": "docker compose exec screeps cli"
}
}
3 changes: 1 addition & 2 deletions screeps-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const RootDir = process.env["SERVER_DIR"];
if (!RootDir) {
throw new Error("Missing environment variable $SERVER_DIR");
}
const ConfigPath = process.env["CONFIG_FILE"] || "./config.yml";

process.chdir(RootDir);

const ConfigPath = path.join(RootDir, "config.yml");
const config = yaml.load(fs.readFileSync(ConfigPath, "utf8"));

const loadPackage = (dir) =>
Expand Down
14 changes: 14 additions & 0 deletions test-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mods:
- screepsmod-auth
- screepsmod-admin-utils
- screepsmod-cli
bots:
simplebot: screepsbot-zeswarm

cli:
host: 0.0.0.0
port: 21028

launcherOptions:
runnerThreads: 1
processorCount: 1