From ee8c8debf6f50b88b4247d89b31c569d871a2e3b Mon Sep 17 00:00:00 2001 From: Siddhartha Dhiman Date: Mon, 9 Sep 2024 20:42:31 -0400 Subject: [PATCH] Add Docker integrated unit tests --- .github/workflows/pydesigner_ci.yml | 39 +++++++++++++++++++++++++++++ Dockerfile_pytest | 7 ------ tests/Dockerfile | 15 +++++++++++ tests/entrypoint.sh | 9 +++++++ 4 files changed, 63 insertions(+), 7 deletions(-) delete mode 100644 Dockerfile_pytest create mode 100644 tests/Dockerfile create mode 100644 tests/entrypoint.sh diff --git a/.github/workflows/pydesigner_ci.yml b/.github/workflows/pydesigner_ci.yml index e42dba6..e8b55ce 100644 --- a/.github/workflows/pydesigner_ci.yml +++ b/.github/workflows/pydesigner_ci.yml @@ -41,3 +41,42 @@ jobs: - name: Return pre-commit response if: steps.pre-commit.outcome == 'failure' run: exit 1 + + pytest: + needs: pre-commit + runs-on: ubuntu-latest + container: + image: dmri/ci-cd:latest + steps: + - name: Checkout code + id: checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.GH_BRIDGE_PAT }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build Docker image + run: docker build -t pydesigner-test -f tests/Dockerfile . + + - name: Run tests in Docker container + run: docker run --name pydesigner-test + + - name: Copy test results + run: docker cp pydesigner-test:/tests/ ./test-results + + - name: Upload test results + uses: actions/upload-artifact@v4 + with: + name: test-results + path: ./test-results + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: ./test-results/coverage.xml + + - name: Clean up + run: docker rm test-container diff --git a/Dockerfile_pytest b/Dockerfile_pytest deleted file mode 100644 index ab89a68..0000000 --- a/Dockerfile_pytest +++ /dev/null @@ -1,7 +0,0 @@ -FROM dmri/ci-cd:latest as builder - -WORKDIR /scr -COPY . . - -RUN poetry install -ENTRYPOINT ["poetry run pytest"] \ No newline at end of file diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..3866f2f --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,15 @@ +FROM dmri/ci-cd-py3.11:e93dd885 +SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] +WORKDIR /src +COPY . /src +ENV TEST_DIR=/tests + +RUN pip install uv && \ + uv venv ${VIRTUAL_ENV} && \ + uv pip install -U pip setuptools wheel +RUN uv pip install -rrequirements.txt -rrequirements-dev.txt +RUN uv pip install --no-deps -e. +RUN mkdir -p ${TEST_DIR} +COPY ./tests/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh new file mode 100644 index 0000000..dba6f94 --- /dev/null +++ b/tests/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# If no arguments are passed, run pytest with coverage +if [ "$#" -eq 0 ]; then + pytest tests -vv --cov=. --cov-report=xml:/tests/coverage.xml --junitxml=/tests/results.xml +else + # Otherwise, run the command passed as arguments + exec "$@" +fi