diff options
| -rw-r--r-- | alias | 2 | ||||
| -rwxr-xr-x | tools/github-release.sh | 27 |
2 files changed, 18 insertions, 11 deletions
| @@ -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 | } |
| 95 | release() { | 95 | release() { |
| 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 | } |
| 99 | asset() { | 99 | asset() { |
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 | ||
| 65 | post_asset() { | 66 | post_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 | ||
| 75 | rename_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 | |||
| 74 | delete_asset() { | 81 | delete_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 |