Skip to content

Commit

Permalink
Merge pull request #103 from fingerprintjs/chore/code-coverage
Browse files Browse the repository at this point in the history
chore: add code coverage INTER-859
  • Loading branch information
Orkuncakilkaya authored Sep 3, 2024
2 parents 0245bfe + 9170f82 commit de25301
Show file tree
Hide file tree
Showing 25 changed files with 1,895 additions and 919 deletions.
118 changes: 118 additions & 0 deletions .github/workflows/coverage-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: 'coverage-diff'
on:
pull_request:

jobs:
coverage-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
clean: false
- 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: "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
- name: Create coverage report for PR
id: pr_coverage
run: |
php ./generate_coverage_report.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@v4
with:
name: coverage-report-md
path: cov/markdown/coverage_report.md

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

- 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: "Create Empty env File for Docker"
run: touch .env
- name: PHPUnit for Base
run: docker-compose run phpunit
- name: Create coverage report for Base
id: base_coverage
run: |
COVERAGE_BASE=0
if [ -f "./generate_coverage_report.php" ]; then
php ./generate_coverage_report.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@v4
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 }}"
- name: Add coverage report to the job summary
run: |
{
echo "${{ env.combined_message }}"
} >> $GITHUB_STEP_SUMMARY
42 changes: 42 additions & 0 deletions .github/workflows/coverage-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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: "Create Empty env File for Docker"
run: touch .env
- name: PHPUnit
run: docker-compose run --user "$(id -u):$(id -g)" phpunit
- name: "Parse Coverage"
run: "php ./generate_coverage_report.php"
- name: Create Coverage Badges
uses: jaywcjlove/coverage-badges-cli@df58615045079f1c827de7867044bbab3ec22b43
with:
source: cov/json/index.json
output: cov/html/coverage.svg
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@920cbb300dcd3f0568dbc42700c61e2fd9e6139c
with:
branch: gh-pages
folder: cov/html
clean-exclude: |
.nojekyll
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
.env
release/yarn-error.log
release/node_modules
.php-cs-fixer.cache
.php-cs-fixer.cache
cov/**/*.*
!cov/**/.gitkeep
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

0 comments on commit de25301

Please sign in to comment.