Skip to content

Commit 1db2198

Browse files
committed
Add GitHub Actions
1 parent 7501cad commit 1db2198

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

.github/workflows/tests.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Run PHPUnit Tests
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: false
17+
18+
jobs:
19+
tests:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Get Composer Cache Directory
26+
id: composer-cache
27+
run: |
28+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
29+
30+
- name: Cache Composer dependencies
31+
uses: actions/cache@v4
32+
with:
33+
path: ${{ steps.composer-cache.outputs.dir }}
34+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-composer-
37+
38+
- name: Install dependencies
39+
uses: php-actions/composer@v6
40+
env:
41+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
42+
with:
43+
php_version: '8.4'
44+
45+
- name: Run PHPUnit tests
46+
uses: php-actions/phpunit@v3
47+
env:
48+
XDEBUG_MODE: coverage
49+
with:
50+
php_version: '8.4'
51+
php_extensions: pcov
52+
53+
- name: Ensure minimum code coverage
54+
env:
55+
MINIMUM_COVERAGE: 80
56+
run: |
57+
COVERAGE=$(php -r '
58+
$xml = new SimpleXMLElement(file_get_contents("public/coverage/clover.xml"));
59+
$m = $xml->project->metrics;
60+
$pct = (int) round(((int) $m["coveredstatements"]) * 100 / (int) $m["statements"]);
61+
echo $pct;
62+
')
63+
echo "Coverage: ${COVERAGE}%"
64+
if [ "${COVERAGE}" -lt ${{ env.MINIMUM_COVERAGE }} ]; then
65+
echo "Code coverage below ${{ env.MINIMUM_COVERAGE }}% threshold."
66+
exit 1
67+
fi
68+
69+
- name: Upload artifact
70+
if: github.ref == 'refs/heads/main'
71+
uses: actions/upload-pages-artifact@v3
72+
with:
73+
path: public/coverage
74+
75+
deploy:
76+
if: github.ref == 'refs/heads/main'
77+
needs: tests
78+
environment:
79+
name: github-pages
80+
url: ${{ steps.deployment.outputs.page_url }}
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: Deploy to GitHub Pages
84+
id: deployment
85+
uses: actions/deploy-pages@v4

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
failOnRisky="true"
1313
failOnWarning="true">
1414
<testsuites>
15-
<testsuite name="Fast Forward Http Factory Test Suite">
15+
<testsuite name="Fast Forward Http Message Test Suite">
1616
<directory>tests</directory>
1717
</testsuite>
1818
</testsuites>

0 commit comments

Comments
 (0)