-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: CI Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- 'badges/**' # Ignore badge updates to avoid triggering the workflow again | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the code | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
# Set up Python environment | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
# Install dependencies | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest coverage flake8 | ||
# Run flake8 linting | ||
- name: Run linting with flake8 | ||
run: | | ||
flake8 . | ||
# Run pytest and generate coverage report | ||
- name: Run tests and generate coverage | ||
run: | | ||
coverage run --source=. -m pytest tests | ||
coverage report | ||
coverage xml | ||
# Fail if coverage is less than 90% | ||
- name: Check coverage threshold | ||
id: coverage_check | ||
run: | | ||
coverage_percent=$(coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//') | ||
echo "Current coverage: $coverage_percent%" | ||
if (( $(echo "$coverage_percent < 90" | bc -l) )); then | ||
echo "Test coverage is below 90%." | ||
exit 1 | ||
fi | ||
echo "coverage_percent=$coverage_percent" >> $GITHUB_OUTPUT | ||
shell: bash | ||
|
||
# Replace the coverage badge | ||
- name: Generate coverage badge | ||
run: | | ||
wget -O ./badges/coverage.svg "https://img.shields.io/badge/coverage-${{ steps.coverage_check.outputs.coverage_percent }}%25-%23F94526" | ||
# Commit the updated coverage badge to the repo | ||
- name: Commit coverage badge | ||
run: | | ||
git config --global user.name 'GitHub Actions' | ||
git config --global user.email '[email protected]' | ||
git checkout main | ||
git add ./badges/coverage.svg | ||
git commit -m "Update coverage badge" | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |