Skip to content

Commit 7874a16

Browse files
author
Greg Bowler
authored
Ci improvements for QA and Matrix builds (#40)
* test: implement unit tests * refactor: remove unused getClass function * test: upgrade phpunit * test: upgrade phpunit * ci: improve QA tooling * docs: update example * docs: update badges
1 parent b98f170 commit 7874a16

File tree

9 files changed

+1478
-326
lines changed

9 files changed

+1478
-326
lines changed

.github/workflows/ci.yml

Lines changed: 113 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on: [push]
55
jobs:
66
composer:
77
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
php: [ 8.0, 8.1, 8.2 ]
811

912
steps:
1013
- uses: actions/checkout@v3
@@ -15,7 +18,10 @@ jobs:
1518
path: /tmp/composer-cache
1619
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
1720

18-
- uses: php-actions/composer@v6
21+
- name: Composer install
22+
uses: php-actions/composer@v6
23+
with:
24+
php_version: ${{ matrix.php }}
1925

2026
- name: Archive build
2127
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./
@@ -26,9 +32,65 @@ jobs:
2632
name: build-artifact
2733
path: /tmp/github-actions
2834

35+
phpunit:
36+
runs-on: ubuntu-latest
37+
needs: [ composer ]
38+
strategy:
39+
matrix:
40+
php: [ 8.0, 8.1, 8.2 ]
41+
42+
outputs:
43+
coverage: ${{ steps.store-coverage.outputs.coverage_text }}
44+
45+
steps:
46+
- uses: actions/download-artifact@v3
47+
with:
48+
name: build-artifact
49+
path: /tmp/github-actions
50+
51+
- name: Extract build archive
52+
run: tar -xvf /tmp/github-actions/build.tar ./
53+
54+
- name: PHP Unit tests
55+
uses: php-actions/phpunit@v3
56+
env:
57+
XDEBUG_MODE: cover
58+
with:
59+
php_version: ${{ matrix.php }}
60+
php_extensions: xdebug
61+
coverage_text: _coverage/coverage.txt
62+
coverage_clover: _coverage/clover.xml
63+
64+
- name: Store coverage data
65+
uses: actions/upload-artifact@v3
66+
with:
67+
name: code-coverage
68+
path: _coverage
69+
70+
coverage:
71+
runs-on: ubuntu-latest
72+
needs: [ phpunit ]
73+
74+
steps:
75+
- uses: actions/checkout@v3
76+
77+
- uses: actions/download-artifact@v3
78+
with:
79+
name: code-coverage
80+
path: _coverage
81+
82+
- name: Output coverage
83+
run: cat "_coverage/coverage.txt"
84+
85+
- name: Upload to Codecov
86+
uses: codecov/codecov-action@v3
87+
2988
phpstan:
3089
runs-on: ubuntu-latest
31-
needs: [composer]
90+
needs: [ composer ]
91+
strategy:
92+
matrix:
93+
php: [ 8.0, 8.1, 8.2 ]
3294

3395
steps:
3496
- uses: actions/download-artifact@v3
@@ -42,11 +104,15 @@ jobs:
42104
- name: PHP Static Analysis
43105
uses: php-actions/phpstan@v3
44106
with:
107+
php_version: ${{ matrix.php }}
45108
path: src/
46109

47-
phpunit:
110+
phpmd:
48111
runs-on: ubuntu-latest
49112
needs: [ composer ]
113+
strategy:
114+
matrix:
115+
php: [ 8.0, 8.1, 8.2 ]
50116

51117
steps:
52118
- uses: actions/download-artifact@v3
@@ -57,10 +123,48 @@ jobs:
57123
- name: Extract build archive
58124
run: tar -xvf /tmp/github-actions/build.tar ./
59125

60-
- name: PHP Unit tests
61-
uses: php-actions/phpunit@v3
126+
- name: PHP Mess Detector
127+
uses: php-actions/phpmd@v1
62128
with:
63-
php_version: '8.1'
64-
php_extensions: xdebug
65-
configuration: test/phpunit/phpunit.xml
66-
bootstrap: vendor/autoload.php
129+
php_version: ${{ matrix.php }}
130+
path: src/
131+
output: text
132+
ruleset: phpmd.xml
133+
134+
phpcs:
135+
runs-on: ubuntu-latest
136+
needs: [ composer ]
137+
strategy:
138+
matrix:
139+
php: [ 8.0, 8.1, 8.2 ]
140+
141+
steps:
142+
- uses: actions/download-artifact@v3
143+
with:
144+
name: build-artifact
145+
path: /tmp/github-actions
146+
147+
- name: Extract build archive
148+
run: tar -xvf /tmp/github-actions/build.tar ./
149+
150+
- name: PHP Code Sniffer
151+
uses: php-actions/phpcs@v1
152+
with:
153+
php_version: ${{ matrix.php }}
154+
path: src/
155+
standard: phpcs.xml
156+
157+
remove_old_artifacts:
158+
runs-on: ubuntu-latest
159+
160+
steps:
161+
- name: Remove old artifacts for prior workflow runs on this repository
162+
env:
163+
GH_TOKEN: ${{ github.token }}
164+
run: |
165+
gh api "/repos/${{ github.repository }}/actions/artifacts?name=build-artifact" | jq ".artifacts[] | select(.name == \"build-artifact\") | .id" > artifact-id-list.txt
166+
while read id
167+
do
168+
echo -n "Deleting artifact ID $id ... "
169+
gh api --method DELETE /repos/${{ github.repository }}/actions/artifacts/$id && echo "Done"
170+
done <artifact-id-list.txt

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ Throughout PHP.Gt repositories, wherever an object represents enclosed data, a c
88
<a href="https://github.com/PhpGt/TypeSafeGetter/actions" target="_blank">
99
<img src="https://badge.status.php.gt/typesafegetter-build.svg" alt="Build status" />
1010
</a>
11-
<a href="https://scrutinizer-ci.com/g/PhpGt/TypeSafeGetter" target="_blank">
11+
<a href="https://app.codacy.com/gh/PhpGt/Curl" target="_blank">
1212
<img src="https://badge.status.php.gt/typesafegetter-quality.svg" alt="Code quality" />
1313
</a>
14+
<a href="https://app.codecov.io/gh/PhpGt/TypeSafeGetter" target="_blank">
15+
<img src="https://badge.status.php.gt/typesafegetter-coverage.svg" alt="Code coverage" />
16+
</a>
1417
<a href="https://packagist.org/packages/PhpGt/TypeSafeGetter" target="_blank">
1518
<img src="https://badge.status.php.gt/typesafegetter-version.svg" alt="Current version" />
1619
</a>
17-
<a href="http://www.php.gt/typesafegetter" target="_blank">
20+
<a href="https://www.php.gt/typesafegetter" target="_blank">
1821
<img src="https://badge.status.php.gt/typesafegetter-docs.svg" alt="PHP.Gt/TypeSafeGetter documentation" />
1922
</a>
2023

@@ -26,13 +29,14 @@ The following methods are defined by this interface:
2629
+ `getFloat(string $name):?float`
2730
+ `getBool(string $name):?bool`
2831
+ `getDateTime(string $name):?DateTimeInterface`
32+
+ `getObject(string $name, class-string<T> $className):?T`
2933

3034
Common areas you will see this interface used:
3135

3236
+ Database rows
3337
+ User input (from the query string or posted form data)
3438
+ Session and cookie storage
35-
+ [DataObject](https://github.com/PhpGt/DataObject)
39+
+ PHP.Gt's [DataObject](https://www.php.gt/dataobject) repository.
3640

3741
`NullableTypeSafeGetter` trait
3842
------------------------------

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
},
1010

1111
"require-dev": {
12-
"phpstan/phpstan": "^v1.8",
13-
"phpunit/phpunit": "^v9.5"
12+
"phpstan/phpstan": "^1.10",
13+
"phpunit/phpunit": "^10.1",
14+
"phpmd/phpmd": "^2.13",
15+
"squizlabs/php_codesniffer": "^3.7"
1416
},
1517

1618
"authors": [

0 commit comments

Comments
 (0)