Skip to content

Commit ebdb37d

Browse files
authored
Merge pull request #5 from cypherbits/feat/CI-build-and-fixes
Feat/ci build and fixes
2 parents c269f1a + 2ba54cb commit ebdb37d

File tree

2 files changed

+128
-3
lines changed

2 files changed

+128
-3
lines changed

.github/workflows/release.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Release PHP BLAKE3 Extension
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
name: Build extension for PHP ${{ matrix.php }}
14+
runs-on: ubuntu-24.04
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php: [ '8.3', '8.4']
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Verify tag points to master
26+
run: |
27+
set -euo pipefail
28+
git fetch --no-tags --depth=1 origin master
29+
if git merge-base --is-ancestor origin/master "$GITHUB_SHA"; then
30+
echo "Tag commit is on master (or descendant). Proceeding."
31+
else
32+
echo "This tag is not on master. Exiting." >&2
33+
exit 1
34+
fi
35+
36+
- name: Add ondrej/php PPA and install build dependencies
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y software-properties-common lsb-release ca-certificates curl git build-essential autoconf automake libtool pkg-config dpkg-dev
40+
sudo add-apt-repository -y ppa:ondrej/php
41+
sudo apt-get update
42+
sudo apt-get install -y php${{ matrix.php }} php${{ matrix.php }}-dev
43+
44+
- name: Build extension (PHP ${{ matrix.php }})
45+
env:
46+
PHP_VER: ${{ matrix.php }}
47+
run: |
48+
set -euo pipefail
49+
PHP_BIN="php${PHP_VER}"
50+
PHPIZE_BIN="phpize${PHP_VER}"
51+
PHP_CONFIG_BIN="php-config${PHP_VER}"
52+
53+
"${PHP_BIN}" -v || { echo "PHP ${PHP_VER} not available" >&2; exit 1; }
54+
"${PHPIZE_BIN}" --version || { echo "phpize ${PHP_VER} not available" >&2; exit 1; }
55+
"${PHP_CONFIG_BIN}" --version || { echo "php-config ${PHP_VER} not available" >&2; exit 1; }
56+
57+
# Prepare and build
58+
"${PHPIZE_BIN}"
59+
./configure --enable-blake3 --with-php-config="$(command -v "${PHP_CONFIG_BIN}")"
60+
make -j"$(nproc)"
61+
62+
# Save raw .so from build dir
63+
if [ -f modules/blake3.so ]; then
64+
DIST_ID=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
65+
DIST_CODENAME=$(lsb_release -cs)
66+
cp modules/blake3.so blake3-${DIST_ID}-${DIST_CODENAME}-php${PHP_VER}-amd64.so
67+
else
68+
echo "Error: modules/blake3.so not found" >&2; exit 1
69+
fi
70+
71+
# Install to system (so php-config ext dir exists even if not)
72+
sudo make install
73+
EXT_DIR="$(${PHP_CONFIG_BIN} --extension-dir)"
74+
echo "Extension dir: $EXT_DIR"
75+
76+
# Prepare Debian package structure
77+
TAG_NAME="${GITHUB_REF_NAME}"
78+
PKG_VERSION="${TAG_NAME#v}"
79+
STAGING="pkgroot"
80+
mkdir -p "${STAGING}${EXT_DIR}"
81+
cp modules/blake3.so "${STAGING}${EXT_DIR}/blake3.so"
82+
83+
mkdir -p "${STAGING}/DEBIAN"
84+
printf "Package: php-blake3\nVersion: %s-php%s\nSection: php\nPriority: optional\nArchitecture: amd64\nMaintainer: php-blake3 maintainers\nDescription: BLAKE3 hashing extension for PHP (built for PHP %s)\n" "${PKG_VERSION}" "${PHP_VER}" "${PHP_VER}" > "${STAGING}/DEBIAN/control"
85+
86+
# Build .deb
87+
DIST_ID=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
88+
DIST_CODENAME=$(lsb_release -cs)
89+
DEB_NAME="php-blake3_${PKG_VERSION}_${DIST_ID}-${DIST_CODENAME}_php${PHP_VER}_amd64.deb"
90+
dpkg-deb --build --root-owner-group "${STAGING}" "${DEB_NAME}"
91+
92+
- name: Upload artifacts
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: php-blake3-php${{ matrix.php }}
96+
path: |
97+
blake3-*-php${{ matrix.php }}-amd64.so
98+
php-blake3_*_php${{ matrix.php }}_amd64.deb
99+
if-no-files-found: error
100+
101+
release:
102+
name: Publish GitHub Release
103+
runs-on: ubuntu-24.04
104+
needs: build
105+
steps:
106+
- name: Download all build artifacts
107+
uses: actions/download-artifact@v4
108+
with:
109+
path: artifacts
110+
111+
- name: List downloaded artifacts
112+
run: ls -R artifacts | sed -n '1,200p'
113+
114+
- name: Create Release and Upload Assets
115+
uses: softprops/action-gh-release@v2
116+
with:
117+
tag_name: ${{ github.ref_name }}
118+
name: ${{ github.ref_name }}
119+
draft: false
120+
prerelease: false
121+
files: |
122+
artifacts/**/blake3-*-php*-amd64.so
123+
artifacts/**/php-blake3_*_php*_amd64.deb
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PHP BLAKE3 Extension
33

44
BLAKE3 is an improved and faster version of BLAKE2.
55

6-
This extension uses the official BLAKE3 C implementation, thus is single-threaded, but still faster than SHA256 or SHA512 on my benchmark on latest PHP 7.4.
6+
This extension uses the official BLAKE3 C implementation, thus is single-threaded, but still faster than SHA256 or SHA512 on my benchmark on PHP 7.4.
77

88
Installation
99
------------
@@ -35,11 +35,11 @@ Usage
3535
**Functions:**
3636

3737
```php
38-
string blake3 ( string $str [, int $outputSize = 64, string $key, bool $rawOutput = false ] )
38+
string blake3 ( string $str [, int $outputSize = 32, string $key, bool $rawOutput = false ] )
3939
```
4040

4141
* $str: The string to hash
42-
* $outputSize: The length of the output hash (can be between 1 and 64)
42+
* $outputSize: The length of the output hash in bytes (must be >= 1). BLAKE3 supports extendable output so larger values are allowed; the default is 32 bytes.
4343
* $key: Turns the output into a keyed hash using the specified key. It MUST be of 32 bytes long.
4444
* $rawOutput: If set to true, then the hash is returned in raw binary format
4545

0 commit comments

Comments
 (0)