Skip to content

Commit 726ee1b

Browse files
feat: Convert to a Platform package (#6)
* feat: Convert to a platform package * temp: Print windows info * revert: Remove temp info printed * feat: Use production package installer
1 parent 18f5b12 commit 726ee1b

35 files changed

+270
-151
lines changed

.github/workflows/release.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: Create Platform-Specific Artifacts
2+
3+
on:
4+
release:
5+
types: [ published, created, edited, prereleased ]
6+
7+
workflow_dispatch:
8+
inputs:
9+
release_tag:
10+
description: 'Release tag to build artifacts for'
11+
required: false
12+
type: string
13+
14+
jobs:
15+
prepare-artifacts:
16+
runs-on: ubuntu-latest
17+
18+
outputs:
19+
platforms: ${{ steps.generate-matrix.outputs.platforms }}
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.event.inputs.release_tag || github.ref }}
26+
27+
- name: Install yq
28+
run: |
29+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
30+
chmod +x /usr/local/bin/yq
31+
32+
- name: Generate Build Matrix
33+
id: generate-matrix
34+
run: |
35+
# Extract platforms from platforms.yml
36+
platforms=$(yq -o=json 'keys' platforms.yml)
37+
echo "platforms=$(echo $platforms | jq -c '. | map(split("/")[0]) | unique')" >> $GITHUB_OUTPUT
38+
39+
build-artifacts:
40+
needs: prepare-artifacts
41+
42+
runs-on: ubuntu-latest
43+
44+
strategy:
45+
matrix:
46+
platform: ${{ fromJson(needs.prepare-artifacts.outputs.platforms) }}
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
with:
52+
ref: ${{ github.event.inputs.release_tag || github.ref }}
53+
54+
- name: Install yq
55+
run: |
56+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
57+
chmod +x /usr/local/bin/yq
58+
59+
- name: Create Platform-Specific Artifact
60+
run: |
61+
# Prepare exclusion list
62+
if [ -f ".gitignore" ]; then
63+
cp .gitignore rsync_exclude.txt
64+
else
65+
touch rsync_exclude.txt
66+
fi
67+
68+
# Add platform-specific exclusions from platforms.yml
69+
echo "" >> rsync_exclude.txt
70+
yq e ".\"${{ matrix.platform }}\".exclude[]" platforms.yml >> rsync_exclude.txt
71+
72+
# Add standard exclusions
73+
echo ".git" >> rsync_exclude.txt
74+
echo ".github" >> rsync_exclude.txt
75+
echo "rsync_exclude.txt" >> rsync_exclude.txt
76+
77+
# Copy files using rsync with exclusions
78+
DIST_DIR="dist-${{ matrix.platform }}"
79+
mkdir -p "$DIST_DIR"
80+
echo "$DIST_DIR" >> rsync_exclude.txt
81+
rsync -av --exclude-from=rsync_exclude.txt ./ "$DIST_DIR"/
82+
83+
# Compress artifact
84+
if [[ "${{ matrix.platform }}" == windows-* ]]; then
85+
zip -r "dist-${{ matrix.platform }}.zip" "$DIST_DIR"
86+
ARTIFACT_EXT="zip"
87+
else
88+
tar -czvf "dist-${{ matrix.platform }}.tar.gz" "$DIST_DIR"
89+
ARTIFACT_EXT="tar.gz"
90+
fi
91+
92+
echo "Artifact created: dist-${{ matrix.platform }}.$ARTIFACT_EXT"
93+
94+
- name: Upload Artifact to Release
95+
uses: softprops/action-gh-release@v2
96+
if: startsWith(github.ref, 'refs/tags/')
97+
with:
98+
files: dist-*
99+
100+
- name: Upload Artifact to Artifact Hub
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: dist-${{ matrix.platform }}
104+
path: dist-*
105+
retention-days: 1
106+
107+
create-release-metadata:
108+
needs: [ prepare-artifacts, build-artifacts ]
109+
110+
runs-on: ubuntu-latest
111+
112+
steps:
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
with:
116+
ref: ${{ github.event.inputs.release_tag || github.ref }}
117+
118+
- name: Install yq
119+
run: |
120+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
121+
chmod +x /usr/local/bin/yq
122+
123+
- name: Generate Platform URLs Metadata
124+
run: |
125+
# Prepare variables
126+
RELEASE_TAG="${{ github.event.inputs.release_tag || github.ref }}"
127+
REPO="${{ github.repository }}"
128+
129+
# Start JSON structure
130+
echo "{" > platform-urls.json
131+
echo ' "platform-urls": {' >> platform-urls.json
132+
133+
# Generate URLs for each platform
134+
FIRST=true
135+
platforms=$(yq -o=json 'keys' platforms.yml | jq -r '.[]')
136+
for platform in $platforms; do
137+
if [ "$FIRST" = true ]; then
138+
FIRST=false
139+
else
140+
echo "," >> platform-urls.json
141+
fi
142+
143+
# Determine file extension
144+
if [[ "$platform" == windows-* ]]; then
145+
EXT="zip"
146+
else
147+
EXT="tar.gz"
148+
fi
149+
150+
# Generate URL
151+
printf ' "%s": "https://github.com/%s/releases/download/%s/dist-%s.%s"' \
152+
"$platform" "$REPO" "$RELEASE_TAG" "$platform" "$EXT" >> platform-urls.json
153+
done
154+
155+
# Close JSON structure
156+
echo "" >> platform-urls.json
157+
echo ' }' >> platform-urls.json
158+
echo "}" >> platform-urls.json
159+
160+
cat platform-urls.json
161+
162+
- name: Upload Platform URLs Metadata
163+
uses: softprops/action-gh-release@v2
164+
if: startsWith(github.ref, 'refs/tags/')
165+
with:
166+
files: platform-urls.json

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
matrix:
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
php: [8.1, 8.2, 8.3, 8.4]
14+
max-parallel: 4
1415

