Skip to content

Commit d2bdaf5

Browse files
committed
fix(ci): improve artifact size comparison logic in release workflow
1 parent 2ec1937 commit d2bdaf5

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

.github/workflows/main.yml

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -222,53 +222,54 @@ jobs:
222222
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
223223
LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest)
224224
LATEST=$(echo "$LATEST_RELEASE" | jq -r '.name')
225-
if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
226-
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
232225
233-
for artifact in vector-*-${VERSION}.*; do
234-
if [ ! -f "$artifact" ]; then
235-
continue
236-
fi
226+
# Check artifact sizes against previous release
227+
if [ -n "$LATEST" ] && [ "$LATEST" != "null" ]; then
228+
echo "Checking artifact sizes against previous release: $LATEST"
229+
FAILED=0
237230
238-
# Get current artifact size
239-
NEW_SIZE=$(stat -c%s "$artifact" 2>/dev/null || stat -f%z "$artifact")
231+
for artifact in vector-*-${VERSION}.*; do
232+
if [ ! -f "$artifact" ]; then
233+
continue
234+
fi
240235
241-
# Get artifact name for previous release
242-
ARTIFACT_NAME=$(echo "$artifact" | sed "s/${VERSION}/${LATEST}/")
236+
# Get current artifact size
237+
NEW_SIZE=$(stat -c%s "$artifact" 2>/dev/null || stat -f%z "$artifact")
243238
244-
# Get previous artifact size from GitHub API
245-
OLD_SIZE=$(echo "$LATEST_RELEASE" | jq -r ".assets[] | select(.name == \"$(basename "$ARTIFACT_NAME")\") | .size")
239+
# Get artifact name for previous release
240+
ARTIFACT_NAME=$(echo "$artifact" | sed "s/${VERSION}/${LATEST}/")
246241
247-
if [ -z "$OLD_SIZE" ] || [ "$OLD_SIZE" = "null" ]; then
248-
echo "⚠️ Previous artifact not found: $(basename "$ARTIFACT_NAME"), skipping comparison"
249-
continue
250-
fi
242+
# Get previous artifact size from GitHub API
243+
OLD_SIZE=$(echo "$LATEST_RELEASE" | jq -r ".assets[] | select(.name == \"$(basename "$ARTIFACT_NAME")\") | .size")
251244
252-
# Calculate percentage increase
253-
INCREASE=$(awk "BEGIN {printf \"%.2f\", (($NEW_SIZE - $OLD_SIZE) / $OLD_SIZE) * 100}")
245+
if [ -z "$OLD_SIZE" ] || [ "$OLD_SIZE" = "null" ]; then
246+
echo "⚠️ Previous artifact not found: $(basename "$ARTIFACT_NAME"), skipping comparison"
247+
continue
248+
fi
254249
255-
echo "📦 $artifact: $OLD_SIZE → $NEW_SIZE bytes (${INCREASE}% change)"
250+
# Calculate percentage increase
251+
INCREASE=$(awk "BEGIN {printf \"%.2f\", (($NEW_SIZE - $OLD_SIZE) / $OLD_SIZE) * 100}")
256252
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
253+
echo "📦 $artifact: $OLD_SIZE → $NEW_SIZE bytes (${INCREASE}% change)"
263254
264-
if [ $FAILED -eq 1 ]; then
265-
echo ""
266-
echo "❌ One or more artifacts exceeded the 5% size increase limit"
267-
exit 1
255+
# Check if increase is more than 5%
256+
if (( $(echo "$INCREASE > 5" | bc -l) )); then
257+
echo "❌ ERROR: $artifact size increased by ${INCREASE}% (limit: 5%)"
258+
FAILED=1
268259
fi
260+
done
269261
270-
echo "✅ All artifacts within 5% size increase limit"
262+
if [ $FAILED -eq 1 ]; then
263+
echo ""
264+
echo "❌ One or more artifacts exceeded the 5% size increase limit"
265+
exit 1
271266
fi
267+
268+
echo "✅ All artifacts within 5% size increase limit"
269+
fi
270+
271+
if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
272+
echo "version=$VERSION" >> $GITHUB_OUTPUT
272273
else
273274
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"
274275
fi

0 commit comments

Comments
 (0)