-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cSpellChanges
- Loading branch information
Showing
2 changed files
with
187 additions
and
30 deletions.
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
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,42 +1,123 @@ | ||
name: 'coverage-cop' | ||
description: 'CI Check Coverage results of unit tests (using lcov)' | ||
inputs: | ||
path: | ||
coverage-file: | ||
description: 'Path to lcov output file containing coverage data.' | ||
required: true | ||
branch-coverage-min: | ||
description: 'The minumum required branch coverage (in %) for success' | ||
required: false | ||
default: 100 | ||
default: 95 | ||
line-coverage-min: | ||
description: 'The minumum required line coverage (in %) for success' | ||
required: false | ||
default: 100 | ||
default: 95 | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Print coverage data | ||
run: lcov --list --rc lcov_branch_coverage=1 ${{ inputs.path }} | ||
steps: | ||
- env: | ||
stepName: Install Dependencies | ||
bashPass: \033[32;1mPASSED - | ||
bashInfo: \033[33;1mINFO - | ||
bashFail: \033[31;1mFAILED - | ||
bashEnd: \033[0 | ||
shell: bash | ||
- name: Install lcov (if not present) | ||
run: sudo apt-get install lcov | ||
name: ${{ env.stepName }} | ||
run: | | ||
# ${{ env.stepName }} | ||
echo -e "::group::${{ env.stepName }}" | ||
sudo apt-get install lcov fd-find | ||
echo -e "::endgroup::" | ||
echo -e "${{ env.bashPass }} ${{env.stepName }} ${{ env.bashEnd }}" | ||
- env: | ||
stepName: Check Line and Branch Coverage | ||
bashPass: \033[32;1mPASSED - | ||
bashInfo: \033[33;1mINFO - | ||
bashFail: \033[31;1mFAILED - | ||
bashEnd: \033[0 | ||
name: ${{ env.stepName }} | ||
id: action-check-line-and-branch-coverage | ||
shell: bash | ||
- name: Check coverage | ||
run: | | ||
LINE_COVERAGE=$(lcov --list ${{ inputs.path }} | tail -n 1 | cut -d '|' -f 2 | sed -n "s/\([^%]*\)%.*/\1/p") | ||
BRANCH_COVERAGE=$(lcov --rc lcov_branch_coverage=1 --list ${{ inputs.path }} | tail -n 1 | cut -d '|' -f 4 | sed -n "s/\([^%]*\)%.*/\1/p") | ||
# ${{ env.stepName }} | ||
# Print the received code cov report. | ||
# TODO: The way it grabs the line/branch coverage is a little complicated | ||
# I'd like to see if this can be done simpler. | ||
echo -e " ${{ env.bashInfo }} Received LCov Report: ${{ inputs.line-coverage-min }} ${{ env.bashEnd}}" | ||
lcov --list --rc lcov_branch_coverage=1 ${{ inputs.coverage-file }} | ||
LINE_COVERAGE=$(lcov --list ${{ inputs.coverage-file }} | tail -n 1 | cut -d '|' -f 2 | sed -n "s/\([^%]*\)%.*/\1/p") | ||
BRANCH_COVERAGE=$(lcov --rc lcov_branch_coverage=1 --list ${{ inputs.coverage-file }} | tail -n 1 | cut -d '|' -f 4 | sed -n "s/\([^%]*\)%.*/\1/p") | ||
RESULT=0 | ||
echo "Required line coverage: ${{ inputs.line-coverage-min }}" | ||
echo "Line coverage: $LINE_COVERAGE" | ||
# Check Line Coverage | ||
echo -e " ${{ env.bashInfo }} Required Line Coverage: ${{ inputs.line-coverage-min }} ${{ env.bashEnd}}" | ||
echo -e " ${{ env.bashInfo }} Received Line Coverage: $LINE_COVERAGE ${{ env.bashEnd}}" | ||
if [[ $(echo "$LINE_COVERAGE < ${{ inputs.line-coverage-min }}" | bc) -ne 0 ]]; then | ||
echo "Line Coverage is too low." | ||
echo -e "${{ env.bashFail }} Line Coverage is too low. ${{ env.bashEnd }}" | ||
RESULT=1 | ||
fi | ||
echo "Required branch coverage: ${{ inputs.branch-coverage-min }}" | ||
echo "Branch coverage: $BRANCH_COVERAGE" | ||
echo -e " ${{ env.bashInfo }} Required Branch Coverage: ${{ inputs.branch-coverage-min }} ${{ env.bashEnd}}" | ||
echo -e " ${{ env.bashInfo }} Received Branch Coverage: $BRANCH_COVERAGE ${{ env.bashEnd}}" | ||
if [[ $(echo "$BRANCH_COVERAGE < ${{ inputs.branch-coverage-min }}" | bc) -ne 0 ]]; then | ||
echo "Branch Coverage is too low." | ||
echo -e "${{ env.bashFail }} Branch Coverage is too low. ${{ env.bashEnd }}" | ||
RESULT=1 | ||
fi | ||
if [ $RESULT -eq 0 ]; then | ||
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" | ||
else | ||
echo -e "::group::Create Failed Codecov HTML Report" | ||
genhtml --rc lcov_branch_coverage=1 --ignore-errors source ${{ inputs.coverage-file }} --legend --title "$(basename `git rev-parse --show-toplevel`) $(git rev-parse HEAD)" --output-directory=CodecovHTMLReport | ||
zip -r CodecovHTMLReport.zip CodecovHTMLReport | ||
echo -e "::endgroup::" | ||
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}" | ||
fi | ||
exit $RESULT | ||
- name: Upload Failed Codecov HTML Report | ||
if: failure() && ( steps.action-check-line-and-branch-coverage.outcome == 'failure' ) | ||
id: upload-codecov-report | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: CodecovHTMLReport | ||
path: CodecovHTMLReport.zip | ||
retention-days: 5 | ||
|
||
- env: | ||
stepName: Codecov Report Info | ||
bashPass: \033[32;1m | ||
bashInfo: \033[33;1m | ||
bashFail: \033[31;1m | ||
bashEnd: \033[0 | ||
if: failure() && ( steps.upload-codecov-report.outcome == 'success' ) | ||
shell: bash | ||
run: | | ||
# ${{ env.stepName }} | ||
echo -e "${{ env.bashInfo }} A zip file of the failed Codecov report has been attached to this workflow ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} This can be accessed by returning to the bottom of the summary page of the workflow run ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} At the bottom of the page will be a CodecovHTMLReport.zip file that you can download ${{ env.bashEnd }}" | ||
echo -e "${{ env.bashInfo }} Unzip the file and then open the index.html file in your browser for more info missing branch and line coverage ${{ env.bashEnd }}" | ||
exit 1 | ||
# We should use this - it creates a link on their website that you can access | ||
# And it displays the results there, which is great. | ||
# But it means we need to set up a Codecov dashboard for each repo and then | ||
# Add that to a secret to use by default when using it. | ||
# CorePKCS11 evidently has this, but I don't know who set that up or what approvals it took | ||
# So For now I'm going to create the html report and add it to the run. | ||
# More info here: https://about.Codecov.io/blog/how-to-set-up-Codecov-with-c-and-github-actions/ | ||
# - env: | ||
# stepName: Upload Line and Branch Report | ||
# name: ${{ env.stepName }} | ||
# if: failure() | ||
# uses: Codecov/Codecov-action@v3 | ||
# with: | ||
# files: ${{ inputs.coverage-file }} | ||
# flags: unit_tests | ||
# fail_ci_if_error: false | ||
# verbose: false |