From 2cd034417bc841cb46fac9f2ba2c60254ad5f2fa Mon Sep 17 00:00:00 2001 From: Joe <104938042+lrljoe@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:26:44 +0100 Subject: [PATCH] Improve Workflow Caches (#2013) * Improve Workflow Caches * Fix styling --------- Co-authored-by: lrljoe --- .github/workflows/pint.yml | 2 +- .github/workflows/run-phpstan-pull.yml | 104 ++++++++++++++++++++++ .github/workflows/run-phpstan.yml | 30 +++++-- .github/workflows/run-tests-pcov-pull.yml | 12 ++- .github/workflows/run-tests-pull.yml | 22 ++--- .github/workflows/run-tests.yml | 40 ++++++--- 6 files changed, 177 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/run-phpstan-pull.yml diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 356103132..c533df969 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -26,7 +26,7 @@ jobs: - name: Fix PHP code style issues uses: aglipanci/laravel-pint-action@latest - - name: Commit changes + - name: Commit styling changes uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Fix styling diff --git a/.github/workflows/run-phpstan-pull.yml b/.github/workflows/run-phpstan-pull.yml new file mode 100644 index 000000000..e6663148e --- /dev/null +++ b/.github/workflows/run-phpstan-pull.yml @@ -0,0 +1,104 @@ +name: run-phpstan-pull + +on: + pull_request: + branches: + - 'master' + - 'development' + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.3] + laravel: [11] + stability: [prefer-dist] + + name: PHPStan - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + + steps: + - name: Wait for tests to finish + uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + running-workflow-name: 'Run Tests Pull' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 20 + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ env.extensionKey }} + + - name: Cache extensions + uses: actions/cache@v4 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + coverage: pcov + tools: phpunit:9.5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Get composer cache directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + + - name: Add token + run: | + composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update + + - name: Update dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer update --${{ matrix.stability }} --no-interaction + + - name: Install PHPStan + run: composer require larastan/larastan:^2.0 --no-interaction + + - uses: actions/cache/restore@v4 + id: larastan-restore + with: + path: ./build/phpstan + key: phpstan-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} + + - name: Run PHPStan Tests + run: ./vendor/bin/phpstan analyse + + - uses: actions/cache/save@v4 + id: larastan-save + with: + path: ./build/phpstan + key: phpstan-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} diff --git a/.github/workflows/run-phpstan.yml b/.github/workflows/run-phpstan.yml index 3701660df..1b7304a85 100644 --- a/.github/workflows/run-phpstan.yml +++ b/.github/workflows/run-phpstan.yml @@ -1,10 +1,6 @@ name: run-phpstan on: - pull_request: - branches: - - 'master' - - 'development' push: branches: - '*' # matches every branch that doesn't contain a '/' @@ -26,10 +22,18 @@ jobs: name: PHPStan - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} env: - extensionKey: phpextensions + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo steps: + - name: Wait for tests to finish + uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + running-workflow-name: 'Run Standard Tests' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 20 + - name: Checkout code uses: actions/checkout@v4 @@ -69,8 +73,8 @@ jobs: - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-PHPStan-P${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-PHPStan-P${{ matrix.php }}-L${{ matrix.laravel }}-composer- + key: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -87,5 +91,17 @@ jobs: - name: Install PHPStan run: composer require larastan/larastan:^2.0 --dev --no-interaction + - uses: actions/cache/restore@v4 + id: larastan-restore + with: + path: ./build/phpstan + key: phpstan-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} + - name: Run PHPStan Tests run: ./vendor/bin/phpstan analyse + + - uses: actions/cache/save@v4 + id: larastan-save + with: + path: ./build/phpstan + key: phpstan-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} diff --git a/.github/workflows/run-tests-pcov-pull.yml b/.github/workflows/run-tests-pcov-pull.yml index fffe0618f..639edbf63 100644 --- a/.github/workflows/run-tests-pcov-pull.yml +++ b/.github/workflows/run-tests-pcov-pull.yml @@ -26,6 +26,14 @@ jobs: extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pcov,pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo steps: + - name: Wait for tests to finish + uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + running-workflow-name: 'Run Tests Pull' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 20 + - name: Checkout code uses: actions/checkout@v4 @@ -66,8 +74,8 @@ jobs: - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-PCOV-PULL-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-PCOV-PULL-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- + key: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | diff --git a/.github/workflows/run-tests-pull.yml b/.github/workflows/run-tests-pull.yml index 80c625554..28e642d03 100644 --- a/.github/workflows/run-tests-pull.yml +++ b/.github/workflows/run-tests-pull.yml @@ -1,4 +1,4 @@ -name: run-tests-pull +name: Run Tests Pull on: pull_request: @@ -20,7 +20,7 @@ jobs: name: PULL PHP-${{ matrix.php }} - Laravel-10 env: - extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: @@ -39,8 +39,8 @@ jobs: uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} - key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} - restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + key: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -64,8 +64,8 @@ jobs: - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + key: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -118,8 +118,8 @@ jobs: uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} - key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} - restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + key: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -143,8 +143,8 @@ jobs: - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + key: ${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -162,4 +162,4 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run Unit Tests - run: php ./vendor/bin/paratest --no-coverage + run: php ./vendor/bin/phpunit --no-coverage diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index bcb0d7031..490c6a3a3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,4 +1,4 @@ -name: run-tests +name: Run Standard Tests on: push: @@ -22,10 +22,18 @@ jobs: name: PHP-${{ matrix.php }} - Laravel-10 env: - extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: + - name: Wait for styling to finish + uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + running-workflow-name: 'Fix PHP code style issues' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 20 + - name: Checkout code uses: actions/checkout@v4 @@ -41,8 +49,8 @@ jobs: uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} - key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} - restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + key: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -66,8 +74,8 @@ jobs: - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + key: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -101,10 +109,18 @@ jobs: name: PHP-${{ matrix.php }} - Laravel-11 env: - extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-L${{ matrix.laravel }} + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: + - name: Wait for styling to finish + uses: lewagon/wait-on-check-action@v1.3.4 + with: + ref: ${{ github.ref }} + running-workflow-name: 'Fix PHP code style issues' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 20 + - name: Checkout code uses: actions/checkout@v4 @@ -120,8 +136,8 @@ jobs: uses: actions/cache@v4 with: path: ${{ steps.extcache.outputs.dir }} - key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} - restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + key: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ matrix.os }}-${{ steps.extcache.outputs.key }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -145,8 +161,8 @@ jobs: - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- + key: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ matrix.os }}-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -164,4 +180,4 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run Unit Tests - run: php ./vendor/bin/paratest --no-coverage + run: php ./vendor/bin/phpunit --no-coverage