Skip to content

Commit 2ec1937

Browse files
committed
feat(ci): add artifact size comparison for releases
1 parent 4a60ec0 commit 2ec1937

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

.github/workflows/main.yml

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,77 @@ jobs:
198198
with:
199199
path: artifacts
200200

201+
- name: zip artifacts
202+
run: |
203+
VERSION=$(make version)
204+
for folder in "artifacts"/*; do
205+
if [ -d "$folder" ]; then
206+
name=$(basename "$folder")
207+
if [[ "$name" != "vector-apple-xcframework" && "$name" != "vector-android-aar" ]]; then
208+
tar -czf "${name}-${VERSION}.tar.gz" -C "$folder" .
209+
fi
210+
if [[ "$name" != "vector-android-aar" ]]; then
211+
(cd "$folder" && zip -rq "../../${name}-${VERSION}.zip" .)
212+
else
213+
cp "$folder"/*.aar "${name}-${VERSION}.aar"
214+
fi
215+
fi
216+
done
217+
201218
- name: release tag version from sqlite-vector.h
202219
id: tag
203220
run: |
204221
VERSION=$(make version)
205222
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
206-
LATEST=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.name')
223+
LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest)
224+
LATEST=$(echo "$LATEST_RELEASE" | jq -r '.name')
207225
if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
208226
echo "version=$VERSION" >> $GITHUB_OUTPUT
227+
228+
# Check artifact sizes against previous release
229+
if [ -n "$LATEST" ] && [ "$LATEST" != "null" ]; then
230+
echo "Checking artifact sizes against previous release: $LATEST"
231+
FAILED=0
232+
233+
for artifact in vector-*-${VERSION}.*; do
234+
if [ ! -f "$artifact" ]; then
235+
continue
236+
fi
237+
238+
# Get current artifact size
239+
NEW_SIZE=$(stat -c%s "$artifact" 2>/dev/null || stat -f%z "$artifact")
240+
241+
# Get artifact name for previous release
242+
ARTIFACT_NAME=$(echo "$artifact" | sed "s/${VERSION}/${LATEST}/")
243+
244+
# Get previous artifact size from GitHub API
245+
OLD_SIZE=$(echo "$LATEST_RELEASE" | jq -r ".assets[] | select(.name == \"$(basename "$ARTIFACT_NAME")\") | .size")
246+
247+
if [ -z "$OLD_SIZE" ] || [ "$OLD_SIZE" = "null" ]; then
248+
echo "⚠️ Previous artifact not found: $(basename "$ARTIFACT_NAME"), skipping comparison"
249+
continue
250+
fi
251+
252+
# Calculate percentage increase
253+
INCREASE=$(awk "BEGIN {printf \"%.2f\", (($NEW_SIZE - $OLD_SIZE) / $OLD_SIZE) * 100}")
254+
255+
echo "📦 $artifact: $OLD_SIZE → $NEW_SIZE bytes (${INCREASE}% change)"
256+
257+
# Check if increase is more than 5%
258+
if (( $(echo "$INCREASE > 5" | bc -l) )); then
259+
echo "❌ ERROR: $artifact size increased by ${INCREASE}% (limit: 5%)"
260+
FAILED=1
261+
fi
262+
done
263+
264+
if [ $FAILED -eq 1 ]; then
265+
echo ""
266+
echo "❌ One or more artifacts exceeded the 5% size increase limit"
267+
exit 1
268+
fi
269+
270+
echo "✅ All artifacts within 5% size increase limit"
271+
fi
209272
else
210273
echo "::warning file=src/sqlite-vector.h::To release a new version, please update the SQLITE_VECTOR_VERSION in src/sqlite-vector.h to be different than the latest $LATEST"
211274
fi
@@ -234,23 +297,6 @@ jobs:
234297
git add modules/sqlite-vector
235298
git commit -m "Bump sqlite-vector version to ${{ steps.tag.outputs.version }}"
236299
git push origin main
237-
238-
- name: zip artifacts
239-
if: steps.tag.outputs.version != ''
240-
run: |
241-
for folder in "artifacts"/*; do
242-
if [ -d "$folder" ]; then
243-
name=$(basename "$folder")
244-
if [[ "$name" != "vector-apple-xcframework" && "$name" != "vector-android-aar" ]]; then
245-
tar -czf "${name}-${{ steps.tag.outputs.version }}.tar.gz" -C "$folder" .
246-
fi
247-
if [[ "$name" != "vector-android-aar" ]]; then
248-
(cd "$folder" && zip -rq "../../${name}-${{ steps.tag.outputs.version }}.zip" .)
249-
else
250-
cp "$folder"/*.aar "${name}-${{ steps.tag.outputs.version }}.aar"
251-
fi
252-
fi
253-
done
254300
255301
- uses: actions/setup-java@v4
256302
if: steps.tag.outputs.version != ''

0 commit comments

Comments
 (0)