Skip to content

Commit 019880c

Browse files
committed
GH scripts: reformat
wrap long lines + early return in while-loop
1 parent c44a265 commit 019880c

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

.github/scripts/delete-asset.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@ DIR=$(dirname "$0")
66

77
TAG_NAME=${1?}
88
PATTERN=$(basename "${2?}")
9-
JSON=$(fetch_json "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$TAG_NAME" "$GITHUB_TOKEN")
9+
JSON=$(fetch_json "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/\
10+
tags/$TAG_NAME" "$GITHUB_TOKEN")
1011
RELEASE_ID=$(jq -r '.id' "$JSON")
1112
rm "$JSON"
12-
JSON=$(fetch_json "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID/assets" "$GITHUB_TOKEN" array)
13+
JSON=$(fetch_json "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/\
14+
$RELEASE_ID/assets" "$GITHUB_TOKEN" array)
1315
LEN=$(jq length "$JSON")
1416
n=-1; while n=$((n + 1)); [ "$n" -lt "$LEN" ]; do
1517
NAME=$(jq -r ".[$n].name" "$JSON")
16-
if expr "$NAME" : "$PATTERN$"; then
17-
ID=$(jq ".[$n].id" "$JSON")
18-
JSON2=$(mktemp)
19-
STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -X DELETE "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/assets/$ID" -w '%{http_code}' -o "$JSON2")
20-
check_errors "$JSON2"
21-
check_status "$STATUS"
22-
rm "$JSON2"
18+
if ! expr "$NAME" : "$PATTERN$"; then
19+
continue
2320
fi
21+
ID=$(jq ".[$n].id" "$JSON")
22+
JSON2=$(mktemp)
23+
STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -X DELETE \
24+
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/assets/$ID" \
25+
-w '%{http_code}' -o "$JSON2")
26+
check_errors "$JSON2"
27+
check_status "$STATUS"
28+
rm "$JSON2"
2429
done
2530
rm "$JSON"
2631

.github/scripts/upload-asset.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ FILENAME=$(basename "${2?}")
1010
CONTENT_TYPE=${3?}
1111
LABEL=$(echo "${4?}" | sed 's/ /%20/g')
1212

13-
JSON=$(fetch_json "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$TAG_NAME" "$GITHUB_TOKEN")
13+
JSON=$(fetch_json\
14+
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$TAG_NAME"\
15+
"$GITHUB_TOKEN")
1416
UPLOAD_URL=$(jq -r .upload_url "$JSON" | sed "s/{.*}//")
1517

1618
JSON=$(mktemp)
17-
STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: $CONTENT_TYPE" -X POST "$UPLOAD_URL?name=$FILENAME&label=$LABEL" -T "$FILE" -w '%{http_code}' -o "$JSON")
19+
STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -H\
20+
"Content-Type: $CONTENT_TYPE" -X POST "$UPLOAD_URL?name=$FILENAME&label=$LABEL"\
21+
-T "$FILE" -w '%{http_code}' -o "$JSON")
1822
check_errors "$JSON"
1923
check_status "$STATUS"
2024
rm "$JSON"

0 commit comments

Comments
 (0)