From ae96ff54736d77b8a414b4b4a02a63212074ccc0 Mon Sep 17 00:00:00 2001 From: Roelof Roos Date: Tue, 7 Mar 2023 14:59:59 +0100 Subject: [PATCH] Improve GitHub Actions --- .github/workflows/auto-format-code.yml | 60 +++++++++++++++++++------- .github/workflows/test.yml | 59 ++++++++++++++++--------- 2 files changed, 83 insertions(+), 36 deletions(-) diff --git a/.github/workflows/auto-format-code.yml b/.github/workflows/auto-format-code.yml index 3c77cf5..8157669 100644 --- a/.github/workflows/auto-format-code.yml +++ b/.github/workflows/auto-format-code.yml @@ -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: @@ -12,14 +21,9 @@ 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 @@ -27,25 +31,49 @@ jobs: 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/git-auto-commit-action@v4.16.0 with: commit_message: Fixed code style using PHP-CS-Fixer diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 769d599..7ed35cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} @@ -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 + dependency-versions: highest # We're installing additional packages, and cannot use the lockfile - - 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 | cut -w -f 2 )" >> $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: "Test Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }} (PHPUnit ${{ steps.phpunit.outputs.phpunit_version }})" - 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 }}