Skip to content

Commit c1e97ee

Browse files
committed
Released Version 0.1.0
1 parent 7aaeccd commit c1e97ee

File tree

7 files changed

+183
-0
lines changed

7 files changed

+183
-0
lines changed

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release workflow
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags: "*"
9+
10+
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Create Release
15+
uses: softprops/action-gh-release@v2
16+
id: create_release
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
build:
20+
runs-on: ubuntu-latest
21+
needs: prepare
22+
strategy:
23+
max-parallel: 1
24+
matrix:
25+
arch:
26+
- amd64
27+
- arm64
28+
php_version:
29+
- "7.2"
30+
- "7.3"
31+
- "7.4"
32+
- "8.0"
33+
- "8.1"
34+
- "8.2"
35+
- "8.3"
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
- name: Set up QEMU
40+
uses: docker/setup-qemu-action@v1
41+
with:
42+
platforms: linux/${{ matrix.arch }}
43+
- name: Build nop_${{ matrix.arch }}_${{ matrix.php_version }}.so.out
44+
run: |
45+
docker run \
46+
--rm \
47+
-v ${{ github.workspace }}:/workspace \
48+
-w /workspace \
49+
--platform linux/${{ matrix.arch }} \
50+
php:${{ matrix.php_version }}-cli \
51+
./scripts/build-extension
52+
- name: Generate nfpm.${{ matrix.arch }}.${{ matrix.php_version }}.yaml
53+
run: ./scripts/nfpm-template
54+
env:
55+
VERSION: ${{ github.ref_name }}
56+
ARCH: ${{ matrix.arch }}
57+
PHP_VERSION: ${{ matrix.php_version }}
58+
- name: Package php${{ matrix.php_version }}-nop_${{ matrix.arch }}_${{ github.ref_name }}.deb
59+
run: |
60+
docker run \
61+
--rm \
62+
-v ${{ github.workspace }}:/workspace \
63+
-w /workspace \
64+
--platform linux/${{ matrix.arch }} \
65+
goreleaser/nfpm:v2.41.0 \
66+
pkg \
67+
--packager deb \
68+
--config nfpm.${{ matrix.arch }}.${{ matrix.php_version }}.yaml \
69+
--target ./private/php${{ matrix.php_version }}-nop_${{ matrix.arch }}_${{ github.ref_name }}.deb
70+
- name: Upload php${{ matrix.php_version }}-nop_${{ matrix.arch }}_${{ github.ref_name }}.deb
71+
id: upload-release-asset
72+
uses: softprops/action-gh-release@v2
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
with:
76+
files: ./private/php${{ matrix.php_version }}-nop_${{ matrix.arch }}_${{ github.ref_name }}.deb

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Files
22

33
.DS_Store
4+
*.deb
45

56
# Directories
67

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ php -d 'extension=nop.so' -d 'nop.functions=' -r 'printf ("hi\n");'
3636
php -d 'extension=nop.so' -d 'nop.functions=printf' -r 'printf ("hi\n");'
3737
```
3838

39+
## Package Extension
40+
41+
```shell
42+
# Build all inside docker container
43+
./scripts/build-all
44+
45+
# Package for Debian
46+
nfpm pkg --packager deb --target ./private/php8.3-nop_0.1.0_arm64.deb
47+
```
48+
3949
## Additional Resources
4050

4151
- https://www.phpinternalsbook.com/
4252
- https://www.zend.com/sites/zend/files/pdfs/whitepaper-zend-php-extensions.pdf
53+
- https://www.zend.com/resources/writing-php-extensions

conf/nop.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; php-nop
2+
extension=nop.so
3+
4+
; comma separated list of functions
5+
nop.functions=

nfpm.template.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: php-nop
2+
arch: ${ARCH}
3+
platform: linux
4+
version: ${VERSION}
5+
section: php
6+
priority: optional
7+
maintainer: Rafael Grigorian <rafael@grigorian.org>
8+
homepage: https://github.com/null93/php-nop
9+
license: MIT
10+
description: PHP extension that replaces any function with a NOP function
11+
contents:
12+
- src: private/shared-objects/nop_${ARCH}_${PHP_VERSION}.so.out
13+
dst: /usr/lib/php/$PHP_API_VERSION/nop.so
14+
file_info:
15+
mode: 0755
16+
- src: conf/nop.ini
17+
dst: /etc/php/${PHP_VERSION}/mods-available/nop.ini
18+
type: config
19+
depends:
20+
- php-common (>= ${PHP_VERSION})

scripts/build-extension

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
arch=`uname -a | grep -q 'x86_64' && echo 'amd64' || echo 'arm64'`
4+
php_version=`php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;'`
5+
output_path="./private/shared-objects/nop_${arch}_${php_version}.so.out"
6+
7+
echo "BUILDING: ${arch} php-${php_version})"
8+
9+
# configure the build
10+
11+
phpize
12+
./configure
13+
14+
# build the extension and test
15+
16+
make
17+
make install
18+
NO_INTERACTION=true make test
19+
20+
# stash the shared object
21+
22+
mkdir -p ./private/shared-objects
23+
mv ./modules/nop.so "${output_path}"
24+
25+
# clean up
26+
27+
make clean
28+
29+
# output file path
30+
31+
echo
32+
echo "OUTPUT: ${output_path}"
33+
echo
34+
ls -la "${output_path}"

scripts/nfpm-template

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
if [[ "$VERSION" = "" ]]; then
4+
echo "Error: VERSION is not set"
5+
exit 1
6+
fi
7+
8+
if [[ "$PHP_VERSION" = "" ]]; then
9+
echo "Error: PHP_VERSION is not set"
10+
exit 1
11+
fi
12+
13+
if [[ "$ARCH" = "" ]]; then
14+
echo "Error: ARCH is not set"
15+
exit 1
16+
fi
17+
18+
php_api_versions_map=`cat << EOF
19+
7.2=20170718
20+
7.3=20180731
21+
7.4=20190902
22+
8.0=20200930
23+
8.1=20210902
24+
8.2=20220829
25+
8.3=20230831
26+
EOF`
27+
28+
export PHP_API_VERSION=`echo "$php_api_versions_map" | grep -E "^${PHP_VERSION}=" | cut -d '=' -f 2 | xargs`
29+
30+
if [[ "$PHP_API_VERSION" = "" ]]; then
31+
echo "Error: PHP_API_VERSION is not set"
32+
exit 1
33+
fi
34+
35+
envsubst < nfpm.template.yaml > "nfpm.${ARCH}.${PHP_VERSION}.yaml"
36+
cat "nfpm.${ARCH}.${PHP_VERSION}.yaml"

0 commit comments

Comments
 (0)