Skip to content

Keep optional coverage Pages deployment non-blocking #33

Keep optional coverage Pages deployment non-blocking

Keep optional coverage Pages deployment non-blocking #33

name: Tests and Coverage Reports
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write # Needed for badge commit
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
test-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Verify installation
run: |
python -c "import polystore; print(f'polystore {polystore.__version__} installed successfully')"
- name: Run tests with coverage
run: |
mkdir -p site
python -m pytest --cov=polystore \
--cov-report=xml \
--cov-report=html:site/coverage \
-v
- name: Generate coverage badge
run: |
mkdir -p .github/badges
genbadge coverage -i coverage.xml -o .github/badges/coverage.svg -n "coverage report"
- name: Create index.html and README
run: |
# Create index.html for redirection
cat > site/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=./coverage/">
<title>Redirecting to coverage report...</title>
</head>
<body>
<p>Redirecting to coverage report... <a href="./coverage/">Click here if not redirected</a></p>
</body>
</html>
EOF
# Create README.md in the site directory
cat > site/README.md << 'EOF'
# Polystore Code Coverage Reports
This site contains the code coverage reports for the [Polystore](https://github.com/trissim/polystore) project.
## Navigation
- [Coverage Report](./coverage/): View the HTML coverage report
## About
These reports are automatically generated by GitHub Actions whenever changes are pushed to the main branch.
They show the percentage of code that is covered by automated tests.
Last updated: $(date)
EOF
- name: Commit and push if coverage badge changed
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .github/badges/coverage.svg -f
git commit -m "chore: update coverage badge" || exit 0
git push
- name: Check GitHub Pages status
run: |
echo "⚠️ IMPORTANT: Make sure GitHub Pages is enabled in your repository settings!"
echo "Go to https://github.com/trissim/polystore/settings/pages"
echo "Set 'Source' to 'GitHub Actions' to enable GitHub Pages deployment."
- name: Setup Pages
continue-on-error: true
uses: actions/configure-pages@v4
- name: Upload Pages artifact
continue-on-error: true
uses: actions/upload-pages-artifact@v3
with:
path: 'site'
retention-days: 1
- name: Deploy to GitHub Pages
id: deployment
continue-on-error: true
uses: actions/deploy-pages@v4
timeout-minutes: 10