diff --git a/.github/scripts/delete-asset.sh b/.github/scripts/delete-asset.sh index 9ccdaa8a2..4a151d4b6 100755 --- a/.github/scripts/delete-asset.sh +++ b/.github/scripts/delete-asset.sh @@ -5,19 +5,20 @@ TAG_NAME=${1?} PATTERN=${2?} JSON=$(fetch_json https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$TAG_NAME $GITHUB_TOKEN) -RELEASE_ID=$(echo "$JSON" | jq -r '.id') +RELEASE_ID=$(jq -r '.id' $JSON) +rm $JSON JSON=$(fetch_json https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID/assets $GITHUB_TOKEN array) -LEN=$(echo "$JSON" | jq length) +LEN=$(jq length $JSON) for n in `seq 0 $(($LEN-1))`; do - NAME=$(echo "$JSON" | jq -r '.['$n'].name') + NAME=$(jq -r '.['$n'].name' "$JSON") if expr "$NAME" : "$PATTERN$"; then - ID=$(echo "$JSON" | jq '.['$n'].id') - TMPNAME=$(mktemp) - STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -X DELETE "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/assets/$ID" -w %{http_code} -o $TMPNAME) - JSON=$(cat $TMPNAME) - rm $TMPNAME - check_errors "$JSON" + ID=$(jq '.['$n'].id' $JSON) + JSON2=$(mktemp) + 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) + check_errors "$JSON2" check_status $STATUS + rm $JSON2 fi done +rm $JSON diff --git a/.github/scripts/json-common.sh b/.github/scripts/json-common.sh index 62b1b7565..c99193e2e 100644 --- a/.github/scripts/json-common.sh +++ b/.github/scripts/json-common.sh @@ -1,9 +1,9 @@ check_errors() { - TYPE=$(echo "$1" | jq -r type) + TYPE=$(jq -r type "$1") if [ "$TYPE" != object ]; then return fi - ERRORS=$(echo "$1" | jq -r '.errors') + ERRORS=$(jq -r '.errors' "$1") if [ "$ERRORS" != null ]; then echo $ERRORS >&2 exit 1 @@ -11,10 +11,10 @@ check_errors() { } check_type() { - TYPE=$(echo "$1" | jq -r type) + TYPE=$(jq -r type "$1") if [ "$TYPE" != "$2" ]; then echo "Wrong JSON type - expected $2, got $TYPE" >&2 - echo "JSON: $JSON" >&2 + echo "JSON: $(cat $1)" >&2 exit 1 fi } @@ -24,10 +24,8 @@ check_type() { ## @param $2 GITHUB_TOKEN ## @param $3 requested type (optional) fetch_json() { - TMPNAM=$(mktemp) - STATUS=$(curl -S -H "Authorization: token ${2?GitHub token is required}" -X GET ${1?URL is required} -w "%{http_code}" -o $TMPNAM) - JSON=$(cat $TMPNAM) - rm $TMPNAM + JSON=$(mktemp) + STATUS=$(curl -S -H "Authorization: token ${2?GitHub token is required}" -X GET ${1?URL is required} -w "%{http_code}" -o $JSON) if [ $STATUS -ne 200 ]; then echo "HTTP error code $STATUS" >&2 echo "JSON: $JSON" >&2 @@ -46,7 +44,7 @@ check_status() { if [ $1 -lt 200 -o $1 -ge 300 ]; then echo "Wrong response status $STATUS!" >&2 if [ -n ${2-""} ]; then - echo "JSON: $JSON" >&2 + echo "JSON: $(cat $2)" >&2 fi exit 1 fi diff --git a/.github/scripts/upload-asset.sh b/.github/scripts/upload-asset.sh index 3f4e9216b..f3dc0327d 100755 --- a/.github/scripts/upload-asset.sh +++ b/.github/scripts/upload-asset.sh @@ -8,12 +8,11 @@ CONTENT_TYPE=${3?} LABEL=${4?} JSON=$(fetch_json https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$TAG_NAME $GITHUB_TOKEN) -UPLOAD_URL=$(echo "$JSON" | jq -r .upload_url | sed "s/{.*}//") +UPLOAD_URL=$(jq -r .upload_url $JSON | sed "s/{.*}//") -TMPNAME=$(mktemp) -STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: $CONTENT_TYPE" -X POST "$UPLOAD_URL?name=$FILE&label=$LABEL" -T $FILE -w %{http_code} -o $TMPNAME) -JSON=$(cat $TMPNAME) -rm $TMPNAME +JSON=$(mktemp) +STATUS=$(curl -S -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: $CONTENT_TYPE" -X POST "$UPLOAD_URL?name=$FILE&label=$LABEL" -T $FILE -w %{http_code} -o $JSON) check_errors "$JSON" check_status $STATUS +rm $JSON diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 4ea66ef78..9be56c946 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -51,7 +51,7 @@ jobs: curl -H "Authorization: token $GITHUB_TOKEN" -X $REQ $URL -T - <