Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/run-backend-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Run backend tests

on:
workflow_call:

env:
FORCE_COLOR: 1

Comment thread
ahmedxgouda marked this conversation as resolved.
permissions: {}

jobs:
run-unit-tests:
name: Run unit tests
permissions:
actions: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Install Poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
cache-dependency-path: backend/poetry.lock
cache: poetry
python-version: '3.13'

- name: Set up backend dependencies cache
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
key: poetry-venv-${{ runner.os }}-${{ hashFiles('backend/poetry.lock') }}
path: backend/.venv

- name: Install backend dependencies
Comment thread
ahmedxgouda marked this conversation as resolved.
run: poetry install --no-interaction
working-directory: backend

- name: Run backend tests
run: set -a && source .env.example && set +a && poetry run pytest tests/unit
working-directory: backend

- name: Upload coverage artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
if-no-files-found: error
name: coverage-xml
path: backend/coverage.xml
timeout-minutes: 5

upload-coverage-to-codecov:
name: Upload coverage to Codecov
needs: run-unit-tests
permissions:
actions: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Download coverage artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: coverage-xml
path: backend

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
fail_ci_if_error: false
files: backend/coverage.xml
flags: backend
use_oidc: true
timeout-minutes: 5
44 changes: 2 additions & 42 deletions .github/workflows/run-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,10 @@ jobs:
needs:
- run-code-quality-checks
permissions:
actions: write
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up Docker buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0

- name: Build backend test image
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
cache-from: |
type=gha
type=registry,ref=owasp/nest:test-backend-cache
cache-to: |
type=gha,compression=zstd
context: backend
file: docker/backend/Dockerfile.test
load: true
platforms: linux/amd64
tags: owasp/nest:test-backend-latest

- name: Run backend tests
run: |
CONTAINER_ID=$(docker create \
-e DJANGO_SETTINGS_MODULE=settings.test \
--env-file backend/.env.example \
owasp/nest:test-backend-latest pytest)
docker start -a $CONTAINER_ID
EXIT_CODE=$?
docker cp $CONTAINER_ID:/home/owasp/coverage.xml backend/coverage.xml 2>/dev/null || true
docker rm $CONTAINER_ID >/dev/null 2>&1
exit $EXIT_CODE

- name: Upload coverage report to Codecov
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
fail_ci_if_error: false
files: backend/coverage.xml
flags: backend
use_oidc: true
timeout-minutes: 5
uses: ./.github/workflows/run-backend-tests.yaml
Comment thread
ahmedxgouda marked this conversation as resolved.

run-frontend-unit-tests:
name: Run frontend unit tests
Expand Down
Loading