|
| 1 | +# Invoking this pipeline requires additional permissions, so must be invoked |
| 2 | +# in a way to pass those permissions on, e.g.: |
| 3 | +# |
| 4 | +# build-assets: |
| 5 | +# permissions: |
| 6 | +# contents: read |
| 7 | +# id-token: write |
| 8 | +# attestations: write |
| 9 | +# uses: ./.github/workflows/build-assets.yml |
| 10 | + |
| 11 | +name: "Build the PIE assets" |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_call: |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-phar: |
| 21 | + runs-on: ${{ matrix.operating-system }} |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + operating-system: |
| 25 | + - ubuntu-latest |
| 26 | + php-versions: |
| 27 | + - '8.1' |
| 28 | + permissions: |
| 29 | + # id-token:write is required for build provenance attestation. |
| 30 | + id-token: write |
| 31 | + # attestations:write is required for build provenance attestation. |
| 32 | + attestations: write |
| 33 | + steps: |
| 34 | + - name: Setup PHP |
| 35 | + uses: shivammathur/setup-php@v2 |
| 36 | + with: |
| 37 | + coverage: none |
| 38 | + tools: composer, box |
| 39 | + php-version: "${{ matrix.php-version }}" |
| 40 | + - uses: actions/checkout@v6 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + # Fixes `git describe` picking the wrong tag - see https://github.com/php/pie/issues/307 |
| 44 | + - run: git fetch --tags --force |
| 45 | + # Ensure some kind of previous tag exists, otherwise box fails |
| 46 | + - run: git describe --tags HEAD || git tag 0.0.0 |
| 47 | + - uses: ramsey/composer-install@v3 |
| 48 | + - name: Build PHAR |
| 49 | + run: box compile |
| 50 | + - name: Check the PHAR executes |
| 51 | + run: php pie.phar --version |
| 52 | + - name: Generate build provenance attestation |
| 53 | + # It does not make sense to do this for PR builds, nor do contributors |
| 54 | + # have permission to do. We can't write attestations to `php/pie` in an |
| 55 | + # unprivileged context, otherwise anyone could send a PR with malicious |
| 56 | + # code, which would store attestation that `php/pie` built the PHAR, and |
| 57 | + # it would look genuine. So this should NOT run for PR builds. |
| 58 | + if: github.event_name != 'pull_request' |
| 59 | + uses: actions/attest-build-provenance@v3 |
| 60 | + with: |
| 61 | + subject-path: '${{ github.workspace }}/pie.phar' |
| 62 | + - uses: actions/upload-artifact@v5 |
| 63 | + with: |
| 64 | + name: pie-${{ github.sha }}.phar |
| 65 | + path: pie.phar |
| 66 | + |
| 67 | + build-executable: |
| 68 | + needs: |
| 69 | + - build-phar |
| 70 | + runs-on: ${{ matrix.operating-system }} |
| 71 | + strategy: |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + operating-system: |
| 75 | + - ubuntu-24.04 |
| 76 | + - ubuntu-24.04-arm |
| 77 | + - macos-15-intel |
| 78 | + - macos-26 |
| 79 | + - windows-2025 |
| 80 | + permissions: |
| 81 | + # id-token:write is required for build provenance attestation. |
| 82 | + id-token: write |
| 83 | + # attestations:write is required for build provenance attestation. |
| 84 | + attestations: write |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v6 |
| 87 | + |
| 88 | + - name: Download SPC (non-Windows) |
| 89 | + if: runner.os != 'Windows' |
| 90 | + run: | |
| 91 | + # @todo find a better way to do this :/ |
| 92 | + # Source URL: https://static-php.dev/en/guide/manual-build.html#build-locally-using-spc-binary-recommended |
| 93 | + case "${{ matrix.operating-system }}" in |
| 94 | + ubuntu-24.04) |
| 95 | + curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64 |
| 96 | + ;; |
| 97 | +
|
| 98 | + ubuntu-24.04-arm) |
| 99 | + curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64 |
| 100 | + ;; |
| 101 | +
|
| 102 | + macos-15-intel) |
| 103 | + curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64 |
| 104 | + ;; |
| 105 | +
|
| 106 | + macos-26) |
| 107 | + curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64 |
| 108 | + ;; |
| 109 | +
|
| 110 | + *) |
| 111 | + echo "unsupported operating system: ${{ matrix.operating-system }}" |
| 112 | + exit 1 |
| 113 | + ;; |
| 114 | + esac |
| 115 | + chmod +x spc |
| 116 | + echo "SPC_BINARY=./spc" >> $GITHUB_ENV |
| 117 | + echo "PIE_BINARY_OUTPUT=pie-${{ runner.os }}-${{ runner.arch }}" >> $GITHUB_ENV |
| 118 | + - name: Download SPC (Windows) |
| 119 | + if: runner.os == 'Windows' |
| 120 | + run: | |
| 121 | + curl.exe -fsSL -o spc.exe https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe |
| 122 | + chmod +x spc.exe |
| 123 | + echo "SPC_BINARY=.\spc.exe" >> $env:GITHUB_ENV |
| 124 | + echo "PIE_BINARY_OUTPUT=pie-${{ runner.os }}-${{ runner.arch }}.exe" >> $env:GITHUB_ENV |
| 125 | +
|
| 126 | + - name: Grab the pie.phar from artifacts |
| 127 | + uses: actions/download-artifact@v5 |
| 128 | + with: |
| 129 | + name: pie-${{ github.sha }}.phar |
| 130 | + |
| 131 | + - name: Build for ${{ runner.os }} ${{ runner.arch }} on ${{ matrix.operating-system }} |
| 132 | + run: ${{ env.SPC_BINARY }} craft resources/spc/craft.yml |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + - name: Bundle pie.phar into executable PIE binary |
| 136 | + run: ${{ env.SPC_BINARY }} micro:combine pie.phar --output=${{ env.PIE_BINARY_OUTPUT }} |
| 137 | + |
| 138 | + - name: Setup PHP |
| 139 | + uses: shivammathur/setup-php@v2 |
| 140 | + with: |
| 141 | + coverage: none |
| 142 | + tools: composer |
| 143 | + php-version: "7.4" |
| 144 | + - name: Quick validation that the binary runs |
| 145 | + run: ./${{ env.PIE_BINARY_OUTPUT }} show --all |
| 146 | + |
| 147 | + - name: Generate build provenance attestation |
| 148 | + # It does not make sense to do this for PR builds, nor do contributors |
| 149 | + # have permission to do. We can't write attestations to `php/pie` in an |
| 150 | + # unprivileged context, otherwise anyone could send a PR with malicious |
| 151 | + # code, which would store attestation that `php/pie` built the binaries, |
| 152 | + # and it would look genuine. So this should NOT run for PR builds. |
| 153 | + if: github.event_name != 'pull_request' |
| 154 | + uses: actions/attest-build-provenance@v3 |
| 155 | + with: |
| 156 | + subject-path: '${{ github.workspace }}/${{ env.PIE_BINARY_OUTPUT }}' |
| 157 | + |
| 158 | + - uses: actions/upload-artifact@v5 |
| 159 | + with: |
| 160 | + name: pie-${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}.bin |
| 161 | + path: ${{ env.PIE_BINARY_OUTPUT }} |
0 commit comments