|
1 | 1 | name: 'coverage-cop'
|
2 | 2 | description: 'CI Check Coverage results of unit tests (using lcov)'
|
3 | 3 | inputs:
|
4 |
| - path: |
| 4 | + coverage-file: |
5 | 5 | description: 'Path to lcov output file containing coverage data.'
|
6 | 6 | required: true
|
7 | 7 | branch-coverage-min:
|
8 | 8 | description: 'The minumum required branch coverage (in %) for success'
|
9 | 9 | required: false
|
10 |
| - default: 100 |
| 10 | + default: 95 |
11 | 11 | line-coverage-min:
|
12 | 12 | description: 'The minumum required line coverage (in %) for success'
|
13 | 13 | required: false
|
14 |
| - default: 100 |
| 14 | + default: 95 |
15 | 15 | runs:
|
16 | 16 | using: "composite"
|
17 |
| - steps: |
18 |
| - - name: Print coverage data |
19 |
| - run: lcov --list --rc lcov_branch_coverage=1 ${{ inputs.path }} |
| 17 | + steps: |
| 18 | + - env: |
| 19 | + stepName: Install Dependencies |
| 20 | + bashPass: \033[32;1mPASSED - |
| 21 | + bashInfo: \033[33;1mINFO - |
| 22 | + bashFail: \033[31;1mFAILED - |
| 23 | + bashEnd: \033[0 |
20 | 24 | shell: bash
|
21 |
| - - name: Install lcov (if not present) |
22 |
| - run: sudo apt-get install lcov |
| 25 | + name: ${{ env.stepName }} |
| 26 | + run: | |
| 27 | + # ${{ env.stepName }} |
| 28 | + echo -e "::group::${{ env.stepName }}" |
| 29 | + sudo apt-get install lcov fd-find |
| 30 | + echo -e "::endgroup::" |
| 31 | + echo -e "${{ env.bashPass }} ${{env.stepName }} ${{ env.bashEnd }}" |
| 32 | +
|
| 33 | + - env: |
| 34 | + stepName: Check Line and Branch Coverage |
| 35 | + bashPass: \033[32;1mPASSED - |
| 36 | + bashInfo: \033[33;1mINFO - |
| 37 | + bashFail: \033[31;1mFAILED - |
| 38 | + bashEnd: \033[0 |
| 39 | + name: ${{ env.stepName }} |
| 40 | + id: action-check-line-and-branch-coverage |
23 | 41 | shell: bash
|
24 |
| - - name: Check coverage |
25 | 42 | run: |
|
26 |
| - LINE_COVERAGE=$(lcov --list ${{ inputs.path }} | tail -n 1 | cut -d '|' -f 2 | sed -n "s/\([^%]*\)%.*/\1/p") |
27 |
| - BRANCH_COVERAGE=$(lcov --rc lcov_branch_coverage=1 --list ${{ inputs.path }} | tail -n 1 | cut -d '|' -f 4 | sed -n "s/\([^%]*\)%.*/\1/p") |
| 43 | + # ${{ env.stepName }} |
| 44 | +
|
| 45 | + # Print the received code cov report. |
| 46 | + # TODO: The way it grabs the line/branch coverage is a little complicated |
| 47 | + # I'd like to see if this can be done simpler. |
| 48 | + echo -e " ${{ env.bashInfo }} Received LCov Report: ${{ inputs.line-coverage-min }} ${{ env.bashEnd}}" |
| 49 | + lcov --list --rc lcov_branch_coverage=1 ${{ inputs.coverage-file }} |
| 50 | + LINE_COVERAGE=$(lcov --list ${{ inputs.coverage-file }} | tail -n 1 | cut -d '|' -f 2 | sed -n "s/\([^%]*\)%.*/\1/p") |
| 51 | + BRANCH_COVERAGE=$(lcov --rc lcov_branch_coverage=1 --list ${{ inputs.coverage-file }} | tail -n 1 | cut -d '|' -f 4 | sed -n "s/\([^%]*\)%.*/\1/p") |
28 | 52 | RESULT=0
|
29 |
| - echo "Required line coverage: ${{ inputs.line-coverage-min }}" |
30 |
| - echo "Line coverage: $LINE_COVERAGE" |
| 53 | +
|
| 54 | + # Check Line Coverage |
| 55 | + echo -e " ${{ env.bashInfo }} Required Line Coverage: ${{ inputs.line-coverage-min }} ${{ env.bashEnd}}" |
| 56 | + echo -e " ${{ env.bashInfo }} Received Line Coverage: $LINE_COVERAGE ${{ env.bashEnd}}" |
31 | 57 | if [[ $(echo "$LINE_COVERAGE < ${{ inputs.line-coverage-min }}" | bc) -ne 0 ]]; then
|
32 |
| - echo "Line Coverage is too low." |
| 58 | + echo -e "${{ env.bashFail }} Line Coverage is too low. ${{ env.bashEnd }}" |
33 | 59 | RESULT=1
|
34 | 60 | fi
|
35 |
| - echo "Required branch coverage: ${{ inputs.branch-coverage-min }}" |
36 |
| - echo "Branch coverage: $BRANCH_COVERAGE" |
| 61 | +
|
| 62 | + echo -e " ${{ env.bashInfo }} Required Branch Coverage: ${{ inputs.branch-coverage-min }} ${{ env.bashEnd}}" |
| 63 | + echo -e " ${{ env.bashInfo }} Received Branch Coverage: $BRANCH_COVERAGE ${{ env.bashEnd}}" |
37 | 64 | if [[ $(echo "$BRANCH_COVERAGE < ${{ inputs.branch-coverage-min }}" | bc) -ne 0 ]]; then
|
38 |
| - echo "Branch Coverage is too low." |
| 65 | + echo -e "${{ env.bashFail }} Branch Coverage is too low. ${{ env.bashEnd }}" |
39 | 66 | RESULT=1
|
40 | 67 | fi
|
| 68 | +
|
| 69 | + if [ $RESULT -eq 0 ]; then |
| 70 | + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" |
| 71 | + else |
| 72 | + echo -e "::group::Create Failed Codecov HTML Report" |
| 73 | + 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 |
| 74 | + zip -r CodecovHTMLReport.zip CodecovHTMLReport |
| 75 | + echo -e "::endgroup::" |
| 76 | + echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}" |
| 77 | + fi |
41 | 78 | exit $RESULT
|
| 79 | +
|
| 80 | + - name: Upload Failed Codecov HTML Report |
| 81 | + if: failure() && ( steps.action-check-line-and-branch-coverage.outcome == 'failure' ) |
| 82 | + id: upload-codecov-report |
| 83 | + uses: actions/upload-artifact@v3 |
| 84 | + with: |
| 85 | + name: CodecovHTMLReport |
| 86 | + path: CodecovHTMLReport.zip |
| 87 | + retention-days: 5 |
| 88 | + |
| 89 | + - env: |
| 90 | + stepName: Codecov Report Info |
| 91 | + bashPass: \033[32;1m |
| 92 | + bashInfo: \033[33;1m |
| 93 | + bashFail: \033[31;1m |
| 94 | + bashEnd: \033[0 |
| 95 | + if: failure() && ( steps.upload-codecov-report.outcome == 'success' ) |
42 | 96 | shell: bash
|
| 97 | + run: | |
| 98 | + # ${{ env.stepName }} |
| 99 | + echo -e "${{ env.bashInfo }} A zip file of the failed Codecov report has been attached to this workflow ${{ env.bashEnd }}" |
| 100 | + echo -e "${{ env.bashInfo }} This can be accessed by returning to the bottom of the summary page of the workflow run ${{ env.bashEnd }}" |
| 101 | + echo -e "${{ env.bashInfo }} At the bottom of the page will be a CodecovHTMLReport.zip file that you can download ${{ env.bashEnd }}" |
| 102 | + 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 }}" |
| 103 | + exit 1 |
| 104 | +
|
| 105 | +
|
| 106 | +
|
| 107 | +# We should use this - it creates a link on their website that you can access |
| 108 | +# And it displays the results there, which is great. |
| 109 | +# But it means we need to set up a Codecov dashboard for each repo and then |
| 110 | +# Add that to a secret to use by default when using it. |
| 111 | +# CorePKCS11 evidently has this, but I don't know who set that up or what approvals it took |
| 112 | +# So For now I'm going to create the html report and add it to the run. |
| 113 | +# More info here: https://about.Codecov.io/blog/how-to-set-up-Codecov-with-c-and-github-actions/ |
| 114 | +# - env: |
| 115 | +# stepName: Upload Line and Branch Report |
| 116 | +# name: ${{ env.stepName }} |
| 117 | +# if: failure() |
| 118 | +# uses: Codecov/Codecov-action@v3 |
| 119 | +# with: |
| 120 | +# files: ${{ inputs.coverage-file }} |
| 121 | +# flags: unit_tests |
| 122 | +# fail_ci_if_error: false |
| 123 | +# verbose: false |
0 commit comments