|
| 1 | +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions |
| 2 | + |
| 3 | +# This workflow checks that PHAR checksum changes only when it's supposed to |
| 4 | +# It should stay the same when the PHAR contents do not change |
| 5 | + |
| 6 | +name: "Check PHAR checksum" |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - 'compiler/**' |
| 12 | + - '.github/workflows/checksum-phar.yml' |
| 13 | + push: |
| 14 | + branches: |
| 15 | + - "1.10.x" |
| 16 | + paths: |
| 17 | + - 'compiler/**' |
| 18 | + - '.github/workflows/checksum-phar.yml' |
| 19 | + |
| 20 | +env: |
| 21 | + COMPOSER_ROOT_VERSION: "1.10.x-dev" |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: checksum-phar-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches |
| 25 | + cancel-in-progress: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + check-phar-checksum: |
| 29 | + name: "Check PHAR checksum" |
| 30 | + |
| 31 | + runs-on: "ubuntu-latest" |
| 32 | + timeout-minutes: 60 |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: "Checkout phpstan-dist" |
| 36 | + uses: actions/checkout@v3 |
| 37 | + with: |
| 38 | + repository: phpstan/phpstan |
| 39 | + path: phpstan-dist |
| 40 | + ref: 1.10.x |
| 41 | + |
| 42 | + - name: "Get info" |
| 43 | + id: info |
| 44 | + working-directory: phpstan-dist |
| 45 | + run: | |
| 46 | + echo "checksum=$(head -n 1 .phar-checksum)" >> $GITHUB_OUTPUT |
| 47 | + echo "commit=$(tail -n 1 .phar-checksum)" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + - name: "Delete phpstan-dist" |
| 50 | + run: "rm -r phpstan-dist" |
| 51 | + |
| 52 | + - name: "Checkout" |
| 53 | + uses: actions/checkout@v3 |
| 54 | + with: |
| 55 | + ref: ${{ steps.info.outputs.commit }} |
| 56 | + |
| 57 | + - name: "Checkout latest PHAR compiler" |
| 58 | + uses: actions/checkout@v3 |
| 59 | + with: |
| 60 | + path: phpstan-src |
| 61 | + ref: ${{ github.sha }} |
| 62 | + |
| 63 | + - name: "Delete old compiler" |
| 64 | + run: "rm -r compiler" |
| 65 | + |
| 66 | + - name: "Move new compiler" |
| 67 | + run: "mv phpstan-src/compiler/ ." |
| 68 | + |
| 69 | + - name: "Delete phpstan-src" |
| 70 | + run: "rm -r phpstan-src" |
| 71 | + |
| 72 | + - name: "Change and commit README.md" |
| 73 | + run: | |
| 74 | + echo Testing > README.md |
| 75 | + git commit -a -m 'Changed README' |
| 76 | +
|
| 77 | + - name: "Install PHP" |
| 78 | + uses: "shivammathur/setup-php@v2" |
| 79 | + with: |
| 80 | + coverage: "none" |
| 81 | + php-version: "8.1" |
| 82 | + extensions: mbstring, intl |
| 83 | + |
| 84 | + - name: "Install dependencies" |
| 85 | + run: "composer install --no-interaction --no-progress" |
| 86 | + |
| 87 | + - name: "Install compiler dependencies" |
| 88 | + run: "composer install --no-interaction --no-progress --working-dir=compiler" |
| 89 | + |
| 90 | + # same steps as in phar.yml |
| 91 | + |
| 92 | + - name: "Prepare for PHAR compilation" |
| 93 | + working-directory: "compiler" |
| 94 | + run: "php bin/prepare" |
| 95 | + |
| 96 | + - name: "Set autoloader suffix" |
| 97 | + run: "composer config autoloader-suffix PHPStanChecksum" |
| 98 | + |
| 99 | + - name: "Composer dump" |
| 100 | + run: "composer install --no-interaction --no-progress" |
| 101 | + env: |
| 102 | + COMPOSER_ROOT_VERSION: "1.10.x-dev" |
| 103 | + |
| 104 | + - name: "Compile PHAR for checksum" |
| 105 | + working-directory: "compiler/build" |
| 106 | + run: "php box.phar compile --no-parallel" |
| 107 | + env: |
| 108 | + PHAR_CHECKSUM: "1" |
| 109 | + COMPOSER_ROOT_VERSION: "1.10.x-dev" |
| 110 | + |
| 111 | + - name: "Re-sign PHAR" |
| 112 | + run: "php compiler/build/resign.php tmp/phpstan.phar" |
| 113 | + |
| 114 | + - name: "Unset autoloader suffix" |
| 115 | + run: "composer config autoloader-suffix --unset" |
| 116 | + |
| 117 | + - name: "Save checksum" |
| 118 | + id: "new_checksum" |
| 119 | + run: echo "md5=$(md5sum tmp/phpstan.phar | cut -d' ' -f1)" >> $GITHUB_OUTPUT |
| 120 | + |
| 121 | + - name: "Assert checksum" |
| 122 | + run: | |
| 123 | + checksum=${{ steps.info.outputs.checksum }} |
| 124 | + new_checksum=${{ steps.new_checksum.outputs.md5 }} |
| 125 | + [[ "$checksum" == "$new_checksum" ]]; |
0 commit comments