diff --git a/.github/workflows/run-backend-tests.yaml b/.github/workflows/run-backend-tests.yaml new file mode 100644 index 0000000000..b0546553e6 --- /dev/null +++ b/.github/workflows/run-backend-tests.yaml @@ -0,0 +1,75 @@ +name: Run backend tests + +on: + workflow_call: + +env: + FORCE_COLOR: 1 + +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@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + key: poetry-venv-${{ runner.os }}-${{ hashFiles('backend/poetry.lock') }} + path: backend/.venv + + - name: Install backend dependencies + 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 diff --git a/.github/workflows/run-ci-cd.yaml b/.github/workflows/run-ci-cd.yaml index a009b65f0e..54d4a3eac0 100644 --- a/.github/workflows/run-ci-cd.yaml +++ b/.github/workflows/run-ci-cd.yaml @@ -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@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.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 run-frontend-unit-tests: name: Run frontend unit tests