mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 01:40:15 +00:00
GitHub CI: use JSON file
Use JSON as a file to fix '\n' in JSON handling.
This commit is contained in:
19
.github/scripts/delete-asset.sh
vendored
19
.github/scripts/delete-asset.sh
vendored
@@ -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
|
||||
|
||||
|
||||
16
.github/scripts/json-common.sh
vendored
16
.github/scripts/json-common.sh
vendored
@@ -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
|
||||
|
||||
9
.github/scripts/upload-asset.sh
vendored
9
.github/scripts/upload-asset.sh
vendored
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user