Skip to content

Commit 339eeb1

Browse files
authored
Merge pull request #1 from asgrim/initial-version
Initial version of the builder
2 parents 4e9dab7 + bb9cf7f commit 339eeb1

11 files changed

Lines changed: 33723 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Test the Action
2+
on:
3+
push:
4+
pull_request:
5+
6+
env:
7+
RELEASE_TAG: 0.0.0-fake+run_${{ github.run_id }}_${{ github.run_attempt }}
8+
9+
jobs:
10+
check-dist-updated:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v6
15+
16+
- name: Setup Node
17+
uses: actions/setup-node@v6
18+
with:
19+
node-version: 20
20+
cache: 'npm'
21+
22+
- name: Install Dependencies
23+
run: npm ci
24+
25+
- name: Rebuild Dist
26+
run: npm run build
27+
28+
- name: Compare Dist
29+
run: |
30+
if [ -n "$(git status --porcelain dist)" ]; then
31+
echo "dist/ is out of date. Please run 'npm run build' and commit the changes."
32+
exit 1
33+
fi
34+
35+
create-test-release:
36+
runs-on: ubuntu-latest
37+
permissions:
38+
# contents:write is required to upload to the release assets
39+
contents: write
40+
steps:
41+
- uses: actions/checkout@v6
42+
with:
43+
fetch-tags: 'true'
44+
ref: ${{ github.ref }}
45+
46+
- name: Create a fake tag for the build
47+
run: |
48+
git config --global user.email "Fake User"
49+
git config --global user.name "fake-user@example.com"
50+
git tag -a -m "test tag for CI build ${{ github.run_id }}" ${{ env.RELEASE_TAG }}
51+
git push origin ${{ env.RELEASE_TAG }}
52+
53+
- name: Create a fake release for the build
54+
run: gh release create "${{ env.RELEASE_TAG }}" --title "${{ env.RELEASE_TAG }}" --draft --notes-from-tag
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
58+
test-action:
59+
runs-on: ${{ matrix.operating-system }}
60+
needs: [create-test-release]
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
operating-system:
65+
- ubuntu-latest
66+
- ubuntu-24.04-arm
67+
- macos-15-intel
68+
- macos-latest
69+
php-versions:
70+
# - 5.6 @todo test ext doesn't currently build on 5.6
71+
- 7.0
72+
- 7.1
73+
- 7.2
74+
- 7.3
75+
- 7.4
76+
- 8.0
77+
- 8.1
78+
- 8.2
79+
- 8.3
80+
- 8.4
81+
zts-mode:
82+
- ts
83+
- nts
84+
permissions:
85+
# contents:write is required to upload to the release assets
86+
contents: write
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v6
90+
91+
- name: Checkout
92+
uses: actions/checkout@v6
93+
with:
94+
repository: asgrim/example-pie-extension
95+
path: ext
96+
97+
- name: Move test ext files
98+
run: |
99+
mv ext/composer.json .
100+
mv ext/config.m4 .
101+
mv ext/php_example_pie_extension.h .
102+
mv ext/zend_example_pie_extension.c .
103+
104+
- name: Setup PHP
105+
uses: shivammathur/setup-php@v2
106+
with:
107+
php-version: ${{ matrix.php-versions }}
108+
env:
109+
# debug: ${{ matrix.zend-debug }} @todo may not be able to use https://github.com/shivammathur/setup-php/issues/816
110+
phpts: ${{ matrix.zts-mode }}
111+
112+
- name: Run the action
113+
id: pie-ext-binary-builder
114+
uses: ./
115+
with:
116+
configure-flags: '--with-hello-name=FROM_MY_ACTION --enable-example-pie-extension'
117+
release-tag: ${{ env.RELEASE_TAG }}
118+
github-token: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- name: Check Output
121+
run: |
122+
echo "Package path: ${{ steps.pie-ext-binary-builder.outputs.package-path }}"
123+
ls -l
124+
125+
delete-test-release:
126+
runs-on: ubuntu-latest
127+
if: always()
128+
needs: [test-action]
129+
steps:
130+
- name: Checkout
131+
uses: actions/checkout@v6
132+
133+
- name: Delete test release
134+
run: |
135+
if gh release view "${{ env.RELEASE_TAG }}" > /dev/null 2>&1; then
136+
gh release delete "${{ env.RELEASE_TAG }}" --yes --cleanup-tag
137+
else
138+
echo "Release ${{ env.RELEASE_TAG }} does not exist, skipping deletion."
139+
fi
140+
env:
141+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.idea
3+
.DS_Store

README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
```

action.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'PIE Pre-Packaged Binary Action'
2+
description: 'Build and upload a PIE pre-packaged binary with the expected naming conventions.'
3+
inputs:
4+
configure-flags:
5+
description: 'Flags to pass to ./configure'
6+
required: false
7+
default: ''
8+
release-tag:
9+
description: 'The tag to use for the release'
10+
required: true
11+
github-token:
12+
description: 'The GitHub token to use for uploading assets'
13+
required: true
14+
outputs:
15+
package-path:
16+
description: 'Path to the generated .tgz package'
17+
runs:
18+
using: 'node20'
19+
main: dist/index.js

0 commit comments

Comments
 (0)