Skip to content

Detect generators by scanning the body for yield, including unreachable code and excluding nested functions #29876

Detect generators by scanning the body for yield, including unreachable code and excluding nested functions

Detect generators by scanning the body for yield, including unreachable code and excluding nested functions #29876

Workflow file for this run

# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Compile PHAR"
on:
pull_request:
push:
branches:
- "2.2.x"
tags:
- '2.2.*'
concurrency:
group: phar-${{ github.ref }} # will be canceled on subsequent pushes in both branches and pull requests
cancel-in-progress: true
jobs:
compiler-tests:
name: "Compiler Tests"
runs-on: "ubuntu-latest"
timeout-minutes: 60
outputs:
checksum: ${{ steps.checksum.outputs.md5 }}
compiler_changed: ${{ steps.changes.outputs.compiler }}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: "Install PHP"
uses: "shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc" # v2.37.1
with:
coverage: "none"
php-version: "8.2"
extensions: mbstring, intl
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
with:
ignore-cache: true
# only sebastian/diff ^4 supports PHP 7.4 so we need that in the PHAR
- name: "Downgrade PHPUnit"
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 doctrine/instantiator:^1.0 --update-with-dependencies --ignore-platform-reqs"
- name: "Install compiler dependencies"
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
with:
working-directory: "compiler"
ignore-cache: true
- name: "Compiler tests"
working-directory: "compiler"
run: "vendor/bin/phpunit -c tests/phpunit.xml tests"
- name: "Compiler PHPStan"
working-directory: "compiler"
run: "vendor/bin/phpstan analyse -l 8 src tests"
- name: "Prepare for PHAR compilation"
working-directory: "compiler"
run: "php bin/prepare"
- name: "Dump autoloader one more time for attributes"
run: "composer dump"
- name: "Install Box dependencies"
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
with:
working-directory: "compiler/box"
ignore-cache: true
- name: "Compile PHAR"
working-directory: "compiler/build"
run: "php ../box/vendor/bin/box compile --no-parallel --sort-compiled-files"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: phar-file
path: tmp/phpstan.phar
- name: "Run PHAR"
working-directory: "compiler"
run: "../tmp/phpstan.phar list"
- name: "Delete PHAR"
run: "rm tmp/phpstan.phar"
- name: "Set autoloader suffix"
run: "composer config autoloader-suffix PHPStanChecksum"
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
env:
COMPOSER_ROOT_VERSION: "2.2.x-dev"
with:
ignore-cache: true
- name: "Compile PHAR for checksum"
working-directory: "compiler/build"
run: "php ../box/vendor/bin/box compile --no-parallel --sort-compiled-files"
env:
PHAR_CHECKSUM: "1"
COMPOSER_ROOT_VERSION: "2.2.x-dev"
- name: "Re-sign PHAR"
run: "php compiler/build/resign.php tmp/phpstan.phar"
- name: "Unset autoloader suffix"
run: "composer config autoloader-suffix --unset"
- name: "Save checksum"
id: "checksum"
run: echo "md5=$(md5sum tmp/phpstan.phar | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: phar-file-checksum
path: tmp/phpstan.phar
- name: "Delete checksum PHAR"
run: "rm tmp/phpstan.phar"
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: changes
with:
filters: |
compiler:
- 'compiler/**'
- '.github/workflows/phar.yml'
- '.github/scripts/**'
integration-tests:
if: github.event_name == 'pull_request'
needs: compiler-tests
uses: phpstan/phpstan/.github/workflows/integration-tests.yml@2.2.x
with:
ref: 2.2.x
phar-checksum: ${{needs.compiler-tests.outputs.checksum}}
extension-tests:
if: github.event_name == 'pull_request'
needs: compiler-tests
uses: phpstan/phpstan/.github/workflows/extension-tests.yml@2.2.x
with:
ref: 2.2.x
phar-checksum: ${{needs.compiler-tests.outputs.checksum}}
other-tests:
if: github.event_name == 'pull_request'
needs: compiler-tests
uses: phpstan/phpstan/.github/workflows/other-tests.yml@2.2.x
with:
ref: 2.2.x
phar-checksum: ${{needs.compiler-tests.outputs.checksum}}
download-base-sha-phar:
name: "Download base SHA PHAR"
needs: compiler-tests
if: github.event_name == 'pull_request' && needs.compiler-tests.outputs.compiler_changed == 'true'
runs-on: "ubuntu-latest"
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Get base commit SHA
id: base
run: echo "base_sha=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 20
- name: Install dependencies
working-directory: .github/scripts
run: npm ci
- name: "Compile TS scripts"
working-directory: .github/scripts
run: npx tsc
- name: Find phar-file-checksum from base commit
id: find-artifact
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
BASE_SHA: ${{ steps.base.outputs.base_sha }}
ARTIFACT_NAME: phar-file-checksum
WORKFLOW_NAME: Compile PHAR
with:
script: |
const script = require('./.github/scripts/dist/find-artifact.js');
await script({github, context, core})
# saved to phar-file-checksum/phpstan.phar
- name: Download old artifact by ID
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ steps.find-artifact.outputs.artifact_id }}
run-id: ${{ steps.find-artifact.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
# download-artifact v5+ extracts single by-ID downloads directly into
# `path`, no longer nested under the artifact name; keep the old layout
path: phar-file-checksum
- name: "Upload old artifact"
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: phar-file-checksum-base
path: phar-file-checksum/phpstan.phar
checksum-phar:
name: "Checksum PHAR"
needs:
- compiler-tests
- download-base-sha-phar
runs-on: "ubuntu-latest"
steps:
# saved to phpstan.phar
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- name: "Download base phpstan.phar"
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: phar-file-checksum-base
- name: "Save old checksum"
id: "old_checksum"
run: echo "md5=$(md5sum phpstan.phar | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- name: "Assert checksum"
run: |
old_checksum=${{ steps.old_checksum.outputs.md5 }}
new_checksum=${{needs.compiler-tests.outputs.checksum}}
[[ "$old_checksum" == "$new_checksum" ]];
phar-prefix-diff:
name: "PHAR Prefix Diff"
needs: download-base-sha-phar
runs-on: "ubuntu-latest"
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# saved to phar-file-checksum/phpstan.phar
- name: "Download phpstan.phar"
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: phar-file-checksum
path: phar-file-checksum
# saved to phar-file-checksum-base/phpstan.phar
- name: "Download base phpstan.phar"
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: phar-file-checksum-base
path: phar-file-checksum-base
- name: "Install PHP"
uses: "shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc" # v2.37.1
with:
coverage: "none"
php-version: "8.2"
- uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
- name: "Install Box dependencies"
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v4.0.0
with:
working-directory: "compiler/box"
- name: "Extract old phpstan.phar"
run: "php compiler/box/vendor/bin/box extract phar-file-checksum-base/phpstan.phar phar-old"
- name: "Extract new phpstan.phar"
run: "php compiler/box/vendor/bin/box extract phar-file-checksum/phpstan.phar phar-new"
- name: "List prefix locations in old PHAR"
run: "php .github/scripts/listPrefix.php ${{ github.workspace }}/phar-old > phar-old.txt"
- name: "List prefix locations in new PHAR"
run: "php .github/scripts/listPrefix.php ${{ github.workspace }}/phar-new > phar-new.txt"
- name: "Diff locations"
run: "diff -u phar-old.txt phar-new.txt > diff.txt || true"
- name: "Diff files where prefix changed"
run: "php .github/scripts/diffPrefixes.php ${{ github.workspace }}/diff.txt ${{ github.workspace }}/phar-old ${{ github.workspace }}/phar-new"
commit:
name: "Commit PHAR"
if: "github.repository_owner == 'phpstan' && (github.ref == 'refs/heads/2.2.x' || startsWith(github.ref, 'refs/tags/'))"
needs: compiler-tests
runs-on: "ubuntu-latest"
timeout-minutes: 60
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
-
name: Import GPG key
id: import-gpg
uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd # v7.0.0
with:
gpg_private_key: ${{ secrets.GPG_PHPSTANBOT_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PHPSTANBOT_KEY_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: "Checkout phpstan-dist"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: phpstan/phpstan
path: phpstan-dist
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
ref: 2.2.x
- name: "Get previous pushed dist commit"
id: previous-commit
working-directory: phpstan-dist
run: echo "sha=$(sed -n '2p' .phar-checksum)" >> "$GITHUB_OUTPUT"
- name: "Checkout phpstan-src"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
path: phpstan-src
- name: "Get Git log"
id: git-log
working-directory: phpstan-src
run: |
echo "log<<MESSAGE" >> "$GITHUB_OUTPUT"
git log ${{ steps.previous-commit.outputs.sha }}..${{ github.event.after }} --reverse --pretty='https://github.com/phpstan/phpstan-src/commit/%H %s' >> "$GITHUB_OUTPUT"
echo 'MESSAGE' >> "$GITHUB_OUTPUT"
- name: "Get short phpstan-src SHA"
id: short-src-sha
working-directory: phpstan-src
run: echo "sha=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"
- name: "Check PHAR checksum"
id: checksum-difference
working-directory: phpstan-dist
run: |
checksum="${{needs.compiler-tests.outputs.checksum}}"
if [[ $(head -n 1 .phar-checksum) != "$checksum" ]]; then
echo "result=different" >> "$GITHUB_OUTPUT"
else
echo "result=same" >> "$GITHUB_OUTPUT"
fi
- name: "Download phpstan.phar"
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: phar-file
- name: "mv PHAR"
run: mv phpstan.phar phpstan-dist/phpstan.phar
- name: "chmod PHAR"
run: chmod 755 phpstan-dist/phpstan.phar
- name: "Update checksum"
run: |
echo ${{needs.compiler-tests.outputs.checksum}} > phpstan-dist/.phar-checksum
echo ${{ github.event.head_commit.id }} >> phpstan-dist/.phar-checksum
- name: "Sign PHAR"
working-directory: phpstan-dist
run: rm phpstan.phar.asc && gpg --command-fd 0 --pinentry-mode loopback -u "$GPG_ID" --batch --detach-sign --armor --output phpstan.phar.asc phpstan.phar
env:
GPG_ID: ${{ steps.import-gpg.outputs.fingerprint }}
- name: "Verify PHAR"
working-directory: phpstan-dist
run: "gpg --verify phpstan.phar.asc"
- name: "Install lucky_commit"
uses: baptiste0928/cargo-install@f204293d9709061b7bc1756fec3ec4e2cd57dec0 # v3.4.0
with:
crate: lucky_commit
args: --no-default-features
- name: "Commit PHAR - development"
if: "!startsWith(github.ref, 'refs/tags/') && steps.checksum-difference.outputs.result == 'different'"
working-directory: phpstan-dist
env:
INPUT_LOG: ${{ steps.git-log.outputs.log }}
run: |
git config --global user.name "phpstan-bot"
git config --global user.email "ondrej+phpstanbot@mirtes.cz"
git add .
git commit --gpg-sign -m "Updated PHPStan to commit ${{ github.event.after }}" -m "$INPUT_LOG" --author "phpstan-bot <ondrej+phpstanbot@mirtes.cz>"
lucky_commit ${{ steps.short-src-sha.outputs.sha }}
git push
- name: "Commit PHAR - tag"
if: "startsWith(github.ref, 'refs/tags/')"
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
with:
commit_user_name: "phpstan-bot"
commit_user_email: "ondrej+phpstanbot@mirtes.cz"
commit_author: "phpstan-bot <ondrej+phpstanbot@mirtes.cz>"
commit_options: "--gpg-sign"
repository: phpstan-dist
commit_message: "PHPStan ${{github.ref_name}}"
tagging_message: ${{github.ref_name}}