1516
name: Tests PHP${{ matrix.php }} - ${{ matrix.os }}
1617

composer.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "codewithkyrian/whisper.php",
33
"description": "PHP bindings for OpenAI Whisper made possible by whisper.cpp",
4-
"type": "library",
4+
"type": "platform-package",
55
"version": "1.0.0",
66
"require": {
77
"php": "^8.1",
88
"ext-ffi": "*",
9-
"psr/log": "^3.0"
9+
"psr/log": "^3.0",
10+
"codewithkyrian/platform-package-installer": "^1.0"
1011
},
1112
"require-dev": {
1213
"symfony/var-dumper": "^6.4.11|^7.1.5",
@@ -35,7 +36,18 @@
3536
],
3637
"config": {
3738
"allow-plugins": {
38-
"pestphp/pest-plugin": true
39+
"pestphp/pest-plugin": true,
40+
"codewithkyrian/platform-package-installer": true
41+
}
42+
},
43+
"extra": {
44+
"platform-urls": {
45+
"linux-x86_64": "https://github.com/Codewithkyrian/whisper.php/releases/download/{version}/dist-linux-x86_64.tar.gz",
46+
"linux-arm64": "https://github.com/Codewithkyrian/whisper.php/releases/download/{version}/dist-linux-arm64.tar.gz",
47+
"darwin-x86_64": "https://github.com/Codewithkyrian/whisper.php/releases/download/{version}/dist-darwin-x86_64.tar.gz",
48+
"darwin-arm64": "https://github.com/Codewithkyrian/whisper.php/releases/download/{version}/dist-darwin-arm64.tar.gz",
49+
"windows-x86_64": "https://github.com/Codewithkyrian/whisper.php/releases/download/{version}/dist-windows-x86_64.zip",
50+
"windows-arm64": "https://github.com/Codewithkyrian/whisper.php/releases/download/{version}/dist-windows-arm64.zip"
3951
}
4052
}
4153
}

lib/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
939 KB
Binary file not shown.
105 KB
Binary file not shown.

lib/darwin-arm64/libggml-cpu.dylib

644 KB
Binary file not shown.
1010 KB
Binary file not shown.

lib/darwin-arm64/libggml.dylib

68.3 KB
Binary file not shown.
1.47 MB
Binary file not shown.

0 commit comments

Comments
 (0)