Skip to content

Commit 932c31d

Browse files
authored
Improve GitHub Actions and test results (#95)
1 parent af9550d commit 932c31d

File tree

7 files changed

+106
-46
lines changed

7 files changed

+106
-46
lines changed
Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
name: Auto-format code
1+
name: Verify code formatting
22

33
on:
4-
push:
4+
pull_request:
55
branches:
6+
- develop
67
- master
8+
push:
9+
branches:
10+
- develop
11+
12+
permissions:
13+
# Give the default GITHUB_TOKEN write permission to commit and push the
14+
# added or changed files to the repository.
15+
contents: write
716

817
jobs:
918
test:
@@ -12,40 +21,59 @@ jobs:
1221

1322
steps:
1423
- name: Checkout
15-
uses: actions/checkout@v1
16-
17-
- name: Setup PHP
18-
uses: shivammathur/setup-php@master
24+
uses: actions/checkout@v3
1925
with:
20-
php-version: '8.1'
21-
extensions: exif,json,mbstring
22-
coverage: none
26+
fetch-depth: 0
2327

2428
- name: Setup NodeJS
2529
uses: actions/setup-node@v3
2630
with:
2731
node-version: lts/*
2832
cache: 'npm'
2933

34+
- name: Install NodeJS dependencies
35+
run: npm install --verbose --foreground-scripts
36+
37+
- name: Setup PHP
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: '8.1'
41+
extensions: exif,json,mbstring
42+
coverage: none
43+
3044
- name: Configure local Laravel Nova dummy package
31-
run: composer config repositories.0 path ./tests/Fixtures/nova
45+
run: |
46+
composer config repositories.0 path ./tests/Fixtures/nova
47+
git update-index --assume-unchanged composer.json composer.lock
3248
3349
- name: Install Composer dependencies
34-
uses: ramsey/composer-install@v1
50+
uses: ramsey/composer-install@v2
3551
with:
3652
composer-options: "--ignore-platform-req=php"
3753
dependency-versions: highest # No lockfile is present, so locked (the default) isn't possible
3854

39-
- name: Install NodeJS dependencies
40-
run: npm install
41-
4255
- name: Lint code
4356
run: |
4457
composer run format
4558
npm run format
4659
47-
- name: Commit changes
48-
uses: stefanzweifel/git-auto-commit-action@v4
60+
- name: Report changes
61+
id: report-changes
62+
run: |
63+
git diff --color=always
64+
echo " > git diff --shortstat" >> $GITHUB_STEP_SUMMARY
65+
echo " $( git diff --shortstat )" >> $GITHUB_STEP_SUMMARY
66+
echo "HAS_CHANGES=$( git diff --quiet && echo 'no' || echo 'yes' )" >> $GITHUB_OUTPUT
67+
68+
- name: Fail on changes (pull request only)
69+
if: ${{ github.event_name == 'pull_request' && steps.report-changes.outputs.HAS_CHANGES == 'yes' }}
70+
run: |
71+
echo '::error title=Linting caused changes::Some files were modified by the linter, please run `composer format` to fix these'
72+
exit 1
73+
74+
- name: Commit changes (push only)
75+
if: ${{ github.event_name == 'push' }}
76+
uses: stefanzweifel/[email protected]
4977
with:
5078
commit_message: Fixed code style using PHP-CS-Fixer
5179

.github/workflows/test.yml

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
test:
11-
name: Test on PHP ${{ matrix.php }}
11+
name: Test Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }}
1212
runs-on: ubuntu-latest
1313
continue-on-error: ${{ matrix.experimental == true }}
1414

@@ -17,57 +17,76 @@ jobs:
1717
matrix:
1818
php:
1919
- '8.1'
20+
- '8.2'
2021
- 'nightly'
2122

23+
laravel:
24+
- '8.0'
25+
- '9.0'
26+
- '10.0'
27+
2228
include:
29+
- php: '8.2'
30+
laravel: '9.0'
31+
stable: true
2332
- php: 'nightly'
2433
experimental: true
34+
- laravel: '8.0'
35+
testbench: '6.0'
36+
- laravel: '9.0'
37+
testbench: '7.0'
38+
- laravel: '10.0'
39+
testbench: '8.0'
2540

2641
steps:
2742
- name: Checkout
28-
uses: actions/checkout@v1
43+
uses: actions/checkout@v3
2944

3045
- name: Setup PHP
31-
uses: shivammathur/setup-php@master
46+
uses: shivammathur/setup-php@v2
3247
with:
3348
php-version: ${{ matrix.php }}
3449
extensions: exif,json,mbstring
3550
coverage: pcov
3651

37-
- name: Setup problem matchers
38-
run: |
39-
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
40-
4152
- name: Remove platform from Composer file
4253
run: composer config --unset platform
4354

44-
- name: Add GitHub Actions printer for PHPUnit
45-
run: composer require --dev --no-update mheap/phpunit-github-actions-printer
55+
- name: Configure to use Laravel ${{ matrix.laravel }} with Testbench ${{ matrix.testbench }}
56+
run: |
57+
composer require --no-update laravel/laravel:^${{ matrix.laravel }}
58+
composer require --no-update --dev orchestra/testbench:^${{ matrix.testbench }}
4659
4760
- name: Configure local Laravel Nova dummy package
4861
run: composer config repositories.0 path ./tests/Fixtures/nova
4962

5063
- name: Install Composer dependencies
51-
uses: ramsey/composer-install@v1
64+
uses: ramsey/composer-install@v2
5265
with:
5366
composer-options: "--ignore-platform-req=php"
54-
dependency-versions: highest # No lockfile is present, so locked (the default) isn't possible
67+
dependency-versions: highest # We're installing additional packages, and cannot use the lockfile
5568

56-
- name: Lint code
57-
run: composer run lint
69+
- name: Run unit tests with coverage and printer
70+
id: phpunit
71+
run: |
72+
echo "phpunit_version=$( vendor/bin/phpunit --version | cut -d ' ' -f 2 )" >> $GITHUB_OUTPUT
73+
vendor/bin/phpunit \
74+
--log-junit ./report-junit.xml \
75+
--coverage-clover ./coverage-clover.xml
5876
59-
- name: Run unit tests
60-
run:
61-
vendor/bin/phpunit
62-
--printer mheap\\GithubActionsReporter\\Printer
63-
--coverage-clover=./coverage.xml
77+
- name: Report test results
78+
if: ${{ success() || failure() }}
79+
uses: mikepenz/action-junit-report@v3
80+
with:
81+
report_paths: ./report-junit.xml
82+
check_name: Test Results Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }} with PHPUnit ${{ steps.phpunit.outputs.phpunit_version }}
6483

6584
- name: Determine coverage
66-
uses: slavcodev/coverage-monitor-action@1.1.0
67-
if: github.event_name == 'pull_request' && matrix.experimental != true
85+
uses: slavcodev/coverage-monitor-action@1.8.0
86+
if: ${{ github.event_name == 'pull_request' && matrix.stable == true }}
6887
continue-on-error: true
6988
with:
7089
github_token: ${{ secrets.GITHUB_TOKEN }}
71-
clover_file: ./coverage.xml
90+
coverage_path: ./coverage-clover.xml
7291
threshold_alert: 60
7392
threshold_warning: 85

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage processUncoveredFiles="true">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
44
<include>
55
<directory suffix=".php">./src</directory>
66
</include>

src/Http/Controllers/EditorJsImageUploadController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public function url(Request $request): JsonResponse
119119
}
120120

121121
/**
122-
* @param $path
123122
* @param array $alterations
124123
*/
125124
private function applyAlterations($path, $alterations = [])
@@ -187,7 +186,6 @@ private function applyAlterations($path, $alterations = [])
187186
}
188187

