-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: Use codecov for coverage reports #632
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,68 +1,37 @@ | ||
name: Coverage | ||
name: Coverage check | ||
|
||
on: | ||
schedule: | ||
# 04:00 daily | ||
- cron: '0 4 * * *' | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
check-coverage: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
msg: ${{ steps.make_msg.outputs.msg }} | ||
coverage: | ||
runs-on: ${{ matrix.os }}-latest | ||
strategy: | ||
matrix: | ||
os: [ubuntu] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: Install llvm | ||
uses: KyleMayes/install-llvm-action@v1 | ||
- uses: mozilla-actions/[email protected] | ||
- uses: dtolnay/rust-toolchain@nightly | ||
with: | ||
version: "16.0" # should match version used by rustc | ||
- name: Download previous summary | ||
uses: dawidd6/action-download-artifact@v2 | ||
with: | ||
# Downloads the artifact from the most recent successful run | ||
workflow: 'coverage.yml' | ||
name: coverage-summary | ||
- name: Rename file | ||
run: mv coverage-summary.txt coverage-summary-prev.txt | ||
- name: Generate coverage report and summary | ||
env: | ||
RUSTFLAGS: "-C instrument-coverage" | ||
run: | | ||
TGT=`cargo test --tests 2>&1 | grep Running | awk -F'[()]' '{print $2}'` | ||
llvm-profdata merge -sparse default_*.profraw -o hugr.profdata | ||
llvm-cov show --format=html --ignore-filename-regex='/.cargo/registry' --instr-profile=hugr.profdata --output-dir coverage --object ${TGT} | ||
llvm-cov report --ignore-filename-regex='/.cargo/registry' --instr-profile=hugr.profdata --object ${TGT} | grep TOTAL | awk '{print $10}' | tr -dc '[:digit:].' > coverage-summary.txt | ||
- name: Upload full report | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: coverage | ||
path: coverage/ | ||
- name: Upload summary | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: coverage-summary | ||
path: coverage-summary.txt | ||
- name: Compare with previous summary and make message | ||
id: make_msg | ||
components: llvm-tools-preview | ||
- name: Install cargo-llvm-cov | ||
uses: taiki-e/install-action@cargo-llvm-cov | ||
- name: Run tests with coverage instrumentation | ||
run: | | ||
change="`cat coverage-summary-prev.txt`% --> `cat coverage-summary.txt`%" | ||
if (( $(echo "`cat coverage-summary-prev.txt` < `cat coverage-summary.txt` + 0.04" | bc -l) )) | ||
then | ||
echo "msg=Coverage check for hugr shows no regression (${change}). ✅ ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "msg=Coverage check for hugr shows regression (${change}). ❌ ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$GITHUB_OUTPUT" | ||
fi | ||
notify-slack: | ||
needs: check-coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Send notification | ||
uses: slackapi/[email protected] | ||
cargo llvm-cov clean --workspace | ||
cargo llvm-cov --doctests | ||
- name: Generate coverage report | ||
run: cargo llvm-cov report --codecov --output-path coverage.json | ||
- name: Upload coverage to codecov.io | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
channel-id: 'C04SHCL4FKP' | ||
slack-message: ${{ needs.check-coverage.outputs.msg }} | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | ||
|
||
files: coverage.json | ||
name: ${{ matrix.os }} | ||
token: ${{ secrets.CODECOV_TOKEN }} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can still send a notification to slack with the headline number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hoped the slack app would have this option, but I didn't find it.
I brought back the cron job (simplified a bit with cargo-llvm-cov). Instead of storing the full coverage result it now just links to the codecov page.
Unfortunately there is no web view for comparing two commits (that's only on the API), so I just link to the landing page with a trend graph.