-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Coverage Reports to CI (#1494)
Signed-off-by: Katherine Hough <kmhough@amazon.com>
- Loading branch information
1 parent
3c5e005
commit 7512e45
Showing
7 changed files
with
511 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: "Create Coverage PR Comment" | ||
description: > | ||
Build a markdown comment to be posted to a PR by the "comment_pr" workflow. | ||
If threshold is set, fails the build if the reported coverage does not meet | ||
met expected criteria. | ||
Uploads the created markdown comment and the number of the PR that triggered this action as workflow artifacts. | ||
inputs: | ||
threshold: | ||
description: > | ||
Minimum proportion of modified lines that need to be covered for acceptance or -1 if there is no minimum. | ||
required: false | ||
default: "-1" | ||
report-artifact-prefix: | ||
description: "Prefix of the name of the artifact to be downloaded" | ||
required: false | ||
default: "coverage_report" | ||
comment-artifact-name: | ||
description: "Name of the artifact to be uploaded" | ||
required: false | ||
default: "coverage_comment" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Download report artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.report-artifact-prefix }}_cobertura | ||
- name: Compute changed lines | ||
id: changed_lines | ||
uses: hestonhoffman/changed-lines@v1 | ||
with: | ||
file_filter: ".rs" | ||
- name: Set up python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.13 | ||
- name: Find last nightly run for BASE | ||
shell: bash | ||
run: | | ||
gh run list \ | ||
--commit $BASE_SHA \ | ||
--status "success" \ | ||
--workflow "Nightly Build" \ | ||
--limit 1 \ | ||
--json "databaseId" \ | ||
| jq --raw-output '.[0]["databaseId"]' \ | ||
> base_run_id.txt | ||
echo "BASE_RUN_ID=$(cat base_run_id.txt)" >> $GITHUB_ENV | ||
env: | ||
BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
GH_TOKEN: ${{ github.token }} | ||
- name: Find coverage report for BASE | ||
if: ${{ env.BASE_RUN_ID != 'null' }} | ||
shell: bash | ||
run: | | ||
mkdir -p base_coverage | ||
gh run download $BASE_RUN_ID --name $NAME --dir base_coverage || true | ||
env: | ||
NAME: ${{ inputs.report-artifact-prefix }}_cobertura | ||
GH_TOKEN: ${{ github.token }} | ||
- name: Create result files | ||
shell: bash | ||
run: | | ||
mkdir -p target/coverage/results | ||
echo $ISSUE_NUMBER > target/coverage/results/issue_number.txt | ||
echo $CHANGED_LINES > target/coverage/results/changed_lines.json | ||
python .github/scripts/process_coverage.py \ | ||
cobertura.xml \ | ||
target/coverage/results/changed_lines.json \ | ||
$THRESHOLD \ | ||
$HEAD_SHA \ | ||
$BASE_SHA \ | ||
$(cat report_location.txt) \ | ||
base_coverage/cobertura.xml \ | ||
target/coverage/results | ||
echo "STATUS=$(cat target/coverage/results/status.txt)" >> $GITHUB_ENV | ||
env: | ||
CHANGED_LINES: ${{ steps.changed_lines.outputs.changed_lines }} | ||
THRESHOLD: ${{ inputs.threshold }} | ||
ISSUE_NUMBER: ${{ github.event.number }} | ||
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
- name: Upload results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.comment-artifact-name }} | ||
path: target/coverage/results/ | ||
retention-days: 1 | ||
- name: Check status | ||
if: ${{ env.STATUS == 'FAILED' }} | ||
uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
core.setFailed('Required coverage criteria were not met.') |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: "Create Coverage Reports" | ||
description: > | ||
Searches the directory tree rooted at the current working directory for raw coverage profiles | ||
('.profraw' files). | ||
Builds grcov HTML and cobertura XML coverage reports from the located profiles. | ||
Uploads the built reports as workflow artifacts. | ||
inputs: | ||
retention-days: | ||
description: > | ||
Duration after which the uploaded artifacts will expire in days, or 0 to use the default setting for the | ||
repository. | ||
required: false | ||
default: "0" | ||
artifact-prefix: | ||
description: "Prefix of the name for the artifacts to be uploaded" | ||
required: false | ||
default: "coverage_report" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install LLVM tools | ||
shell: bash | ||
run: rustup component add llvm-tools-preview | ||
- name: Install grcov | ||
shell: bash | ||
run: cargo install grcov | ||
- name: Collect coverage profiles | ||
shell: bash | ||
run: zip -0 raw_cov.zip $(find . -name "*.profraw") -q | ||
# Note: source-based branch coverage is not supported for Rust | ||
# (see http://github.com/rust-lang/rust/issues/79649) | ||
- name: Build coverage report | ||
shell: bash | ||
run: | | ||
mkdir -p ./target/coverage | ||
grcov raw_cov.zip \ | ||
--source-dir . \ | ||
--binary-path ./target/debug/ \ | ||
-t html,cobertura \ | ||
--ignore 'target/debug/*' \ | ||
--ignore '/*' \ | ||
--ignore '*/build.rs' \ | ||
--ignore '*/tests/*' \ | ||
--excl-start '^\#\[cfg\(test\)\]' \ | ||
--excl-stop '^}' \ | ||
--ignore-not-existing \ | ||
-o ./target/coverage/ | ||
- name: Upload HTML coverage report | ||
uses: actions/upload-artifact@v4 | ||
id: upload-artifact | ||
with: | ||
name: ${{ inputs.artifact-prefix }}_html | ||
path: target/coverage/html | ||
retention-days: ${{ inputs.retention-days }} | ||
- name: Create directory for cobertura report | ||
shell: bash | ||
run: | | ||
mkdir -p target/coverage/cobertura | ||
mv target/coverage/cobertura.xml target/coverage/cobertura/ | ||
echo $REPORT_LOCATION > target/coverage/cobertura/report_location.txt | ||
env: | ||
REPORT_LOCATION: ${{ steps.upload-artifact.outputs.artifact-url }} | ||
- name: Upload cobertura coverage report | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.artifact-prefix }}_cobertura | ||
path: target/coverage/cobertura | ||
retention-days: ${{ inputs.retention-days }} |
Oops, something went wrong.