add workflow to delete old workflow runs weekly #23
This file contains hidden or 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: Lint and Test Coverage | |
permissions: | |
contents: read | |
pull-requests: write | |
checks: write | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
env: | |
PYTHON_VERSION: '3.10' | |
COVERAGE_THRESHOLD: 95 | |
jobs: | |
lint-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install ruff | |
python -m pip install pytest pytest-cov | |
if [ -f requirements.txt ]; then | |
python -m pip install -r requirements.txt | |
else | |
echo "No requirements.txt found, skipping..." | |
fi | |
- name: Lint with ruff | |
run: | | |
ruff check --config=pyproject.toml --output-format=github . | |
ruff format --check --config=pyproject.toml . | |
- name: Run tests with coverage | |
run: | | |
python -m pytest \ | |
--cov=src/hrt \ | |
--cov-report=html:htmlcov \ | |
--cov-report=term \ | |
--cov-report=json:coverage.json \ | |
--cov-report=xml:coverage.xml \ | |
tests/ | |
- name: Extract coverage percentage | |
id: coverage | |
run: | | |
COVERAGE=$(python -c " | |
import json | |
with open('coverage.json') as f: | |
data = json.load(f) | |
print(f\"{data['totals']['percent_covered']:.0f}\") | |
") | |
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT | |
echo "Coverage: ${COVERAGE}%" | |
- name: Check coverage threshold | |
run: | | |
COVERAGE=${{ steps.coverage.outputs.percentage }} | |
echo "Coverage: ${COVERAGE}%" | |
echo "Required threshold: ${{ env.COVERAGE_THRESHOLD }}%" | |
if [ "$COVERAGE" -lt "${{ env.COVERAGE_THRESHOLD }}" ]; then | |
echo "::error::Test coverage is ${COVERAGE}%, which is below the threshold of ${{ env.COVERAGE_THRESHOLD }}%" | |
exit 1 | |
else | |
echo "::notice::Coverage is ${COVERAGE}%, which meets the threshold of ${{ env.COVERAGE_THRESHOLD }}%" | |
fi | |
- name: Set coverage status | |
id: coverage_status | |
run: | | |
COVERAGE=${{ steps.coverage.outputs.percentage }} | |
if [ "$COVERAGE" -ge "${{ env.COVERAGE_THRESHOLD }}" ]; then | |
echo "status=✅ Passed" >> $GITHUB_OUTPUT | |
else | |
echo "status=❌ Failed" >> $GITHUB_OUTPUT | |
fi | |
- name: Upload coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
file: ./coverage.xml | |
flags: unittests | |
name: codecov-umbrella | |
fail_ci_if_error: false | |
verbose: false | |
override_commit: ${{ github.sha }} | |
- name: Comment coverage on PR | |
if: github.event_name == 'pull_request' | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
message: | | |
## 📊 Test Coverage Report | |
**Coverage:** ${{ steps.coverage.outputs.percentage }}% | |
**Threshold:** ${{ env.COVERAGE_THRESHOLD }}% | |
**Status:** ${{ steps.coverage_status.outputs.status }} |