From cb577b729b1fd437b4b663c27aa88daeaf89e0d4 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Wed, 8 Jul 2026 00:14:28 -0700 Subject: [PATCH] Sync `run-in-docker.sh` from `generic-test-runner`; move `run-in-docker` scripts into `bin/` --- run-in-docker.bat => bin/run-in-docker.bat | 0 bin/run-in-docker.sh | 46 ++++++++++++++++++++++ run-in-docker.sh | 37 ----------------- 3 files changed, 46 insertions(+), 37 deletions(-) rename run-in-docker.bat => bin/run-in-docker.bat (100%) create mode 100755 bin/run-in-docker.sh delete mode 100755 run-in-docker.sh diff --git a/run-in-docker.bat b/bin/run-in-docker.bat similarity index 100% rename from run-in-docker.bat rename to bin/run-in-docker.bat diff --git a/bin/run-in-docker.sh b/bin/run-in-docker.sh new file mode 100755 index 00000000..18c4fa27 --- /dev/null +++ b/bin/run-in-docker.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env sh + +# Synopsis: +# Run the test runner on a solution using the test runner Docker image. +# The test runner Docker image is built automatically. + +# Arguments: +# $1: exercise slug +# $2: path to solution folder +# $3: path to output directory + +# Output: +# Writes the test results to a results.json file in the passed-in output directory. +# The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md + +# Example: +# ./bin/run-in-docker.sh two-fer path/to/solution/folder/ path/to/output/directory/ + +# Stop executing when a command returns a non-zero return code +set -e + +# If any required arguments is missing, print the usage and exit +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then + echo "usage: ./bin/run-in-docker.sh exercise-slug path/to/solution/folder/ path/to/output/directory/" + exit 1 +fi + +slug="$1" +solution_dir=$(realpath "${2%/}") +output_dir=$(realpath "${3%/}") + +# Create the output directory if it doesn't exist +mkdir -p "${output_dir}" + +# Build the Docker image +docker build --rm -t exercism/javascript-test-runner . + +# Run the Docker image using the settings mimicking the production environment +docker run \ + --rm \ + --network none \ + --read-only \ + --mount type=bind,src="${solution_dir}",dst=/solution \ + --mount type=bind,src="${output_dir}",dst=/output \ + --mount type=tmpfs,dst=/tmp \ + exercism/javascript-test-runner "${slug}" /solution /output diff --git a/run-in-docker.sh b/run-in-docker.sh deleted file mode 100755 index 54c9a726..00000000 --- a/run-in-docker.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -# Synopsis: -# Test runner for run.sh in a docker container -# Takes the same arguments as run.sh (EXCEPT THAT SOLUTION AND OUTPUT PATH ARE RELATIVE) -# Builds the Dockerfile -# Runs the docker image passing along the initial arguments - -# Arguments: -# $1: exercise slug -# $2: **RELATIVE** path to solution folder (without trailing slash) -# $3: **RELATIVE** path to output directory (without trailing slash) - -# Output: -# Writes the tests output to the output directory - -# Example: -# ./run-in-docker.sh two-fer ./relative/path/to/two-fer/solution/folder/ ./relative/path/to/output-directory/ -# ./run-in-docker.sh two-fer ./test/fixtures/two-fer/pass ./test/fixtures/two-fer/pass - -# If arguments not provided, print usage and exit -if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "usage: ./run-in-docker.sh two-fer ./relative/path/to/two-fer/solution/folder/ ./relative/path/to/output-directory/" -fi - -# build docker image -docker build -t javascript-test-runner . - -# run image passing the arguments -# --mount type=tmpfs,dst=/tmp \ -docker run \ - --network none \ - --read-only \ - --mount type=bind,src=$PWD/$2,dst=/solution/ \ - --mount type=bind,src=$PWD/$3,dst=/output/ \ - --tmpfs /tmp:exec \ - javascript-test-runner $1 /solution/ /output/