name: 'coverage-cop' description: 'CI Check Coverage results of unit tests (using lcov)' inputs: path: 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 line-coverage-min: description: 'The minumum required line coverage (in %) for success' required: false default: 100 runs: using: "composite" steps: - name: Print coverage data run: lcov --list --rc lcov_branch_coverage=1 ${{ inputs.path }} shell: bash - name: Install lcov (if not present) run: sudo apt-get install lcov 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") RESULT=0 echo "Required line coverage: ${{ inputs.line-coverage-min }}" echo "Line coverage: $LINE_COVERAGE" if [[ $(echo "$LINE_COVERAGE < ${{ inputs.line-coverage-min }}" | bc) -ne 0 ]]; then echo "Line Coverage is too low." RESULT=1 fi echo "Required branch coverage: ${{ inputs.branch-coverage-min }}" echo "Branch coverage: $BRANCH_COVERAGE" if [[ $(echo "$BRANCH_COVERAGE < ${{ inputs.branch-coverage-min }}" | bc) -ne 0 ]]; then echo "Branch Coverage is too low." RESULT=1 fi exit $RESULT shell: bash