From 71402f189558b6aaeb11d7541367af282361636d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 16 Aug 2024 17:10:25 +0200 Subject: [PATCH] a --- .../{check-release.yml => check.yml} | 8 +++--- .github/workflows/test.yml | 26 +++++++++++++++++++ .test/minetest.conf | 2 ++ .test/run.sh | 24 +++++++++++++++++ mesecons/init.lua | 8 ++++++ 5 files changed, 64 insertions(+), 4 deletions(-) rename .github/workflows/{check-release.yml => check.yml} (94%) create mode 100644 .github/workflows/test.yml create mode 100644 .test/minetest.conf create mode 100644 .test/run.sh diff --git a/.github/workflows/check-release.yml b/.github/workflows/check.yml similarity index 94% rename from .github/workflows/check-release.yml rename to .github/workflows/check.yml index 616adb36..33533253 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check.yml @@ -1,10 +1,10 @@ on: [push, pull_request] -name: Check & Release +name: "Check" jobs: lint: runs-on: ubuntu-latest - + name: "Luacheck" steps: - uses: actions/checkout@main - name: apt @@ -14,9 +14,9 @@ jobs: - name: luacheck run run: $HOME/.luarocks/bin/luacheck ./ - test: + mineunit: runs-on: ubuntu-latest - + name: "Mineunit tests" steps: - uses: actions/checkout@main - name: apt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..d1e76e60 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +on: [push, pull_request] +name: "Test" + +jobs: + test: + name: "Smoke Test ${{ matrix.cfg.image }}" + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + matrix: + cfg: + - { image: 'registry.gitlab.com/minetest/minetest/server:5.0.1', mtg: false } + - { image: '', mtg: true } # latest mater + steps: + - uses: actions/checkout@main + + - uses: actions/checkout@main + with: + repository: 'minetest/minetest_game' + path: minetest_game + if: ${{ matrix.cfg.mtg }} + + - name: Run tests + run: ./.test/run.sh + env: + DOCKER_IMAGE: "${{ matrix.cfg.image }}" diff --git a/.test/minetest.conf b/.test/minetest.conf new file mode 100644 index 00000000..063b6db9 --- /dev/null +++ b/.test/minetest.conf @@ -0,0 +1,2 @@ +mg_name = singlenode +mesecons.internal_test = true diff --git a/.test/run.sh b/.test/run.sh new file mode 100644 index 00000000..55c02668 --- /dev/null +++ b/.test/run.sh @@ -0,0 +1,24 @@ +#!/bin/bash +tempdir=$(mktemp -d) +trap 'rm -rf "$tempdir"' EXIT + +[ -f mesecons/mod.conf ] || { echo "Must be run in modpack root folder." >&2; exit 1; } + +command -v docker >/dev/null || { echo "Docker is not installed." >&2; exit 1; } +[ -d minetest_game ] || echo "A source checkout of minetest_game was not found. This can fail if your docker image does not ship a game." >&2 + +cp -v .test/minetest.conf "$tempdir/" +chmod -R 777 "$tempdir" + +[ -z "$DOCKER_IMAGE" ] && DOCKER_IMAGE="ghcr.io/minetest/minetest:master" +vol=( + -v "$tempdir/minetest.conf":/etc/minetest/minetest.conf + -v "$tempdir":/var/lib/minetest/.minetest + -v "$PWD":/var/lib/minetest/.minetest/world/worldmods/mesecons +) +[ -d minetest_game ] && vol+=( + -v "$PWD/minetest_game":/var/lib/minetest/.minetest/games/minetest_game +) +docker run --rm -i "${vol[@]}" "$DOCKER_IMAGE" + +exit 0 diff --git a/mesecons/init.lua b/mesecons/init.lua index 3446004a..9a45a407 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -123,3 +123,11 @@ dofile(minetest.get_modpath("mesecons").."/legacy.lua"); --Services like turnoff receptor on dignode and so on dofile(minetest.get_modpath("mesecons").."/services.lua"); + +-- Automated test run +if mesecon.setting("internal_test", false) then + -- currently does nothing, we only fail if some error happens right on startup + minetest.after(5, function() + minetest.request_shutdown() + end) +end