From 268f2d003ca43be6ee590b001e742cf3f1ee2a1f Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Tue, 21 Apr 2026 20:23:37 +1000 Subject: [PATCH] CI: check exercises against test runner resolves https://github.com/exercism/zig-test-runner/issues/56 --- .github/workflows/test-runner.yml | 18 +++++++++++++++ bin/.test-in-docker | 38 +++++++++++++++++++++++++++++++ bin/test | 27 ++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 .github/workflows/test-runner.yml create mode 100644 bin/.test-in-docker create mode 100755 bin/test diff --git a/.github/workflows/test-runner.yml b/.github/workflows/test-runner.yml new file mode 100644 index 00000000..ceecc050 --- /dev/null +++ b/.github/workflows/test-runner.yml @@ -0,0 +1,18 @@ +name: Track Exercises on Runner + +on: + pull_request: + push: + branches: [main] + workflow_dispatch: + +jobs: + ci: + runs-on: ubuntu-24.04 + + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + - run: docker pull exercism/zig-test-runner + - name: Run tests for all exercises + run: sh ./bin/test diff --git a/bin/.test-in-docker b/bin/.test-in-docker new file mode 100644 index 00000000..bb5c1433 --- /dev/null +++ b/bin/.test-in-docker @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# This script is meant to be run in the docker container of zig-test-runner + +all_slugs="$*" + +exit_code=0 + +for slug in $all_slugs; do + snake="${slug//-/_}" + local_exit_code=0 + + rm -rf /tmp/solution + cp -r "/exercises/practice/${slug}" /tmp/solution + + # Integration test: Check if the example solution passes the tests + # as run by the zig-test-runner similiarly to a student submitting + # their solution. + cp /tmp/solution/.meta/example.zig "/tmp/solution/${snake}.zig" + bin/run.sh "${slug}" /tmp/solution /tmp/solution > /dev/null + solution_pattern=$(cat /tmp/solution/results.json | jq -r tostring | grep "{\"version\":2,\"status\":\"pass\"") + + errors="" + + if [ -z "$solution_pattern" ]; then + errors="${errors}\n\nSolution is incorrect:\n$(cat /tmp/solution/results.json | jq -r '.message')" + local_exit_code=1; + fi + + if [ $local_exit_code = 0 ]; then + echo -e "${slug}: \e[32mPASSED\e[0m" + else + exit_code=1 + echo -e "${slug}: \e[31mFAILED\e[0m\n${errors}\n\n" + fi +done + +exit ${exit_code} diff --git a/bin/test b/bin/test new file mode 100755 index 00000000..ca7ad5d1 --- /dev/null +++ b/bin/test @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Synopsis: +# Test the zig track's exercises. +# +# For each exercise we test if the example solution +# .meta/example.zig passes the tests. +# +# Usage: +# ./bin/test [slug...] + +all_slugs="$*" +if [ -z "$all_slugs" ]; then + all_slugs=$(ls ./exercises/practice/) +fi + +docker run --rm --entrypoint bash \ + --network none \ + --mount type=bind,src="$(realpath ./exercises)",dst=/exercises,ro \ + --mount type=bind,src="$(realpath ./bin)",dst=/scripts,ro \ + --mount type=tmpfs,dst=/tmp \ + exercism/zig-test-runner \ + /scripts/.test-in-docker "$all_slugs" + +exit_code=$? + +exit ${exit_code}