Skip to content

Commit

Permalink
Add Docker integrated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaeger committed Sep 10, 2024
1 parent 1ff58a1 commit ee8c8de
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/pydesigner_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions Dockerfile_pytest

This file was deleted.

15 changes: 15 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 9 additions & 0 deletions tests/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ee8c8de

Please sign in to comment.