Enhancements: Enhance Tests and Improve CI Workflow #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI - Code Testing Workflow | |
on: | |
pull_request: | |
branches: | |
- develop | |
- main | |
- "feature/*" | |
- "hotfix/*" | |
paths: | |
- "src/**" | |
- "tests/**" | |
push: | |
branches: | |
- main | |
- develop | |
paths: | |
- "src/**" | |
- "tests/**" | |
jobs: | |
test: | |
name: Run Tests and Generate Coverage Report | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.9" | |
# Step 3: Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m venv venv # Create a virtual environment | |
source venv/bin/activate # Activate the virtual environment | |
pip install -r requirements.txt # Install required dependencies | |
pip install pytest pytest-cov # Add coverage tools | |
# Step 4: Run tests with coverage | |
- name: Run tests with coverage | |
run: | | |
source venv/bin/activate # Ensure the virtual environment is active | |
pytest --maxfail=3 --disable-warnings --cov=src --cov-report=xml --cov-report=term | |
# Step 5: Post coverage summary as a PR comment | |
- name: Post coverage summary | |
if: github.event_name == 'pull_request' | |
uses: mikepenz/comment-action@v2 | |
with: | |
message: | | |
## Test Coverage Summary | |
$(cat coverage.xml | sed -n '/<coverage/,/<\/coverage>/p' | sed -e 's/<[^>]*>//g' | head -n 10) |