Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add code coverage INTER-859 #103

Merged
merged 53 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
10de2a5
chore: add code coverage
Orkuncakilkaya Aug 28, 2024
87e0fac
chore(ci): change test branch name for coverage report workflow
Orkuncakilkaya Aug 29, 2024
b421467
chore(coverage): fix php version env
Orkuncakilkaya Aug 29, 2024
3bc4ae7
chore(coverage): implement coverage report with docker
Orkuncakilkaya Aug 30, 2024
4f38f59
chore(coverage): add docker-compose install step
Orkuncakilkaya Aug 30, 2024
9414784
chore(coverage): add env creation step
Orkuncakilkaya Aug 30, 2024
dec411d
chore(template): use parentschema instead of parent for invalid prope…
Orkuncakilkaya Aug 30, 2024
bf03dd2
chore(coverage): add permissions for cov directory
Orkuncakilkaya Aug 30, 2024
dce75b6
chore(coverage-diff): use docker
Orkuncakilkaya Aug 30, 2024
0ad5e24
chore(coverage-diff): test coverage diff
Orkuncakilkaya Aug 30, 2024
c9c75d2
chore(coverage): cleanup branches
Orkuncakilkaya Aug 30, 2024
4876354
docs(readme): update coverage badge link
Orkuncakilkaya Sep 2, 2024
444e1eb
chore(ci): use sha instead of version for 3rd party actions
Orkuncakilkaya Sep 2, 2024
5549a02
chore(ci): try to run coverage result
Orkuncakilkaya Sep 2, 2024
a5cdb1f
chore(coverage-diff): implement custom coverage diff
Orkuncakilkaya Sep 2, 2024
5f72fc0
chore(coverage-diff): update checkout step
Orkuncakilkaya Sep 2, 2024
9190959
chore(coverage-diff): install requirements for base branch phpunit
Orkuncakilkaya Sep 2, 2024
2e1fc62
chore(coverage-diff): update paths for diff check
Orkuncakilkaya Sep 2, 2024
8a753f7
chore(coverage-diff): fix coverage message template
Orkuncakilkaya Sep 2, 2024
1802475
chore(coverage-diff): use awk instead grep for calculating diff
Orkuncakilkaya Sep 2, 2024
2bd23e1
chore(coverage-diff): update base calculation and message body
Orkuncakilkaya Sep 2, 2024
79eb7e0
chore(coverage-diff): update diff calculation
Orkuncakilkaya Sep 2, 2024
c7d0a4d
chore(coverage-diff): fix path for clover destinations
Orkuncakilkaya Sep 2, 2024
3e2b832
chore(coverage-diff): update diff with markdown result
Orkuncakilkaya Sep 2, 2024
4561bdf
refactor: supress warnings for sealed
Orkuncakilkaya Sep 2, 2024
d06c244
Merge branch 'develop' into chore/code-coverage
Orkuncakilkaya Sep 2, 2024
e6d46e0
chore(coverage-diff): update diff base coverage calc and hide files s…
Orkuncakilkaya Sep 2, 2024
ca3cc8c
chore(coverage-diff): use markdown report as artifact
Orkuncakilkaya Sep 2, 2024
b9eb259
chore(coverage-diff): update combining markdown and comment format
Orkuncakilkaya Sep 2, 2024
f6b87e3
chore(coverage-diff): combine message with coverage message
Orkuncakilkaya Sep 2, 2024
5b021e3
chore(coverage-diff): include all php files for coverage
Orkuncakilkaya Sep 2, 2024
0bfb1b1
chore(coverage-diff): remove conditionals from markdown report
Orkuncakilkaya Sep 2, 2024
71953b6
docs(contributing): add coverage report section
Orkuncakilkaya Sep 2, 2024
7d8fed3
docs(contributing): add coverage report html section
Orkuncakilkaya Sep 2, 2024
b5239ef
docs(contributing): fix typos in coverage html section
Orkuncakilkaya Sep 2, 2024
f670f21
chore(coverage-diff): use relative path for coverage files
Orkuncakilkaya Sep 3, 2024
6fcaae0
chore(coverage-diff): use gitkeep instead of using 777 perms
Orkuncakilkaya Sep 3, 2024
3d81684
chore(coverage): coverage inside phpunit xml file
Orkuncakilkaya Sep 3, 2024
0c5e9ac
chore(coverage): update folder permissions
Orkuncakilkaya Sep 3, 2024
e48c72a
chore(coverage-diff): remove git clean
Orkuncakilkaya Sep 3, 2024
b33758a
chore(coverage): update folder permissions
Orkuncakilkaya Sep 3, 2024
8daa056
chore(coverage-diff): prettify overall coverage table
Orkuncakilkaya Sep 3, 2024
630f3ab
chore(coverage-diff): prettify files coverage table
Orkuncakilkaya Sep 3, 2024
78ec433
docs(contributing): add docker section alternative to run php locally
Orkuncakilkaya Sep 3, 2024
c3ef2ad
chore: test coverage report
Orkuncakilkaya Sep 3, 2024
282e40d
chore(coverage-report): update docker user and group
Orkuncakilkaya Sep 3, 2024
51747bd
chore(coverage-badge): format value for badge
Orkuncakilkaya Sep 3, 2024
19caf40
chore(coverage-report): add no jekyll to the exclude list for clean
Orkuncakilkaya Sep 3, 2024
9f4bd04
chore: update sha versions of 3rd party action versions
Orkuncakilkaya Sep 3, 2024
63332de
refactor: rename coverage.php to more explaining name and add comment…
Orkuncakilkaya Sep 3, 2024
edbfd13
chore: cleanup branches for coverage actions
Orkuncakilkaya Sep 3, 2024
8c60356
chore: use v4 instead of v3 for github builtin actions
Orkuncakilkaya Sep 3, 2024
9170f82
chore: add jub summary for coverage diff
Orkuncakilkaya Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/coverage-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: 'coverage-diff'
on:
pull_request:
branches:
- main
- chore/code-coverage # remove this before merge to main
- develop # remove this before merge to main
jobs:
coverage-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231
with:
php-version: 8.2
coverage: none
tools: composer:v2
extensions: xdebug
- name: Install Dependencies
run: composer install -q --profile --ignore-platform-reqs --no-interaction --no-ansi --no-scripts --no-suggest --prefer-dist
- uses: KengoTODA/actions-setup-docker-compose@4677f0d86d41e623c9c6e11e1d910976da297bc0
with:
version: '2.14.2'
- name: Set Permissions for Coverage Directory
run: |
mkdir -p cov/json cov/xml cov/html
chmod -R 777 cov
- name: "Create Empty env File for Docker"
run: touch .env
- name: Clear previous coverage data
run: rm -f cov/xml/clover-pr.xml cov/xml/clover-base.xml cov/xml/clover.xml
- name: PHPUnit for PR
run: docker-compose run phpunit --coverage-clover=cov/xml/clover.xml
- name: Create coverage report for PR
id: pr_coverage
run: |
php ./coverage.php
COVERAGE_PR=$(jq -r '.total.statements.pct' cov/json/index.json)
echo "COVERAGE_PR=$COVERAGE_PR" >> $GITHUB_ENV
- name: Upload coverage report markdown
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-report-md
path: cov/markdown/coverage_report.md

- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}

- uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231
with:
php-version: 8.2
coverage: none
tools: composer:v2
extensions: xdebug
- name: Install Dependencies
run: composer install -q --profile --ignore-platform-reqs --no-interaction --no-ansi --no-scripts --no-suggest --prefer-dist
- uses: KengoTODA/actions-setup-docker-compose@4677f0d86d41e623c9c6e11e1d910976da297bc0
with:
version: '2.14.2'
- name: Set Permissions for Coverage Directory
run: |
mkdir -p cov/json cov/xml cov/html
chmod -R 777 cov
- name: "Create Empty env File for Docker"
run: touch .env
- name: PHPUnit for Base
run: docker-compose run phpunit --coverage-clover=cov/xml/clover.xml
- name: Create coverage report for Base
id: base_coverage
run: |
COVERAGE_BASE=0

if [ -f "./coverage.php" ]; then
php ./coverage.php
fi

if [ -f "cov/json/index.json" ]; then
COVERAGE_BASE=$(jq -r '.total.statements.pct' cov/json/index.json)
fi

echo "COVERAGE_BASE=$COVERAGE_BASE" >> $GITHUB_ENV

- name: Compare coverage
id: compare_coverage
run: |
COVERAGE_DIFF=$(echo "$COVERAGE_PR - $COVERAGE_BASE" | awk '{printf "%.2f", $0}')
echo "Coverage PR: $COVERAGE_PR%"
echo "Coverage Base: $COVERAGE_BASE%"
echo "Coverage Diff: $COVERAGE_DIFF%"

if (( $(echo "$COVERAGE_DIFF > 0" | awk '{print ($0 > 0)}') )); then
COVERAGE_MESSAGE=":green_circle: Coverage increased by $COVERAGE_DIFF%"
elif (( $(echo "$COVERAGE_DIFF < 0" | awk '{print ($0 < 0)}') )); then
COVERAGE_MESSAGE=":red_circle: Coverage decreased by ${COVERAGE_DIFF#-}%"
else
COVERAGE_MESSAGE=":yellow_circle: Coverage remained the same."
fi

