|
| 1 | +# Generate Pre-Packaged Binaries for PIE Extensions |
| 2 | + |
| 3 | +This is a GitHub action designed to help generate pre-packaged binaries for |
| 4 | +[PIE (PHP Installer for Extensions)](https://github.com/php/pie) extensions and attach |
| 5 | +them to your GitHub releases. It will: |
| 6 | + |
| 7 | + - Build a `.so` from your extension |
| 8 | + - Package the `.so` in an archive, and name it according to PIE's expectations |
| 9 | + - Upload the archive to your GitHub release |
| 10 | + |
| 11 | +> [!TIP] |
| 12 | +> Looking for Windows support? You probably want [`php/php-windows-builder`](https://github.com/php/php-windows-builder) |
| 13 | +
|
| 14 | +## The Action |
| 15 | + |
| 16 | +You must specify a `release-tag`. This is a tag, for which you have created |
| 17 | +a release ready for the action to upload the builds to. |
| 18 | + |
| 19 | +> [!IMPORTANT] |
| 20 | +> If you have enabled immutable releases on your repository, the release must be |
| 21 | +> a draft release, otherwise uploading the assets will fail. |
| 22 | +
|
| 23 | +```yaml |
| 24 | +uses: php/php-ext-binary-builder@v1 |
| 25 | +with: |
| 26 | + configure-flags: '--enable-something --enable-other-things' |
| 27 | + release-tag: ${{ github.ref_name }} |
| 28 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | +``` |
| 30 | +
|
| 31 | +### Inputs |
| 32 | +
|
| 33 | +| Name | Description | Required | Default | |
| 34 | +|-------------------|-------------------------------------------------------------------------------------------------|----------|---------| |
| 35 | +| `release-tag` | The tag to use when building the extension; there must be an existing draft release for the tag | `true` | - | |
| 36 | +| `github-token` | The GitHub token to use. Usually `${{ secrets.GITHUB_TOKEN }}` would be fine for most cases. | `true` | - | |
| 37 | +| `configure-flags` | If you need to pass additional flags to the `./configure` command, specify them here | `false` | `''` | |
| 38 | + |
| 39 | +### Outputs |
| 40 | + |
| 41 | +| Name | Description | |
| 42 | +|----------------|-----------------------------------| |
| 43 | +| `package-path` | Path to the generated `.tgz` file | |
| 44 | + |
| 45 | +## Complete example |
| 46 | + |
| 47 | +This use case is for a scenario where: |
| 48 | + |
| 49 | + - The action triggers when you push any tag |
| 50 | + - It will create a draft release |
| 51 | + - It will then check out your extension, set up the required PHP version, build it, and upload to the draft release |
| 52 | + |
| 53 | +You would then have to navigate to the draft release and publish it. |
| 54 | + |
| 55 | +```yaml |
| 56 | +name: Build and release binaries for PIE |
| 57 | +
|
| 58 | +on: |
| 59 | + push: |
| 60 | + tags: |
| 61 | + - '*' |
| 62 | +
|
| 63 | +permissions: |
| 64 | + contents: read |
| 65 | +
|
| 66 | +jobs: |
| 67 | + # This first step will create a *draft* release based on the tag name. In the |
| 68 | + # case where immutable releases are enabled, the release MUST be in draft |
| 69 | + # mode, otherwise we would not be able to attach the release assets (since |
| 70 | + # the release is immutable once published. |
| 71 | + create-draft-release: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: |
| 74 | + - build-assets |
| 75 | + permissions: |
| 76 | + # contents:write is required to create the draft release |
| 77 | + contents: write |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v6 |
| 80 | + with: |
| 81 | + fetch-tags: 'true' |
| 82 | + ref: ${{ github.ref }} |
| 83 | + - name: Create draft release from tag |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ github.token }} |
| 86 | + run: gh release create "${{ github.ref_name }}" --title "${{ github.ref_name }}" --draft --notes-from-tag |
| 87 | +
|
| 88 | + add-pie-binaries: |
| 89 | + runs-on: ${{ matrix.operating-system }} |
| 90 | + # The matrix defines which combination of binaries you want to build |
| 91 | + strategy: |
| 92 | + matrix: |
| 93 | + operating-system: |
| 94 | + - ubuntu-latest |
| 95 | + - macos-latest |
| 96 | + php-versions: |
| 97 | + - 8.2 |
| 98 | + - 8.3 |
| 99 | + - 8.4 |
| 100 | + zts-mode: |
| 101 | + - ts |
| 102 | + - nts |
| 103 | + permissions: |
| 104 | + # contents:write is required to upload to the release assets |
| 105 | + contents: write |
| 106 | + steps: |
| 107 | + - name: Checkout |
| 108 | + uses: actions/checkout@v6 |
| 109 | +
|
| 110 | + # Install the desired version of PHP in order to build the extension for it |
| 111 | + - name: Setup PHP |
| 112 | + uses: shivammathur/setup-php@v2 |
| 113 | + with: |
| 114 | + php-version: ${{ matrix.php-versions }} |
| 115 | + env: |
| 116 | + phpts: ${{ matrix.zts-mode }} |
| 117 | +
|
| 118 | + # Finally, this invokes the action, which builds the extension, creates |
| 119 | + # the archive with the correct naming, and uploads it to the release for |
| 120 | + # the given tag name |
| 121 | + - name: Build and release |
| 122 | + id: php-ext-binary-builder |
| 123 | + uses: php/php-ext-binary-builder@v1 |
| 124 | + with: |
| 125 | + release-tag: ${{ github.ref_name }} |
| 126 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 127 | +``` |
0 commit comments