File tree Expand file tree Collapse file tree 3 files changed +29
-19
lines changed
Expand file tree Collapse file tree 3 files changed +29
-19
lines changed Original file line number Diff line number Diff line change @@ -6,21 +6,26 @@ DIR=$(dirname "$0")
66
77TAG_NAME=${1?}
88PATTERN=$( 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 " )
1011RELEASE_ID=$( jq -r ' .id' " $JSON " )
1112rm " $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)
1315LEN=$( jq length " $JSON " )
14- for n in $( seq 0 $(( LEN - 1 )) ) ; do
16+ 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 "
2429done
2530rm " $JSON "
2631
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -8,13 +8,17 @@ TAG_NAME=${1?}
88FILE=${2?}
99FILENAME=$( basename " ${2?} " )
1010CONTENT_TYPE=${3?}
11- LABEL=${4?}
11+ 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 " )
1416UPLOAD_URL=$( jq -r .upload_url " $JSON " | sed " s/{.*}//" )
1517
1618JSON=$( 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 " )
1822check_errors " $JSON "
1923check_status " $STATUS "
2024rm " $JSON "
You can’t perform that action at this time.
0 commit comments