Skip to content

DO_NOT_MERGE: test

DO_NOT_MERGE: test #40

Workflow file for this run

name: Coverage
permissions:
contents: write
pull-requests: write
on:
push:
branches:
- main
pull_request:
jobs:
Linux:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['8.3']
type: ['cli', 'zts']
distro: ['bookworm']
outputs:
matrix: ${{ toJson(matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: "arm64,s390x"
- name: Setup buildx
uses: docker/setup-buildx-action@v3
- name: Build container
run: |
docker compose build --pull --no-cache --build-arg PLATFORM="linux/amd64" --build-arg IMAGE="php" --build-arg TAG="${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }}"
- name: Test with gcov
run: |
docker compose run -v "$(pwd)/ext:/ext" --rm shell /bin/sh -c 'pskel test gcov && lcov --capture --directory "/ext" --output-file "/ext/lcov.info" --exclude "/usr/local/include/*" --exclude "third_party/*" && lcov --list "/ext/lcov.info"'
- name: Upload coverage to artifact
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }}
path: ${{ github.workspace }}/ext/lcov.info
Coverage:
needs: [Linux]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download coverage artifacts
uses: actions/download-artifact@v4
- name: Merge coverages
run: |
sudo apt-get install -y "lcov"
LCOV_FILES="$(find . -name "lcov.info")"
CMD="$(which "lcov")"
for LCOV_FILE in ${LCOV_FILES}; do
CMD+=" -a ${LCOV_FILE}"
done
CMD+=" -o lcov.info"
echo "Merging coverages: ${LCOV_FILES}"
${CMD}
- name: Report coverage
uses: k1LoW/octocov-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
config: .github/octocov.yml
- name: Upload coverage to artifact
uses: actions/upload-artifact@v4
with:
name: coverage-unified
path: ${{ github.workspace }}/lcov.info
PullRequestComment:
needs: [Coverage]
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- 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://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://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