Skip to content

DO_NOT_MERGE: test

DO_NOT_MERGE: test #43

Workflow file for this run

name: Coverage
permissions:
contents: write
pull-requests: write
on:
push:
branches:
- main
pull_request:
jobs:
PullRequestComment:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# - name: Download coverage artifact
# uses: actions/download-artifact@v4
# with:
# name: coverage-unified
- name: Get changed files
uses: tj-actions/changed-files@v45
id: changed-files
- name: Report comment for PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install -g lcov-parse
lcov_data=$(lcov-parse ./lcov.info)
pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
is_line_covered() {
local file=$1
local line=$2
echo "$lcov_data" | jq -e --arg file "$file" --arg line "$line" '.[] | select(.file == $file) | .lines[] | select(.line == ($line | tonumber)) | .hit > 0' > /dev/null
}
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
diff_output=$(git diff origin/${{ github.base_ref }}..HEAD -- "$file")
start_line=""
end_line=""
in_range=false
while IFS= read -r line; do
if [[ $line =~ ^\+([^+].*)$ ]]; then
added_line="${BASH_REMATCH[1]}"
line_number=$(echo "$diff_output" | grep -n "^+$added_line" | cut -d: -f1)
if ! is_line_covered "$file" "$line_number"; then
if [ "$in_range" = false ]; then
start_line=$line_number
in_range=true
fi
end_line=$line_number
else
if [ "$in_range" = true ]; then
comment="Uncovered lines in file $file:$start_line-$end_line"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/comments" \
-d "{\"body\":\"$comment\",\"commit_id\":\"${{ github.event.pull_request.head.sha }}\",\"path\":\"$file\",\"start_line\":$start_line,\"line\":$end_line}"
in_range=false
fi
fi
fi
done <<< "$diff_output"
if [ "$in_range" = true ]; then
comment="Uncovered lines in file $file:$start_line-$end_line"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/comments" \
-d "{\"body\":\"$comment\",\"commit_id\":\"${{ github.event.pull_request.head.sha }}\",\"path\":\"$file\",\"start_line\":$start_line,\"line\":$end_line}"
fi
done