Skip to content

fly: switch health checks to /nginx-health and extend grace; use [[vm… #753

fly: switch health checks to /nginx-health and extend grace; use [[vm…

fly: switch health checks to /nginx-health and extend grace; use [[vm… #753

Workflow file for this run

name: pytest
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Test with pytest and generate coverage
run: |
pytest tests/ --cov=anomstack --cov-report=term-missing --cov-report=json
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(python -c "
import json
with open('coverage.json', 'r') as f:
data = json.load(f)
percentage = round(data['totals']['percent_covered'])
print(f'{percentage}')
")
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Coverage: $COVERAGE%"
- name: Determine badge color
id: badge-color
run: |
COVERAGE=${{ steps.coverage.outputs.percentage }}
if [ $COVERAGE -lt 30 ]; then
COLOR="red"
elif [ $COVERAGE -lt 50 ]; then
COLOR="orange"
elif [ $COVERAGE -lt 70 ]; then
COLOR="yellow"
elif [ $COVERAGE -lt 90 ]; then
COLOR="green"
else
COLOR="brightgreen"
fi
echo "color=$COLOR" >> $GITHUB_OUTPUT
echo "Badge color: $COLOR"
- name: Update coverage badge in README
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
COVERAGE=${{ steps.coverage.outputs.percentage }}
COLOR=${{ steps.badge-color.outputs.color }}
# Update main README.md
sed -i "s/Coverage-[0-9]*%25-[a-z]*/Coverage-${COVERAGE}%25-${COLOR}/g" README.md
# Update tests/README.md
sed -i "s/\*\*Coverage:\*\* [0-9]*% overall/\*\*Coverage:\*\* ${COVERAGE}% overall/g" tests/README.md
sed -i "s/achieves \*\*[0-9]*% overall coverage\*\*/achieves \*\*${COVERAGE}% overall coverage\*\*/g" tests/README.md
sed -i "s/maintains \*\*[0-9]*% test coverage\*\*/maintains \*\*${COVERAGE}% test coverage\*\*/g" CONTRIBUTING.md
echo "Updated coverage badge to ${COVERAGE}% with color ${COLOR}"
- name: Commit and push changes
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
if git diff --quiet; then
echo "No changes to commit"
else
git add README.md tests/README.md CONTRIBUTING.md
git commit -m "🔄 Auto-update coverage badge to ${{ steps.coverage.outputs.percentage }}% [skip ci]"
git push
fi
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const coverage = '${{ steps.coverage.outputs.percentage }}';
const color = '${{ steps.badge-color.outputs.color }}';
const comment = `## 📊 Test Coverage Report
**Coverage:** ${coverage}% (${color})
${coverage >= 47 ? '✅ Coverage maintained or improved!' : '⚠️ Coverage decreased from baseline (47%)'}
> 💡 See detailed coverage report in the [tests README](./tests/README.md#coverage-report)
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});