Skip to content

Commit

Permalink
ci: run integration tests on proper versions
Browse files Browse the repository at this point in the history
Before it was running all workflow tests
using the same minetest version.
It is now running the workflow builds on
the proper version parameter.
  • Loading branch information
ronoaldo committed Nov 20, 2023
1 parent 424c5c8 commit 809c9e5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/multiarch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
10 changes: 7 additions & 3 deletions minetest-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
} 2>&1 | tee -a "${MINETEST_STDERR_FILE}"

RET="$(cat /tmp/status || echo 0)"
exit "${RET}"
26 changes: 24 additions & 2 deletions test/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -14,20 +16,38 @@ log() {
}

cleanup() {
RET=$?
log "Exiting with ${RET} status..."
if [ "${CLEANUP}" = "true" ]; then
log "Removing temporary directory ${TMPDIR}"
rm -rvf "${TMPDIR}"
fi
}

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)"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 809c9e5

Please sign in to comment.