diff options
author | typebrook <typebrook@gmail.com> | 2019-11-30 12:43:26 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-11-30 12:43:26 +0800 |
commit | 8c581d3fc4e96e934d6f21d49863897a696e4a23 (patch) | |
tree | f2afbbe15644e5238cee21eb459fd8640ecf59e3 /scripts/upload-github-release-asset.sh | |
parent | 4f74567c6047ce189236e14eb2d991313fd253be (diff) |
update
Diffstat (limited to 'scripts/upload-github-release-asset.sh')
-rwxr-xr-x | scripts/upload-github-release-asset.sh | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/scripts/upload-github-release-asset.sh b/scripts/upload-github-release-asset.sh index 206e3cd..ee2723b 100755 --- a/scripts/upload-github-release-asset.sh +++ b/scripts/upload-github-release-asset.sh | |||
@@ -51,14 +51,24 @@ curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or | |||
51 | # Read asset tags. | 51 | # Read asset tags. |
52 | response=$(curl -sH "$AUTH" $GH_TAGS) | 52 | response=$(curl -sH "$AUTH" $GH_TAGS) |
53 | 53 | ||
54 | # Get ID of the release. | ||
55 | eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | sed 's/id/release_id/') | ||
56 | [ "$release_id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; } | ||
57 | |||
54 | # Get ID of the asset based on given filename. | 58 | # Get ID of the asset based on given filename. |
55 | eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') | 59 | # If exists, delete it. |
56 | [ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; } | 60 | eval $(echo "$response" | grep -C2 "\"name\":.\+$(basename $filename)" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | sed 's/id/asset_id/') |
61 | if [ "$asset_id" = "" ]; then | ||
62 | echo "No need to overwrite asset" | ||
63 | else | ||
64 | echo "Deleting asset($asset_id)... " | ||
65 | curl -X "DELETE" -H "Authorization: token $github_api_token" "https://api.github.com/repos/$owner/$repo/releases/assets/$asset_id" | ||
66 | fi | ||
57 | 67 | ||
58 | # Upload asset | 68 | # Upload asset |
59 | echo "Uploading asset... " | 69 | echo "Uploading asset... " |
60 | 70 | ||
61 | # Construct url | 71 | # Construct url |
62 | GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$id/assets?name=$(basename $filename)" | 72 | GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$release_id/assets?name=$(basename $filename)" |
63 | 73 | ||
64 | curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "Authorization: token $github_api_token" -H "Content-Type: application/octet-stream" $GH_ASSET | 74 | curl --data-binary @"$filename" -H "Authorization: token $github_api_token" -H "Content-Type: application/octet-stream" $GH_ASSET |