diff --git a/.github/workflows/multiarch.yaml b/.github/workflows/multiarch.yaml index 0498255..8cc7c8e 100644 --- a/.github/workflows/multiarch.yaml +++ b/.github/workflows/multiarch.yaml @@ -54,7 +54,11 @@ jobs: id: minetest-version run: | export MINETEST_VERSION="$(echo "${{ matrix.args }}" | grep MINETEST_VERSION | cut -f 2 -d=)" + export MINETEST_GAME_VERSION="$(echo "${{ matrix.args }}" | grep MINETEST_GAME_VERSION | cut -f 2 -d=)" + export IRRLICHT_VERSION="$(echo "${{ matrix.args }}" | grep IRRLICHT_VERSION | cut -f 2 -d=)" echo "version=${MINETEST_VERSION}" >> $GITHUB_OUTPUT + echo "game=${MINETEST_GAME_VERSION}" >> $GITHUB_OUTPUT + echo "irrlicht=${IRRLICHT_VERSION}" >> $GITHUB_OUTPUT - name: Extract metadata (tags, labels) for Docker id: meta @@ -75,6 +79,9 @@ jobs: id: run-test-build shell: bash run: | + MINETEST_VERSION=${{steps.minetest-version.outputs.version}} \ + MINETEST_GAME_VERSION=${{steps.minetest-version.outputs.game}} \ + MINETEST_IRRLICHT_VERSION=${{steps.minetest-version.outputs.irrlicht}} \ ./test/integration-test.sh - name: Set up QEMU for multiarch builds diff --git a/Dockerfile b/Dockerfile index 581520f..8aa3ca5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,6 +84,7 @@ RUN adduser --system --uid 30000 --group --home /var/lib/minetest minetest &&\ # Copy files and folders COPY --from=builder /usr/share/doc/minetest/minetest.conf.example /etc/minetest/minetest.conf COPY --from=builder /usr/share/minetest /usr/share/minetest +COPY --from=builder /usr/src/minetest/games /usr/share/minetest/games COPY --from=builder /usr/bin/minetestserver /usr/bin COPY --from=builder /usr/bin/contentdb /usr/bin COPY --from=builder /opt/luajit/usr/ /usr/ diff --git a/minetest-wrapper.sh b/minetest-wrapper.sh index 3d3de3f..0e2270c 100755 --- a/minetest-wrapper.sh +++ b/minetest-wrapper.sh @@ -8,13 +8,17 @@ while true ; do echo -e "\n\n-- Separator --\n\n" >> "${MINETEST_STDERR_FILE}" minetestserver "$@" RET="$?" + echo "${RET}" > /tmp/status if [ "${NO_LOOP}" == "true" ]; then - echo "Exiting ..." - exit ${RET} + echo "Exiting (${RET})..." + break fi echo "Minetest server crashed! See error logs at debug.txt and ${MINETEST_STDERR_FILE}" echo "Restarting in 10s ..." sleep 10 done -} 2>&1 | tee -a "${MINETEST_STDERR_FILE}" \ No newline at end of file +} 2>&1 | tee -a "${MINETEST_STDERR_FILE}" + +RET="$(cat /tmp/status || echo 0)" +exit "${RET}" \ No newline at end of file diff --git a/test/integration-test.sh b/test/integration-test.sh index cf802ae..aea7902 100755 --- a/test/integration-test.sh +++ b/test/integration-test.sh @@ -2,6 +2,8 @@ set -e set -x +export MINETEST_VERSION MINETEST_GAME_VERSION IRRLICHT_VERSION + BASEDIR="$(readlink -f "$(dirname "$0")/..")" IMG="ghcr.io/ronoaldo/minetestserver:testing" TMPDIR="$(mktemp -d)" @@ -14,6 +16,8 @@ log() { } cleanup() { + RET=$? + log "Exiting with ${RET} status..." if [ "${CLEANUP}" = "true" ]; then log "Removing temporary directory ${TMPDIR}" rm -rvf "${TMPDIR}" @@ -21,13 +25,29 @@ cleanup() { } version_from_workflow() { - # TODO(ronoaldo): proper YAML parser to avoid breaking - grep "$1"= "${BASEDIR}/.github/workflows/multiarch.yaml" | grep -v export | tail -n 1 | cut -f 2 -d= + # If the variable is defined already, use it + if [ "${!1}" != "" ]; then + echo -n "${!1}" + return + fi + # Else, check if the variable can be parsed from YAML, returning the first value + # configured by the workflow file. + yq -r '.jobs["multiarch-build"].strategy.matrix.include[].args' < .github/workflows/multiarch.yaml |\ + grep "$1"= | tail -n 1 | cut -f 2 -d= +} + +install_deps() { + yq --version 2>/dev/null >/dev/null || { + sudo apt-get install -yq yq + } } log "Starting an integration test using IMG=${IMG}" trap 'cleanup' EXIT +log "Installing required dependencies ..." +install_deps + log "Detecting versions from workflow ..." MT="$(version_from_workflow MINETEST_VERSION)" MTG="$(version_from_workflow MINETEST_GAME_VERSION)" @@ -64,6 +84,8 @@ if pushd "${TMPDIR}" ; then -v "$PWD:/server" \ -u 0:0 \ ${TEST_IMG} bash -c 'chown -R minetest /server/data' + + docker run --rm ${TEST_IMG} minetestserver --gameid list # 3. Run the server without the restart loop. # shellcheck disable=2086