echo "COVERAGE_MESSAGE=$COVERAGE_MESSAGE" >> $GITHUB_ENV

- name: Download coverage report markdown
uses: actions/download-artifact@v3
with:
name: coverage-report-md
path: cov/markdown/

- name: Combine Coverage Message and Report
run: |
echo "${COVERAGE_MESSAGE}" > coverage_message.txt
cat cov/markdown/coverage_report.md >> coverage_message.txt
combined_message=$(cat coverage_message.txt)
echo "combined_message<<EOF" >> $GITHUB_ENV
echo "$combined_message" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Add comment with coverage report
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31
with:
message: "${{ env.combined_message }}"
44 changes: 44 additions & 0 deletions .github/workflows/coverage-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'coverage-report'
on:
push:
branches:
- main

permissions:
contents: write
jobs:
coverage-report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231
with:
php-version: 8.2
coverage: none
tools: composer:v2
extensions: xdebug
- name: Install Dependencies
run: composer install -q --profile --ignore-platform-reqs --no-interaction --no-ansi --no-scripts --no-suggest --prefer-dist
- uses: KengoTODA/actions-setup-docker-compose@4677f0d86d41e623c9c6e11e1d910976da297bc0
with:
version: '2.14.2'
- name: Set Permissions for Coverage Directory
run: |
mkdir -p cov/json cov/xml cov/html
chmod -R 777 cov
- name: "Create Empty env File for Docker"
run: touch .env
- name: PHPUnit
run: docker-compose run phpunit --coverage-xml cov/xml --coverage-html cov/html --coverage-clover=cov/xml/clover.xml
- name: "Parse Coverage"
run: "php ./coverage.php"
- name: Create Coverage Badges
uses: jaywcjlove/coverage-badges-cli@e07f25709cd25486855c1ba1b26da53576ff3620
with:
source: cov/json/index.json
output: cov/html/coverage.svg
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@8817a56e5bfec6e2b08345c81f4d422db53a2cdc
with:
branch: gh-pages
folder: cov/html
2 changes: 1 addition & 1 deletion .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231
with:
php-version: "${{ matrix.php_version }}"
coverage: none
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231
with:
php-version: "${{ matrix.php_version }}"
coverage: none
tools: composer:v2
- name: Install Dependencies
run: composer install -q --profile --ignore-platform-reqs --no-interaction --no-ansi --no-scripts --no-suggest --prefer-dist
- uses: php-actions/phpunit@v3
- uses: php-actions/phpunit@aed47a6852905dbd05b7c1a47c526b38fcc4bc17
with:
php_version: "${{ matrix.php_version }}"
bootstrap: vendor/autoload.php
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
.env
release/yarn-error.log
release/node_modules
.php-cs-fixer.cache
.php-cs-fixer.cache
cov/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<p align="center">
<a href="https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/actions/workflows/release.yml"><img src="https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/actions/workflows/release.yml/badge.svg" alt="CI badge" /></a>
<a href="https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/actions/workflows/test.yml"><img src="https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/actions/workflows/test.yml/badge.svg" alt="CI badge" /></a>
<a href="https://fingerprintjs.github.io/fingerprint-pro-server-api-php-sdk"><img src="https://fingerprintjs.github.io/fingerprint-pro-server-api-php-sdk/coverage.svg" alt="Unit Test Coverage" /></a>
<a href="https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/actions/workflows/functional.yml"><img src="https://github.com/fingerprintjs/fingerprint-pro-server-api-php-sdk/actions/workflows/functional.yml/badge.svg" alt="CI badge" /></a>
<a href="https://packagist.org/packages/fingerprint/fingerprint-pro-server-api-sdk"><img src="https://poser.pugx.org/fingerprint/fingerprint-pro-server-api-sdk/v" alt="Latest Stable Version on Packagist"></a>
<a href="https://packagist.org/packages/fingerprint/fingerprint-pro-server-api-sdk"><img src="https://poser.pugx.org/fingerprint/fingerprint-pro-server-api-sdk/require/php?style=flat-square" alt="PHP Version Require"></a>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"ext-openssl": "*"
},
"require-dev": {
"phpunit/phpunit": "8.5.33",
"phpunit/phpunit": "9.3.0",
"vlucas/phpdotenv": "^5.6"
},
"autoload": {
Expand Down
Loading
Loading