Skip to content

Backend testing updates #39

Backend testing updates

Backend testing updates #39

name: Codecov Coverage
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
Frontend-Codecov-Publishing:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v2
# Setup Node environment
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
# Restore dependencies
- name: Install dependencies
run: npm install
working-directory: ./frontend
# Build the project
- name: Build
run: npm run build
working-directory: ./frontend
# Step 5: Run tests and collect code coverage
- name: Test and calculate coverage
run: npm run test:coverage
working-directory: ./frontend
# Step 6: Upload the code coverage report to Codecov
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
# files: ./frontend/coverage/lcov.info, ./ManualCoverageBackend.cobertura.xml
flags: frontend
fail_ci_if_error: true
Backend-Codecov-Publishing:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v2
# Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
# Restore dependencies
- name: Restore dependencies
run: dotnet restore
working-directory: ./backend
# Build the backend
- name: Build the project
run: dotnet build --no-restore --configuration Release
working-directory: ./backend
- name: Start database container
run: docker compose up -d mysql
- name: List running containers
run: docker ps -a
- name: Wait for database to be ready
run: |
for i in {1..30}; do
if docker exec $(docker ps -q --filter "name=mysql") mysqladmin ping -h"localhost" --silent; then
echo "Database is ready!"
sleep 10
exit 0
fi
echo "Waiting for database connection..."
sleep 2
done
echo "Database failed to start within the expected time."
exit 1
# Run tests and generate coverage report
- name: Run tests and generate coverage
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage"
working-directory: ./backend
# Find the coverage file using regex
- name: Locate coverage file
id: coverage-path
run: |
COVERAGE_PATH=$(find ./backend/TestResults -regextype posix-extended -regex ".*cobertura.*\cobertura.xml" -print -quit)
echo "COVERAGE_PATH=$COVERAGE_PATH" >> $GITHUB_ENV
# Upload backend coverage to Codecov
- name: Upload backend coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{ env.COVERAGE_PATH }}
flags: backend
fail_ci_if_error: true
- name: Stop and remove database container
run: docker compose down