Skip to content

Commit

Permalink
Improve GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
roelofr committed Mar 7, 2023
1 parent 14f94f8 commit 1beb3f2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 35 deletions.
60 changes: 44 additions & 16 deletions .github/workflows/auto-format-code.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
name: Auto-format code
name: Verify code formatting

on:
push:
pull_request:
branches:
- develop
- master
push:
branches:
- develop

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

jobs:
test:
Expand All @@ -12,40 +21,59 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@master
uses: actions/checkout@v3
with:
php-version: '8.1'
extensions: exif,json,mbstring
coverage: none
fetch-depth: 0

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: 'npm'

- name: Install NodeJS dependencies
run: npm install --verbose --foreground-scripts

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: exif,json,mbstring
coverage: none

- name: Configure local Laravel Nova dummy package
run: composer config repositories.0 path ./tests/Fixtures/nova
run: |
composer config repositories.0 path ./tests/Fixtures/nova
git update-index --assume-unchanged composer.json composer.lock
- name: Install Composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2
with:
composer-options: "--ignore-platform-req=php"
dependency-versions: highest # No lockfile is present, so locked (the default) isn't possible

- name: Install NodeJS dependencies
run: npm install

- name: Lint code
run: |
composer run format
npm run format
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
- name: Report changes
id: report-changes
run: |
git diff --color=always
echo " > git diff --shortstat" >> $GITHUB_STEP_SUMMARY
echo " $( git diff --shortstat )" >> $GITHUB_STEP_SUMMARY
echo "HAS_CHANGES=$( git diff --quiet && echo 'no' || echo 'yes' )" >> $GITHUB_OUTPUT
- name: Fail on changes (pull request only)
if: ${{ github.event_name == 'pull_request' && steps.report-changes.outputs.HAS_CHANGES == 'yes' }}
run: |
echo '::error title=Linting caused changes::Some files were modified by the linter, please run `composer format` to fix these'
exit 1
- name: Commit changes (push only)
if: ${{ github.event_name == 'push' }}
uses: stefanzweifel/[email protected]
with:
commit_message: Fixed code style using PHP-CS-Fixer

57 changes: 38 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
test:
name: Test on PHP ${{ matrix.php }}
name: Test Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental == true }}

Expand All @@ -17,54 +17,73 @@ jobs:
matrix:
php:
- '8.1'
- '8.2'
- 'nightly'

laravel:
- '8.0'
- '9.0'
- '10.0'

include:
- php: '8.2'
laravel: '9.0'
stable: true
- php: 'nightly'
experimental: true
- laravel: '8.0'
testbench: '6.0'
- laravel: '9.0'
testbench: '7.0'
- laravel: '10.0'
testbench: '8.0'

steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: exif,json,mbstring
coverage: pcov

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

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

- name: Install Composer dependencies
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v2
with:
composer-options: "--ignore-platform-req=php"
dependency-versions: highest # No lockfile is present, so locked (the default) isn't possible

- name: Lint code
run: composer run lint
- name: Run unit tests with coverage and printer
id: phpunit
run: |
echo "phpunit_version=$( vendor/bin/phpunit --version )" >> $GITHUB_OUTPUT
vendor/bin/phpunit \
--log-junit=./report-junit.xml \
--coverage-clover=./coverage-clover.xml
- name: Run unit tests
run:
vendor/bin/phpunit
--printer mheap\\GithubActionsReporter\\Printer
--coverage-clover=./coverage.xml
- name: Report test results
if: ${{ success() || failure() }}
uses: mikepenz/action-junit-report@v3
with:
report_paths: ./report-junit.xml
check_name: "PHPUnit ${{ steps.phpunit.outputs.phpunit_version }} on PHP ${{ matrix.php }} with Laravel ${{ matrix.laravel }}"

- name: Determine coverage
uses: slavcodev/coverage-monitor-action@1.1.0
if: github.event_name == 'pull_request' && matrix.experimental != true
uses: slavcodev/coverage-monitor-action@1.8.0
if: ${{ github.event_name == 'pull_request' && matrix.stable == true }}
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down

0 comments on commit 1beb3f2

Please sign in to comment.