Skip to content

Commit 2646312

Browse files
committed
fix: use file-based merge for appcast to avoid awk newline errors
1 parent 8df8f77 commit 2646312

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

scripts/ci/sign-and-appcast.sh

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ else
117117
SECOND_APPCAST="${APPCAST_XMLS[1]}"
118118

119119
# Extract <item>...</item> blocks for the current version from second appcast
120-
NEW_ITEMS=$(awk "
120+
ITEMS_FILE=$(mktemp)
121+
awk "
121122
/<item>/ { capture=1; buf=\"\" }
122123
capture { buf = buf \$0 \"\\n\" }
123124
/<\\/item>/ {
@@ -126,28 +127,22 @@ else
126127
printf \"%s\", buf
127128
}
128129
}
129-
" "$SECOND_APPCAST")
130-
131-
if [ -n "$NEW_ITEMS" ]; then
132-
# Insert the new items after the first <item> block for this version
133-
# (i.e., after the arm64 entry's closing </item>)
134-
awk -v new_items="$NEW_ITEMS" -v version="$VERSION" '
135-
BEGIN { inserted=0 }
136-
/<\/item>/ {
137-
print
138-
if (!inserted && found_version) {
139-
printf "%s", new_items
140-
inserted=1
141-
}
142-
next
143-
}
144-
/<sparkle:shortVersionString>/ {
145-
if (index($0, version) > 0) found_version=1
146-
}
147-
{ print }
148-
' "$FINAL_APPCAST" > "${FINAL_APPCAST}.merged"
149-
mv "${FINAL_APPCAST}.merged" "$FINAL_APPCAST"
130+
" "$SECOND_APPCAST" > "$ITEMS_FILE"
131+
132+
if [ -s "$ITEMS_FILE" ]; then
133+
# Find the line number of the first </item> in the base appcast and
134+
# insert the second arch's item block right after it.
135+
FIRST_CLOSE=$(grep -n '</item>' "$FINAL_APPCAST" | head -1 | cut -d: -f1)
136+
if [ -n "$FIRST_CLOSE" ]; then
137+
{
138+
head -n "$FIRST_CLOSE" "$FINAL_APPCAST"
139+
cat "$ITEMS_FILE"
140+
tail -n +"$((FIRST_CLOSE + 1))" "$FINAL_APPCAST"
141+
} > "${FINAL_APPCAST}.merged"
142+
mv "${FINAL_APPCAST}.merged" "$FINAL_APPCAST"
143+
fi
150144
fi
145+
rm -f "$ITEMS_FILE"
151146
fi
152147

153148
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)