Coverage Reports Setup
This project automatically generates HTML coverage reports through GitHub Actions and makes them available in multiple ways.
1. CI Artifacts (Always Available)
Every PR and push to main automatically generates coverage reports as downloadable artifacts:
- Navigate to Actions tab in your GitHub repository
- Click on any workflow run (e.g., “Test” workflow)
- Scroll down to Artifacts section
- Download coverage-report artifact
- Extract the ZIP file and open
coverage.htmlin your browser
2. GitHub Pages Setup (Optional)
To enable automatic deployment of coverage reports to GitHub Pages:
Enable GitHub Pages
- Go to Settings → Pages in your GitHub repository
- Under Source, select GitHub Actions
- The coverage reports will be automatically deployed to:
https://[your-org].github.io/[repo-name]/
Workflow Configuration
The .github/workflows/pages.yml workflow will:
- Run on every push to
mainbranch - Generate fresh coverage reports
- Deploy them to GitHub Pages
- Make them accessible at a public URL
Custom Domain (Optional)
To use a custom domain:
- Add a
CNAMEfile to your repository root with your domain - Configure your DNS to point to GitHub Pages
- Enable HTTPS in repository settings
3. Local Development
Generate coverage reports locally:
# Generate coverage report and open in browser
make coverage
# Or step by step:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
open coverage.html # macOS
xdg-open coverage.html # Linux
start coverage.html # Windows
4. Alternative: AWS S3/CloudFront
If you prefer to host coverage reports on AWS:
- Create an S3 bucket for static hosting
- Modify
.github/workflows/test.ymlto upload to S3:
- name: Deploy to S3
if: matrix.test-type == 'unit' && github.ref == 'refs/heads/main'
run: |
aws s3 cp coverage.html s3://your-coverage-bucket/index.html
aws cloudfront create-invalidation --distribution-id YOUR_DISTRIBUTION_ID --paths "/*"
env:
AWS_ACCESS_KEY_ID: $
AWS_SECRET_ACCESS_KEY: $
Security Considerations
- Public Repositories: Coverage reports will be publicly accessible via GitHub Pages
- Private Repositories: Coverage reports are only accessible to repository collaborators
- Sensitive Data: Ensure no secrets or sensitive file paths are exposed in coverage reports
Troubleshooting
Coverage Reports Not Generating
- Check that tests are running successfully in the “unit” matrix job
- Verify the
coverage.txtfile is being created - Ensure Go toolchain has permission to write files
GitHub Pages Not Updating
- Check the Pages workflow run in Actions tab
- Verify Pages is enabled in repository settings
- Ensure the workflow has proper permissions (
pages: write,id-token: write)
Missing Coverage for Some Files
- Check the
-coverpkgparameter includes your package paths - Verify test files are properly structured and discoverable
- Review the coverage profile with
go tool cover -func=coverage.txt