-
Notifications
You must be signed in to change notification settings - Fork 1
327 lines (276 loc) · 11.4 KB
/
ci.yml
File metadata and controls
327 lines (276 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
name: CI
on:
push:
branches: [ main ]
pull_request:
jobs:
dotnet-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build managed projects
run: dotnet build --configuration Release --no-restore
native-linux:
needs: dotnet-build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake libopenblas-dev liblapack-dev
- name: Configure native build
run: cmake -S native -B native/build/linux -DCMAKE_BUILD_TYPE=Release
- name: Build native library
run: cmake --build native/build/linux --target mlxsharp --config Release
- name: Package native artifact
run: |
mkdir -p artifacts/native/linux-x64
cp native/build/linux/libmlxsharp.so artifacts/native/linux-x64/
- name: Upload native artifact
uses: actions/upload-artifact@v4
with:
name: native-linux-x64
path: artifacts/native/linux-x64/libmlxsharp.so
native-macos:
needs: dotnet-build
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install CMake
run: brew install cmake
- name: Configure native build
run: cmake -S native -B native/build/macos -DCMAKE_BUILD_TYPE=Release
- name: Build native library
run: cmake --build native/build/macos --target mlxsharp --config Release
- name: Package native artifact
run: |
mkdir -p artifacts/native/osx-arm64
cp native/build/macos/libmlxsharp.dylib artifacts/native/osx-arm64/
- name: Upload native artifact
uses: actions/upload-artifact@v4
with:
name: native-osx-arm64
path: artifacts/native/osx-arm64/libmlxsharp.dylib
package-test:
needs:
- native-linux
- native-macos
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Show .NET info
run: dotnet --info
- name: Restore dependencies
run: dotnet restore
- name: Build C# projects (initial validation)
run: dotnet build --configuration Release --no-restore
- name: Setup Python for HuggingFace
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install HuggingFace CLI
run: pip install huggingface_hub
- name: Download test model from HuggingFace
run: |
mkdir -p models
huggingface-cli download mlx-community/Qwen1.5-0.5B-Chat-4bit --local-dir models/Qwen1.5-0.5B-Chat-4bit
echo "Model files:"
ls -la models/Qwen1.5-0.5B-Chat-4bit/
- name: Download macOS native library
uses: actions/download-artifact@v4
with:
name: native-osx-arm64
path: artifacts/native/osx-arm64
- name: Download Linux native library
uses: actions/download-artifact@v4
with:
name: native-linux-x64
path: artifacts/native/linux-x64
- name: Stage native libraries in project
run: |
mkdir -p src/MLXSharp/runtimes/osx-arm64/native
cp artifacts/native/osx-arm64/libmlxsharp.dylib src/MLXSharp/runtimes/osx-arm64/native/
mkdir -p src/MLXSharp/runtimes/linux-x64/native
cp artifacts/native/linux-x64/libmlxsharp.so src/MLXSharp/runtimes/linux-x64/native/
- name: Build C# projects with native libraries
run: dotnet build --configuration Release --no-restore
- name: Copy native library to test output
run: |
TEST_OUTPUT="src/MLXSharp.Tests/bin/Release/net9.0"
mkdir -p "$TEST_OUTPUT/runtimes/osx-arm64/native"
cp src/MLXSharp/runtimes/osx-arm64/native/libmlxsharp.dylib "$TEST_OUTPUT/runtimes/osx-arm64/native/"
ls -la "$TEST_OUTPUT/runtimes/osx-arm64/native/"
- name: Run tests
run: dotnet test --configuration Release --no-build --logger "trx;LogFileName=TestResults.trx" --results-directory artifacts/test-results
env:
MLXSHARP_MODEL_PATH: ${{ github.workspace }}/models/Qwen1.5-0.5B-Chat-4bit
- name: Prepare artifact folders
run: |
mkdir -p artifacts/test-results
mkdir -p artifacts/packages
mkdir -p artifacts/native
cp artifacts/native/osx-arm64/libmlxsharp.dylib artifacts/native/
cp artifacts/native/linux-x64/libmlxsharp.so artifacts/native/
- name: Pack MLXSharp library
run: dotnet pack src/MLXSharp/MLXSharp.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/artifacts/native/osx-arm64/libmlxsharp.dylib -p:MLXSharpLinuxNativeBinary=$GITHUB_WORKSPACE/artifacts/native/linux-x64/libmlxsharp.so
- name: Pack MLXSharp.SemanticKernel library
run: dotnet pack src/MLXSharp.SemanticKernel/MLXSharp.SemanticKernel.csproj --configuration Release --output artifacts/packages -p:MLXSharpMacNativeBinary=$GITHUB_WORKSPACE/artifacts/native/osx-arm64/libmlxsharp.dylib -p:MLXSharpLinuxNativeBinary=$GITHUB_WORKSPACE/artifacts/native/linux-x64/libmlxsharp.so -p:MLXSharpSkipLinuxNativeValidation=true
- name: Verify package contains native libraries
run: |
echo "Checking package contents..."
shopt -s nullglob
packages=(artifacts/packages/*.nupkg)
if [ ${#packages[@]} -eq 0 ]; then
echo "✗ ERROR: No packages were produced"
exit 1
fi
missing=0
for package in "${packages[@]}"; do
echo "Inspecting ${package}"
filename=$(basename "${package}")
case "${filename}" in
MLXSharp.SemanticKernel.*.nupkg)
echo " ↷ Skipping native check for ${filename}"
;;
MLXSharp.*.nupkg)
package_missing=0
if unzip -l "${package}" | grep -q "runtimes/osx-arm64/native/libmlxsharp.dylib"; then
echo " ✓ macOS library present"
else
echo " ✗ macOS library missing"
package_missing=1
fi
if unzip -l "${package}" | grep -q "runtimes/linux-x64/native/libmlxsharp.so"; then
echo " ✓ Linux library present"
else
echo " ✗ Linux library missing"
package_missing=1
fi
if [ ${package_missing} -ne 0 ]; then
unzip -l "${package}"
missing=1
fi
;;
*)
echo " ↷ Skipping native check for ${filename}"
;;
esac
done
if [ $missing -ne 0 ]; then
exit 1
fi
- name: Upload native artifact
uses: actions/upload-artifact@v4
with:
name: native-libs
path: artifacts/native
- name: Upload packages artifact
uses: actions/upload-artifact@v4
with:
name: packages
path: artifacts/packages
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: artifacts/test-results
release:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: package-test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract version from Directory.Build.props
id: version
run: |
VERSION=$(grep -oP '<Version>\K[^<]+' Directory.Build.props)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
# - name: Check if tag exists
# id: check_tag
# run: |
# if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.version.outputs.version }}"; then
# echo "exists=true" >> $GITHUB_OUTPUT
# echo "Tag v${{ steps.version.outputs.version }} already exists"
# else
# echo "exists=false" >> $GITHUB_OUTPUT
# echo "Tag v${{ steps.version.outputs.version }} does not exist"
# fi
# - name: Download package artifacts
# if: steps.check_tag.outputs.exists == 'false'
# uses: actions/download-artifact@v4
# with:
# name: packages
# path: artifacts/packages
# - name: Publish to NuGet
# if: steps.check_tag.outputs.exists == 'false'
# run: |
# for package in artifacts/packages/*.nupkg; do
# echo "Publishing $package..."
# dotnet nuget push "$package" \
# --api-key ${{ secrets.NUGET_API_KEY }} \
# --source https://api.nuget.org/v3/index.json \
# --skip-duplicate || true
# done
# - name: Create Git tag
# if: steps.check_tag.outputs.exists == 'false'
# run: |
# git config user.name "github-actions[bot]"
# git config user.email "github-actions[bot]@users.noreply.github.com"
# git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
# git push origin "v${{ steps.version.outputs.version }}"
# - name: Generate release notes
# if: steps.check_tag.outputs.exists == 'false'
# id: release_notes
# run: |
# PREVIOUS_TAG=$(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1) 2>/dev/null || echo "")
# if [ -z "$PREVIOUS_TAG" ]; then
# COMMITS=$(git log --pretty=format:"- %s (%h)" --reverse)
# else
# COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --reverse)
# fi
# echo "## What's Changed" > release_notes.md
# echo "" >> release_notes.md
# echo "$COMMITS" >> release_notes.md
# echo "" >> release_notes.md
# echo "## NuGet Packages" >> release_notes.md
# echo "- [MLXSharp v${{ steps.version.outputs.version }}](https://www.nuget.org/packages/MLXSharp/${{ steps.version.outputs.version }})" >> release_notes.md
# echo "- [MLXSharp.SemanticKernel v${{ steps.version.outputs.version }}](https://www.nuget.org/packages/MLXSharp.SemanticKernel/${{ steps.version.outputs.version }})" >> release_notes.md
# cat release_notes.md
# - name: Create GitHub Release
# if: steps.check_tag.outputs.exists == 'false'
# uses: softprops/action-gh-release@v1
# with:
# tag_name: v${{ steps.version.outputs.version }}
# name: Release v${{ steps.version.outputs.version }}
# body_path: release_notes.md
# files: artifacts/packages/*
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}