Skip to content

Commit

Permalink
Ci improvements for QA and Matrix builds (#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
g105b authored Apr 27, 2023
1 parent b98f170 commit 7874a16
Show file tree
Hide file tree
Showing 9 changed files with 1,478 additions and 326 deletions.
122 changes: 113 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on: [push]
jobs:
composer:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 8.0, 8.1, 8.2 ]

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

- uses: php-actions/composer@v6
- name: Composer install
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php }}

- name: Archive build
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./
Expand All @@ -26,9 +32,65 @@ jobs:
name: build-artifact
path: /tmp/github-actions

phpunit:
runs-on: ubuntu-latest
needs: [ composer ]
strategy:
matrix:
php: [ 8.0, 8.1, 8.2 ]

outputs:
coverage: ${{ steps.store-coverage.outputs.coverage_text }}

steps:
- uses: actions/download-artifact@v3
with:
name: build-artifact
path: /tmp/github-actions

- name: Extract build archive
run: tar -xvf /tmp/github-actions/build.tar ./

- name: PHP Unit tests
uses: php-actions/phpunit@v3
env:
XDEBUG_MODE: cover
with:
php_version: ${{ matrix.php }}
php_extensions: xdebug
coverage_text: _coverage/coverage.txt
coverage_clover: _coverage/clover.xml

- name: Store coverage data
uses: actions/upload-artifact@v3
with:
name: code-coverage
path: _coverage

coverage:
runs-on: ubuntu-latest
needs: [ phpunit ]

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: code-coverage
path: _coverage

- name: Output coverage
run: cat "_coverage/coverage.txt"

- name: Upload to Codecov
uses: codecov/codecov-action@v3

phpstan:
runs-on: ubuntu-latest
needs: [composer]
needs: [ composer ]
strategy:
matrix:
php: [ 8.0, 8.1, 8.2 ]

steps:
- uses: actions/download-artifact@v3
Expand All @@ -42,11 +104,15 @@ jobs:
- name: PHP Static Analysis
uses: php-actions/phpstan@v3
with:
php_version: ${{ matrix.php }}
path: src/

phpunit:
phpmd:
runs-on: ubuntu-latest
needs: [ composer ]
strategy:
matrix:
php: [ 8.0, 8.1, 8.2 ]

steps:
- uses: actions/download-artifact@v3
Expand All @@ -57,10 +123,48 @@ jobs:
- name: Extract build archive
run: tar -xvf /tmp/github-actions/build.tar ./

- name: PHP Unit tests
uses: php-actions/phpunit@v3
- name: PHP Mess Detector
uses: php-actions/phpmd@v1
with:
php_version: '8.1'
php_extensions: xdebug
configuration: test/phpunit/phpunit.xml
bootstrap: vendor/autoload.php
php_version: ${{ matrix.php }}
path: src/
output: text
ruleset: phpmd.xml

phpcs:
runs-on: ubuntu-latest
needs: [ composer ]
strategy:
matrix:
php: [ 8.0, 8.1, 8.2 ]

steps:
- uses: actions/download-artifact@v3
with:
name: build-artifact
path: /tmp/github-actions

- name: Extract build archive
run: tar -xvf /tmp/github-actions/build.tar ./

- name: PHP Code Sniffer
uses: php-actions/phpcs@v1
with:
php_version: ${{ matrix.php }}
path: src/
standard: phpcs.xml

remove_old_artifacts:
runs-on: ubuntu-latest

steps:
- name: Remove old artifacts for prior workflow runs on this repository
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api "/repos/${{ github.repository }}/actions/artifacts?name=build-artifact" | jq ".artifacts[] | select(.name == \"build-artifact\") | .id" > artifact-id-list.txt
while read id
do
echo -n "Deleting artifact ID $id ... "
gh api --method DELETE /repos/${{ github.repository }}/actions/artifacts/$id && echo "Done"
done <artifact-id-list.txt
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ Throughout PHP.Gt repositories, wherever an object represents enclosed data, a c
<a href="https://github.com/PhpGt/TypeSafeGetter/actions" target="_blank">
<img src="https://badge.status.php.gt/typesafegetter-build.svg" alt="Build status" />
</a>
<a href="https://scrutinizer-ci.com/g/PhpGt/TypeSafeGetter" target="_blank">
<a href="https://app.codacy.com/gh/PhpGt/Curl" target="_blank">
<img src="https://badge.status.php.gt/typesafegetter-quality.svg" alt="Code quality" />
</a>
<a href="https://app.codecov.io/gh/PhpGt/TypeSafeGetter" target="_blank">
<img src="https://badge.status.php.gt/typesafegetter-coverage.svg" alt="Code coverage" />
</a>
<a href="https://packagist.org/packages/PhpGt/TypeSafeGetter" target="_blank">
<img src="https://badge.status.php.gt/typesafegetter-version.svg" alt="Current version" />
</a>
<a href="http://www.php.gt/typesafegetter" target="_blank">
<a href="https://www.php.gt/typesafegetter" target="_blank">
<img src="https://badge.status.php.gt/typesafegetter-docs.svg" alt="PHP.Gt/TypeSafeGetter documentation" />
</a>

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

Common areas you will see this interface used:

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

`NullableTypeSafeGetter` trait
------------------------------
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
},

"require-dev": {
"phpstan/phpstan": "^v1.8",
"phpunit/phpunit": "^v9.5"
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.1",
"phpmd/phpmd": "^2.13",
"squizlabs/php_codesniffer": "^3.7"
},

"authors": [
Expand Down
Loading

0 comments on commit 7874a16

Please sign in to comment.