aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-25 17:08:37 +0800
committertypebrook <typebrook@gmail.com>2020-03-25 17:08:37 +0800
commitd5d9804bfa54910e2ad03e487f217d614aca3580 (patch)
treeb7fd1555f3d7a49bd54d12da74c1d28d3a3eb7d7
parent103cd9acb396092863935d71591990128e475e24 (diff)
Update github-release.sh
-rw-r--r--alias2
-rwxr-xr-xtools/github-release.sh27
2 files changed, 18 insertions, 11 deletions
diff --git a/alias b/alias
index c70606a..f0c9451 100644
--- a/alias
+++ b/alias
@@ -93,7 +93,7 @@ gcg() {
93 git clone git@github.com:$1/$2.git && cd $(basename $2) 93 git clone git@github.com:$1/$2.git && cd $(basename $2)
94} 94}
95release() { 95release() {
96 command="github-release.sh\n github_api_token=$GITHUB_API_TOKEN\n repo=typebrook/tig\n tag=LATEST\n type=asset\n filename=$(which tig)\n overwrite=false" 96 command="github-release.sh\n github_api_token=$GITHUB_API_TOKEN\n repo=typebrook/tig\n tag=LATEST\n type=asset\n filename=$(which tig)\n action=upload|overwrite|rename|delete\n extra="
97 prompt "$command" 97 prompt "$command"
98} 98}
99asset() { 99asset() {
diff --git a/tools/github-release.sh b/tools/github-release.sh
index 2936134..b8f6dba 100755
--- a/tools/github-release.sh
+++ b/tools/github-release.sh
@@ -16,7 +16,8 @@
16# * type (asset or edit) 16# * type (asset or edit)
17# * filename 17# * filename
18# * github_api_token 18# * github_api_token
19# * overwrite (optional, could be ture, false, delete, default to be false) 19# * action (optional, could be upload, overwrite, rename, delete, default to be upload)
20# * extra (optional, new filename for action 'rename')
20# 21#
21# Example: 22# Example:
22# 23#
@@ -64,15 +65,21 @@ eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:al
64 65
65post_asset() { 66post_asset() {
66 # Upload asset 67 # Upload asset
67 echo "Uploading asset... " > /dev/tty 68 echo "Uploading asset... "
68 # Construct url 69 # Construct url
69 GH_ASSET="https://uploads.github.com/repos/$repo/releases/$release_id/assets?name=$(basename $1)" 70 GH_ASSET="https://uploads.github.com/repos/$repo/releases/$release_id/assets?name=$(basename $1)"
70 71
71 curl --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET 72 curl --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET
72} 73}
73 74
75rename_asset() {
76 echo "Renaming asset($1) from $2 to $3"
77 curl -X PATCH -H "$AUTH" -H "Content-Type: application/json" \
78 --data "{\"name\":\"$3\"}" "$GH_REPO/releases/assets/$1"
79}
80
74delete_asset() { 81delete_asset() {
75 echo "Deleting asset($1)... " > /dev/tty 82 echo "Deleting asset($1)... "
76 curl -X "DELETE" -H "$AUTH" "$GH_REPO/releases/assets/$1" 83 curl -X "DELETE" -H "$AUTH" "$GH_REPO/releases/assets/$1"
77} 84}
78 85
@@ -84,19 +91,19 @@ upload_asset() {
84 echo "No need to overwrite asset" 91 echo "No need to overwrite asset"
85 post_asset $filename 92 post_asset $filename
86 else 93 else
87 if [ "$overwrite" = "true" ]; then 94 if [ "$action" = "overwrite" ]; then
88 new_asset_id=$(post_asset ${filename}_bak | sed -E 's/^\{[^{]+"id":([0-9]+).+$/\1/') 95 new_asset_id=$(post_asset "bak_$filename" | sed -E 's/^\{[^{]+"id":([0-9]+).+$/\1/')
89 [ "$new_asset_id" = "" ] && exit 1 || delete_asset "$asset_id" 96 [ "$new_asset_id" = "" ] && exit 1 || delete_asset "$asset_id"
90 97
91 echo "Renaming asset($new_asset_id) from $(basename $filename)_bak to $(basename $filename)" > /dev/tty 98 rename_asset "$new_asset_id" "bak_$filename" "$filename"
92 curl -X PATCH -H "$AUTH" -H "Content-Type: application/json" \ 99 elif [ "$action" = "rename" ]; then
93 --data "{\"name\":\"$(basename $filename)\"}" "$GH_REPO/releases/assets/$new_asset_id" 100 rename_asset "$asset_id" "$filename" "$extra"
94 elif [ "$overwrite" = "delete" ]; then 101 elif [ "$action" = "delete" ]; then
95 delete_asset "$asset_id" 102 delete_asset "$asset_id"
96 exit 0 103 exit 0
97 else 104 else
98 echo "File already exists on tag $tag" 105 echo "File already exists on tag $tag"
99 echo "If you want to overwrite it, set overwrite=true" 106 echo "If you want to overwrite it, set action=overwrite"
100 exit 1 107 exit 1
101 fi 108 fi
102 fi 109 fi