Skip to content

Commit 037f5c0

Browse files
authored
feat: load file (#356)
1 parent 5780e4c commit 037f5c0

22 files changed

+943
-317
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,86 @@ on:
44
push:
55
pull_request:
66

7+
env:
8+
COVERAGE: '0'
9+
710
jobs:
811
build:
912
name: Build and Test
1013
runs-on: ubuntu-latest
11-
env:
12-
extensions: json
13-
composer_version: 2
1414
strategy:
1515
matrix:
16-
php_version:
16+
php:
1717
- '7.4'
1818
- '8.0'
19+
include:
20+
- php: '8.0'
21+
coverage: true
1922
steps:
2023
- uses: actions/checkout@v2
2124

2225
- name: Get Composer Cache Directory
2326
id: composer-cache
24-
run: |
25-
echo "::set-output name=dir::$(composer config cache-files-dir)"
27+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
2628

2729
- uses: actions/cache@v2
2830
with:
2931
path: ${{ steps.composer-cache.outputs.dir }}
3032
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
31-
restore-keys: |
32-
${{ runner.os }}-composer-
33+
restore-keys: ${{ runner.os }}-composer-
3334

3435
- name: Setup PHP with extensions
3536
uses: shivammathur/setup-php@v2
3637
with:
37-
php-version: ${{ matrix.php_version }}
38-
extensions: ${{ env.extensions }}
38+
php-version: ${{ matrix.php }}
39+
extensions: json
3940
ini-values: memory_limit=-1
4041
coverage: pcov
41-
tools: composer:v2, cs2pr, php-cs-fixer
42+
tools: composer, cs2pr, php-cs-fixer
4243

4344
- name: Install prerequisites
4445
run: |
45-
export PATH="$PATH:$HOME/.composer/vendor/bin"
46-
mkdir -p build/logs
47-
wget https://github.com/satooshi/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
4846
wget -O box.phar https://github.com/humbug/box/releases/download/3.13.0/box.phar
49-
export BOX_BIN=$(pwd)/box.phar
47+
echo "BOX_BIN=$(pwd)/box.phar" >> $GITHUB_ENV
5048
sudo chown -R $(whoami):$(whoami) .
5149
5250
- name: Install dependencies
53-
run: composer install --prefer-dist --no-interaction --no-progress
51+
if: startsWith(matrix.php, '8.0')
52+
run: composer install --prefer-dist --no-interaction --no-progress --ansi
53+
54+
- name: Update dependencies
55+
if: "!startsWith(matrix.php, '8.0')"
56+
run: composer update --no-interaction --no-progress --ansi
57+
58+
- name: Enable code coverage
59+
if: matrix.coverage
60+
run: echo "COVERAGE=1" >> $GITHUB_ENV
5461

5562
- name: Run phpunit
56-
run: vendor/bin/simple-phpunit
63+
run: |
64+
mkdir -p build/logs/phpunit
65+
if [ "$COVERAGE" = '1' ]; then
66+
vendor/bin/simple-phpunit --coverage-clover build/logs/phpunit/clover.xml
67+
else
68+
vendor/bin/simple-phpunit
69+
fi
5770
5871
- name: Run php-cs-fixer
59-
run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
72+
run: php-cs-fixer fix --dry-run --format=checkstyle --ansi | cs2pr
6073

6174
- name: Run phpstan
62-
run: |
63-
vendor/bin/phpstan analyse
75+
run: vendor/bin/phpstan analyse --ansi
6476

6577
- name: Run e2e tests
78+
if: startsWith(matrix.php, '8.0')
79+
run: bin/compile
80+
81+
- name: Upload coverage results to Coveralls
82+
if: matrix.coverage
83+
env:
84+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6685
run: |
67-
php bin/compile
86+
composer global require --prefer-dist --no-interaction --no-progress --ansi php-coveralls/php-coveralls
87+
export PATH="$PATH:$HOME/.composer/vendor/bin"
88+
php-coveralls --coverage_clover=build/logs/phpunit/clover.xml -v
89+
continue-on-error: true

.github/workflows/release.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ jobs:
99
build:
1010
name: Create Release and Upload Release Asset
1111
runs-on: ubuntu-latest
12-
env:
13-
extensions: json
14-
php_version: '8.0'
1512
outputs:
1613
upload_url: ${{ steps.step_upload_url.outputs.upload_url }}
1714
steps:
@@ -21,27 +18,25 @@ jobs:
2118
- name: Setup PHP with extensions
2219
uses: shivammathur/setup-php@v2
2320
with:
24-
php-version: ${{ env.php_version }}
25-
extensions: ${{ env.extensions }}
21+
php-version: '8.0'
22+
extensions: json
2623
ini-values: memory_limit=-1
27-
tools: composer:v2
24+
tools: composer
2825

2926
- name: Install dependencies
30-
run: composer install --prefer-dist --no-interaction --no-progress
27+
run: composer install --prefer-dist --no-interaction --no-progress --ansi
3128

3229
- name: Download box.phar
33-
run: |
34-
wget -O box.phar https://github.com/humbug/box/releases/download/3.11.1/box.phar
35-
export BOX_BIN=$(pwd)/box.phar
30+
run: wget -O box.phar https://github.com/humbug/box/releases/download/3.13.0/box.phar
3631

3732
- name: Compile project
38-
run: php ./box.phar compile;
33+
run: php ./box.phar compile
3934

4035
- name: Create Release
4136
id: create_release
4237
uses: actions/create-release@v1
4338
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4540
with:
4641
tag_name: ${{ github.ref }}
4742
release_name: Release ${{ github.ref }}

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
->in(__DIR__)
2525
->exclude('tests/Fixtures/app/cache')
2626
->exclude('build')
27+
->exclude('tmp')
2728
->exclude('tests/e2e');
2829

2930
$config = new PhpCsFixer\Config();

bin/compile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ set -eox pipefail
44

55
php "$BOX_BIN" compile;
66

7-
php schema.phar generate tmp/ tests/e2e/schema.yml;
7+
rm -rf tmp/original
88

9-
diff tests/e2e/src/App/Entity/Person.php tmp/App/Entity/Person.php;
10-
diff tests/e2e/src/App/Entity/PostalAddress.php tmp/App/Entity/PostalAddress.php;
11-
diff tests/e2e/src/App/Entity/Thing.php tmp/App/Entity/Thing.php;
9+
php schema.phar generate tmp/original tests/e2e/schema.yml -n -vv --ansi;
10+
11+
diff tests/e2e/original/App/Entity/Person.php tmp/original/App/Entity/Person.php;
12+
diff tests/e2e/original/App/Entity/PostalAddress.php tmp/original/App/Entity/PostalAddress.php;
13+
diff tests/e2e/original/App/Entity/Thing.php tmp/original/App/Entity/Thing.php;
14+
15+
# Already generated files
16+
17+
cp -r tests/e2e/customized tmp/
18+
19+
php schema.phar generate tmp/customized tests/e2e/schema.yml -n -vv --ansi;
20+
21+
diff tests/e2e/customized/App/Entity/Person.php tmp/customized/App/Entity/Person.php;
22+
diff tests/e2e/customized/App/Entity/PostalAddress.php tmp/customized/App/Entity/PostalAddress.php;
23+
diff tests/e2e/customized/App/Entity/Thing.php tmp/customized/App/Entity/Thing.php;

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"symfony/yaml": "^5.2",
4343
"symfony/filesystem": "^5.2",
4444
"twig/twig": "^3.0",
45-
"nette/php-generator": "^3.6"
45+
"nette/php-generator": "^3.6 || ^4.0-dev",
46+
"nette/utils": "^3.1 || ^4.0-dev",
47+
"nikic/php-parser": "^4.13"
4648
},
4749
"require-dev": {
4850
"api-platform/core": "^2.5",

0 commit comments

Comments
 (0)