From 08268ced16e1fd058a5f729a60d84173d6e48577 Mon Sep 17 00:00:00 2001 From: riccardopinosio Date: Fri, 2 Feb 2024 11:57:44 +0100 Subject: [PATCH] more work --- .ci/docker-compose.yaml | 13 +++++++++++++ .github/workflows/release.yaml | 10 ++++++++-- .github/workflows/test.yaml | 16 ++++++++++++++++ Dockerfile | 2 ++ scripts/run-unit-tests-container.sh | 2 +- scripts/run-unit-tests.sh | 25 +++++++++++-------------- 6 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 .ci/docker-compose.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.ci/docker-compose.yaml b/.ci/docker-compose.yaml new file mode 100644 index 0000000..f788215 --- /dev/null +++ b/.ci/docker-compose.yaml @@ -0,0 +1,13 @@ +services: + hugo: + image: hugo:$commit_hash + build: + context: ./.. + dockerfile: ./Dockerfile + volumes: + - $test_folder:/test + - $test_folder/../scripts/run-unit-tests-container.sh:/run-unit-tests-container.sh + environment: + - HOST_UID=$host_uid + - TEST_MODELS_FOLDER=/unittest/models + command: /run-unit-tests-container.sh \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 21eb45a..3826918 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,3 @@ -# https://docs.github.com/en/actions - name: Create release on: @@ -11,6 +9,14 @@ permissions: contents: write jobs: + test: + name: Run test suite + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build and run tests + run: make run-tests release: name: Release pushed tag runs-on: ubuntu-22.04 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..587aa3a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,16 @@ +name: Run tests + +on: workflow_dispatch + +permissions: + contents: write + +jobs: + test: + name: Run test suite + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build and run tests + run: make run-tests \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a97ef97..f182b15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,8 @@ COPY --from=building /usr/lib/libtokenizers.a /usr/lib/libtokenizers.a COPY --from=building /unittest /unittest COPY --from=building /usr/local/bin/test2json /usr/local/bin/test2json COPY --from=building /usr/local/bin/gotestsum /usr/local/bin/gotestsum + +# copy over the test models COPY ./models /unittest/models ENV GOVERSION=$GO_VERSION diff --git a/scripts/run-unit-tests-container.sh b/scripts/run-unit-tests-container.sh index 0e0156d..a1b8587 100755 --- a/scripts/run-unit-tests-container.sh +++ b/scripts/run-unit-tests-container.sh @@ -2,4 +2,4 @@ set -e -gotestsum --raw-command --junitfile "/test/unit/pipelines.xml" -- test2json -t -p pipelines /unittest/pipelines.test -test.v=test2json \ No newline at end of file +gotestsum --raw-command --junitfile "/test/unit/pipelines.xml" --jsonfile "/test/unit/pipelines.json" -- test2json -t -p pipelines /unittest/pipelines.test -test.v=test2json \ No newline at end of file diff --git a/scripts/run-unit-tests.sh b/scripts/run-unit-tests.sh index 588b24c..6311404 100755 --- a/scripts/run-unit-tests.sh +++ b/scripts/run-unit-tests.sh @@ -6,20 +6,17 @@ set -e this_dir="$( cd "$( dirname "$0" )" && pwd )" src_dir="$(realpath "${this_dir}/..")" -commit_hash=$(git rev-parse --short HEAD) -docker build -f ./Dockerfile -t hugo:$commit_hash . +export commit_hash=$(git rev-parse --short HEAD) +export test_folder="$src_dir/testTarget" +mkdir -p $test_folder +export host_uid=$(id -u "$USER") -echo "Running tests for commit hash: $commit_hash" - -mkdir -p $src_dir/testTarget +# build with compose +docker compose -f $src_dir/.ci/docker-compose.yaml build +# (cd $src_dir/.ci && docker compose build) -host_uid=$(id -u "$USER") +echo "Running tests for commit hash: $commit_hash" -docker run \ ---rm \ --e HOST_UID=$host_uid \ --e TEST_MODELS_FOLDER=/unittest/models \ --v "$src_dir/testTarget:/test" \ --v "$this_dir/run-unit-tests-container.sh:/run-unit-tests-container.sh" \ -"hugo:${commit_hash}" \ -/run-unit-tests-container.sh \ No newline at end of file +docker compose -f $src_dir/.ci/docker-compose.yaml up && \ +docker compose -f $src_dir/.ci/docker-compose.yaml logs --no-color >& $test_folder/logs.txt && \ +docker compose -f $src_dir/.ci/docker-compose.yaml rm -fsv \ No newline at end of file