From 435e2722a0497451f0f1d604fc2150cc1f420564 Mon Sep 17 00:00:00 2001 From: Atsushi Matsuo Date: Sun, 20 Jul 2025 10:13:53 +0900 Subject: [PATCH] Add CI workflow file to save a baseline for Phan and PHPStan --- .github/workflows/phan.yml | 28 ++------------- .github/workflows/phpstan.yml | 41 ++++++---------------- .github/workflows/save-baseline.yml | 54 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/save-baseline.yml diff --git a/.github/workflows/phan.yml b/.github/workflows/phan.yml index 957a3a0..4d1f397 100644 --- a/.github/workflows/phan.yml +++ b/.github/workflows/phan.yml @@ -5,13 +5,7 @@ permissions: on: push: - branches: - - "*" pull_request: - branches: [ 'master', 'main' ] - pull_request_target: - types: - - closed jobs: run: @@ -24,7 +18,7 @@ jobs: uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1 with: php-version: '8.4' - tools: phan:5.5.0 + tools: phan coverage: none - name: Restore cached baseline for Phan @@ -40,27 +34,11 @@ jobs: - name: Run Phan continue-on-error: true run: | - if [ -f ~/test/phan-baseline.php ]; then + if [ -f test/phan-baseline.php ]; then echo "Cached baseline for Phan is found. Running Phan with baseline." - phan -d ./ -k .phan/config.php --load-baseline ~/test/phan-baseline.php --no-progress-bar + phan -d ./ -k .phan/config.php --load-baseline test/phan-baseline.php --no-progress-bar else echo "Cached baseline for Phan is not found. Running Phan without baseline." phan -d ./ -k .phan/config.php --no-progress-bar exit 0 fi - - - name: Generate the baseline for Phan - continue-on-error: true - if: github.event.pull_request.merged == true - run: | - phan -d ./ -k .phan/config.php --save-baseline ~/test/phan-baseline.php --no-progress-bar - exit 0 - - - name: Save the baseline for Phan - id: save-the-baseline-for-phan - if: github.event.pull_request.merged == true - uses: actions/cache/save@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2 - with: - path: | - test/phan-baseline.php - key: phan-baseline-${{ github.run_id }}" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index fe7e34b..60b3d86 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,14 +1,11 @@ name: PHPStan +permissions: + contents: read + on: push: - branches: - - "*" pull_request: - branches: [ 'master', 'main' ] - pull_request_target: - types: - - closed jobs: run: @@ -19,17 +16,16 @@ jobs: level: [ 1, 2 ] include: - current-level: 1 - - max-level: 2 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Setup PHP - uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1 with: php-version: '8.4' - - name: Remove phpDocumentor temporarily and Install PHPStan - run: composer remove --dev --no-update phpdocumentor/phpdocumentor; composer update + - name: Install PHPStan + run: composer install - name: Restore cached baseline for PHPStan id: cache-baseline-restore @@ -42,30 +38,13 @@ jobs: phpstan-baseline- - name: Run PHPStan - if: matrix.level == matrix.current-level - continue-on-error: true + if: matrix.level < matrix.current-level || matrix.level == matrix.current-level run: | - ./vendor/bin/phpstan analyse --memory-limit 1G -c test/phpstan.neon src test -l "${{ matrix.level }}" + ./vendor/bin/phpstan analyse --memory-limit 1G -c test/phpstan.neon src test -l "${{ matrix.level }}" - name: Run PHPStan if: matrix.level > matrix.current-level continue-on-error: true run: | - ./vendor/bin/phpstan analyse --memory-limit 1G -c test/phpstan.neon src test -l "${{ matrix.level }}" - exit 0 - - - name: Generate the baseline for PHPStan - if: matrix.level == matrix.max-level && github.event.pull_request.merged == true - continue-on-error: true - run: | - ./vendor/bin/phpstan analyse --memory-limit 1G -c test/phpstan.neon --generate-baseline test/phpstan-baseline.neon src test -vvv --debug -l "${{ matrix.level }}" - exit 0 - - - name: Save the baseline for PHPStan - id: cache-baseline-save - if: matrix.level == matrix.max-level && github.event.pull_request.merged == true - uses: actions/cache/save@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2 - with: - path: | - test/phpstan-baseline.neon - key: phpstan-baseline-${{ github.run_id }}" + ./vendor/bin/phpstan analyse --memory-limit 1G -c test/phpstan.neon src test -l "${{ matrix.level }}" + exit 0 diff --git a/.github/workflows/save-baseline.yml b/.github/workflows/save-baseline.yml new file mode 100644 index 0000000..6cb02cb --- /dev/null +++ b/.github/workflows/save-baseline.yml @@ -0,0 +1,54 @@ +name: Save Baseline for Phan and PHPStan + +permissions: + contents: read + +on: + pull_request: + types: + - closed + +jobs: + run: + name: Save Baseline + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Setup PHP + uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1 + with: + php-version: '8.4' + tools: phan + coverage: none + + - name: Install PHPStan + run: composer install + + - name: Generate the baseline for Phan + continue-on-error: true + run: | + phan -d ./ -k .phan/config.php --save-baseline test/phan-baseline.php --no-progress-bar + exit 0 + + - name: Generate the baseline for PHPStan + continue-on-error: true + run: | + ./vendor/bin/phpstan analyse --memory-limit 1G -c test/phpstan.neon --generate-baseline test/phpstan-baseline.neon src test -vvv --debug -l 2 + exit 0 + + - name: Save the baseline for Phan + id: save-the-baseline-for-phan + uses: actions/cache/save@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2 + with: + path: | + test/phan-baseline.php + key: phan-baseline-${{ github.run_id }}" + + - name: Save the baseline for PHPStan + id: cache-baseline-save + uses: actions/cache/save@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2 + with: + path: | + test/phpstan-baseline.neon + key: phpstan-baseline-${{ github.run_id }}"