189188
/**
190-
* @param $path
191189
* @return array
192190
*/
193191
private function applyThumbnails($path)
@@ -224,7 +222,6 @@ private function applyThumbnails($path)
224222

225223

226224
/**
227-
* @param $path
228225
*/
229226
private function deleteThumbnails($path)
230227
{

src/NovaEditorJsConverter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ protected function registerDefaultCallbacks(): void
147147
}
148148

149149
/**
150-
* @param $blockData
151150
* @return string
152151
*/
153152
protected function calculateImageClasses($blockData)

tests/Feature/Http/Controllers/EditorJsImageUploadControllerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function testSubmittingImageUrlWithErrors(): void
167167
* Provides a list of valid image files to test.
168168
* @return string[][]
169169
*/
170-
public function provideValidFiles(): array
170+
public static function provideValidFiles(): array
171171
{
172172
return [
173173
'gif' => [test_resource('responses/image.gif')],
@@ -182,9 +182,9 @@ public function provideValidFiles(): array
182182
* Provides a subset of the available image formats, since svg isn't supported by the GD library.
183183
* @return string[][]
184184
*/
185-
public function provideValidFilesForImageUpload(): array
185+
public static function provideValidFilesForImageUpload(): array
186186
{
187-
return Arr::except($this->provideValidFiles(), [
187+
return Arr::except(self::provideValidFiles(), [
188188
'svg',
189189
]);
190190
}

tests/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ class TestCase extends OrchestraTestCase
1616
{
1717
use DatabaseMigrations;
1818

19+
/**
20+
* Ensure the HTTP Client requests have a method to prevent stray requests (without logic)
21+
* @before
22+
*/
23+
protected function repairLaravel8Compatibiliy()
24+
{
25+
if (! \Composer\InstalledVersions::satisfies(new \Composer\Semver\VersionParser(), 'illuminate/support', '^8.0')) {
26+
return;
27+
}
28+
29+
$this->afterApplicationCreated(function () {
30+
\Illuminate\Http\Client\PendingRequest::macro('preventStrayRequests', function () {
31+
return $this;
32+
});
33+
});
34+
}
35+
1936
/**
2037
* Path to config file from here
2138
*/

0 commit comments

Comments
 (0)