Skip to content

Commit

Permalink
Add Docker test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 25, 2024
1 parent 64937ea commit c59e7ed
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,11 @@
name: "Integration test"
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4

- run: ./test/run.sh
3 changes: 3 additions & 0 deletions mods/default/init.lua
Expand Up @@ -1654,3 +1654,6 @@ dofile(modpath .. "/furnace.lua")
dofile(modpath .. "/sao.lua")
dofile(modpath .. "/mapgen_setup.lua")
dofile(modpath .. "/abm.lua")
if minetest.settings:get_bool("minetest_classic_internal_test") then
dofile(modpath .. "/test.lua")
end
43 changes: 43 additions & 0 deletions mods/default/test.lua
@@ -0,0 +1,43 @@
local function wait_map(callback)
local pos = vector.new(5, 30, 5)
for y = 0, 4 do
assert(minetest.forceload_block(
vector.new(pos.x, y*16, pos.z), true, -1
))
end

local function check()
if minetest.get_node(pos).name ~= "ignore" then
return callback(pos)
end
minetest.after(0, check)
end
check()
end

do
local v = minetest.get_version()
minetest.log("action", "Engine version: " .. (v.hash or v.string))
end

minetest.after(0, function()
wait_map(function(pos)
for x = -1, 1 do
for z = -1, 1 do
minetest.add_node(pos:offset(x, 0, z), {name="default:dirt"})
end
end

pos = pos:offset(0, 1, 0)
assert(minetest.add_entity(pos, "default:rat") ~= nil)
assert(minetest.add_entity(pos, "default:oerkki1") ~= nil)
assert(minetest.add_entity(pos, "default:firefly") ~= nil)
assert(default.spawn_mobv2(pos, default.get_mob_dungeon_master()) ~= nil)

minetest.after(2.5, function()
minetest.log("action", "Exiting test run.")
minetest.request_shutdown()
end)
end)
end)

3 changes: 3 additions & 0 deletions test/minetest.conf
@@ -0,0 +1,3 @@
mg_name = v6
minetest_classic_internal_test = true
max_forceloaded_blocks = 500
18 changes: 18 additions & 0 deletions test/run.sh
@@ -0,0 +1,18 @@
#!/bin/bash -e
world=$(mktemp -d)
trap 'rm -rf "$world"' EXIT

[ -f game.conf ] || { echo "Must be run in game root folder." >&2; exit 1; }

cp -v test/world.mt "$world/"
chmod -R a+rwX "$world" # needed because server runs as unprivileged user inside container

[ -z "$DOCKER_IMAGE" ] && DOCKER_IMAGE="ghcr.io/minetest/minetest:master"
docker run --rm -i \
-v "$PWD/test/minetest.conf":/etc/minetest/minetest.conf \
--tmpfs /var/lib/minetest/.minetest \
-v "$PWD":/var/lib/minetest/.minetest/games/minetest_classic \
-v "$world":/var/lib/minetest/.minetest/world \
"$DOCKER_IMAGE"

exit 0
3 changes: 3 additions & 0 deletions test/world.mt
@@ -0,0 +1,3 @@
enable_damage = true
creative_mode = false
gameid = minetest_classic

0 comments on commit c59e7ed

Please sign in to comment.