Skip to content

Commit fc7c63c

Browse files
committed
GH scripts: small updates
- use while instead of for..seq - cat json file directly (avoid interpretting \n and \r that XSI-compilant echo, as in dash, does) - cat really the $json file, don't print its name The rewrite of `for n in \`seq` may be perhaps a bit controversal (with while is less readable) but technically POSIX doesn't specify the seq comand.
1 parent 3d70eb5 commit fc7c63c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

.github/scripts/delete-asset.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RELEASE_ID=$(jq -r '.id' "$JSON")
1111
rm "$JSON"
1212
JSON=$(fetch_json "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID/assets" "$GITHUB_TOKEN" array)
1313
LEN=$(jq length "$JSON")
14-
for n in $(seq 0 $((LEN-1))); do
14+
n=-1; while n=$((n + 1)); [ "$n" -lt "$LEN" ]; do
1515
NAME=$(jq -r ".[$n].name" "$JSON")
1616
if expr "$NAME" : "$PATTERN$"; then
1717
ID=$(jq ".[$n].id" "$JSON")

.github/scripts/json-common.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ check_type() {
1818
TYPE=$(jq -r type "$1")
1919
if [ "$TYPE" != "$2" ]; then
2020
echo "Wrong JSON type - expected $2, got $TYPE" >&2
21-
json=$(cat "$1")
22-
echo "JSON: $json" >&2
21+
echo 'JSON:' >&2
22+
cat "$1" >&2
2323
exit 1
2424
fi
2525
}
2626

27-
## @brief Returns json for given URL and authorization token while checking errors
27+
## @brief Returns json file for given URL and authorization token while checking errors
2828
## @param $1 URL
2929
## @param $2 GITHUB_TOKEN (optional)
3030
## @param $3 requested type (optional)
@@ -41,7 +41,8 @@ fetch_json() {
4141
status=$(curl -sS "$@" -X GET "$url" -w "%{http_code}" -o "$json")
4242
if ! is_int "$status" || [ "$status" -ne 200 ]; then
4343
echo "HTTP error code $status" >&2
44-
echo "JSON: $json" >&2
44+
echo "JSON:" >&2
45+
cat "$json" >&2
4546
fi
4647
check_errors "$json"
4748
if [ -n "$req_type" ]; then
@@ -57,8 +58,8 @@ check_status() {
5758
if ! is_int "$1" || [ "$1" -lt 200 ] || [ "$1" -ge 300 ]; then
5859
echo "Wrong response status $1!" >&2
5960
if [ -n "${2-}" ]; then
60-
json=$(cat "$2")
61-
echo "JSON: $json" >&2
61+
echo "JSON:" >&2
62+
cat "$2"
6263
fi
6364
exit 1
6465
fi

0 commit comments

Comments
 (0)