Skip to content

Commit

Permalink
Add matrix to github actions. (#7)
Browse files Browse the repository at this point in the history
* Add matrix to github actions.

* Update `composer.json`.

* Update `phpunit.xml`.

* Update `docker-compose.yml`.

---------

Co-authored-by: david_smith <[email protected]>
  • Loading branch information
zero-to-prod and david_smith authored Oct 29, 2024
1 parent c34ac56 commit 014c964
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/CONTRIBUTING.md export-ignore
/docker-compose.yml export-ignore
/LICENSE.md export-ignore
/logo.png export-ignore
/phpunit.xml export-ignore
/README.md export-ignore
/SECURITY.md export-ignore
/test.sh export-ignore
88 changes: 13 additions & 75 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,37 @@ name: tests

on:
push:
branches:
- main
branches: [main]
pull_request:
branches:
- main

permissions:
contents: write
branches: [main]

jobs:
php81:
test:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Composer dependencies
run: docker compose run --rm php81composer composer install --prefer-dist --no-progress --no-suggest

- name: Run tests
run: docker compose run --rm php81 vendor/bin/phpunit

php82:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Composer dependencies
run: docker compose run --rm php82composer composer install --prefer-dist --no-progress --no-suggest

- name: Run tests
run: docker compose run --rm php82 vendor/bin/phpunit

php83:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged
strategy:
matrix:
php-version: [php81, php82, php83]

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
- name: Validate composer files
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-

- name: Install Composer dependencies
run: docker compose run --rm php83composer composer install --prefer-dist --no-progress --no-suggest
- name: Install dependencies
run: docker compose run --rm -v ${{ github.workspace }}/test-output:/app/test-output ${{ matrix.php-version }}composer composer install --prefer-dist

- name: Run tests
run: docker compose run --rm php83 vendor/bin/phpunit
run: docker compose run --rm -v ${{ github.workspace }}/test-output:/app/test-output ${{ matrix.php-version }} vendor/bin/phpunit
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "*"
},
"suggest": {
"zero-to-prod/transformable": "Transform a class into different types."
Expand Down
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
target: base
volumes:
- ./:/app
- ./docker/php81:/usr/local/etc/php

php81debug:
build:
Expand All @@ -28,7 +27,6 @@ services:
target: base
volumes:
- ./:/app
- ./docker/php82:/usr/local/etc/php

php82debug:
build:
Expand All @@ -51,7 +49,6 @@ services:
target: base
volumes:
- ./:/app
- ./docker/php83:/usr/local/etc/php

php83debug:
build:
Expand Down
12 changes: 5 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true">
failOnWarning="true"
colors="true"
>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true"
restrictNotices="true"
restrictWarnings="true"
>
<source restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
Expand Down
16 changes: 16 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# run-tests.sh
set -e

php_versions=("php83" "php82" "php81")

for version in "${php_versions[@]}"; do
echo "Setting up environment..."
rm composer.lock
docker compose run --rm "$version"composer composer install
echo "Running tests on $version..."
if ! docker compose run --rm "$version" vendor/bin/phpunit; then
echo "Tests failed on $version."
exit 1
fi
done
echo "All tests passed!"

0 comments on commit 014c964

Please sign in to comment.