diff options
| -rw-r--r-- | alias | 10 | ||||
| -rwxr-xr-x | tools/github-release.sh | 19 |
2 files changed, 16 insertions, 13 deletions
| @@ -95,10 +95,13 @@ github_api() { | |||
| 95 | gcg() { | 95 | gcg() { |
| 96 | git clone git@github.com:$1/$2.git && cd $(basename $2) | 96 | git clone git@github.com:$1/$2.git && cd $(basename $2) |
| 97 | } | 97 | } |
| 98 | github_release_asset() { | 98 | release() { |
| 99 | command="github-release.sh\n github_api_token=$GITHUB_API_TOKEN\n owner=typebrook\n repo=tig\n tag=LATEST\n type=asset\n filename=$(which tig)\n overwrite=false" | 99 | 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" |
| 100 | prompt "$command" | 100 | prompt "$command" |
| 101 | } | 101 | } |
| 102 | asset() { | ||
| 103 | curl -LO https://github.com/$1/$2/releases/download/$3/$4 | ||
| 104 | } | ||
| 102 | 105 | ||
| 103 | # tig | 106 | # tig |
| 104 | alias cdt='cd ~/git/tig' | 107 | alias cdt='cd ~/git/tig' |
| @@ -109,8 +112,7 @@ alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2 | |||
| 109 | upload_tig() { | 112 | upload_tig() { |
| 110 | github-release.sh \ | 113 | github-release.sh \ |
| 111 | github_api_token=$GITHUB_API_TOKEN \ | 114 | github_api_token=$GITHUB_API_TOKEN \ |
| 112 | owner=typebrook \ | 115 | repo=typebrook/tig \ |
| 113 | repo=tig \ | ||
| 114 | tag=LATEST \ | 116 | tag=LATEST \ |
| 115 | filename=$(which tig) | 117 | filename=$(which tig) |
| 116 | overwrite=false | 118 | overwrite=false |
diff --git a/tools/github-release.sh b/tools/github-release.sh index bed34db..e7ddb3b 100755 --- a/tools/github-release.sh +++ b/tools/github-release.sh | |||
| @@ -7,10 +7,10 @@ | |||
| 7 | # Originally created by stefanbuck | 7 | # Originally created by stefanbuck |
| 8 | # fork from: https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447 | 8 | # fork from: https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447 |
| 9 | # | 9 | # |
| 10 | # -- | ||
| 11 | # This script manages a release note or its asset with GitHub API v3. | ||
| 12 | # It accepts the following parameters: | ||
| 10 | # | 13 | # |
| 11 | # This script accepts the following parameters: | ||
| 12 | # | ||
| 13 | # * owner | ||
| 14 | # * repo | 14 | # * repo |
| 15 | # * tag | 15 | # * tag |
| 16 | # * type (asset or edit) | 16 | # * type (asset or edit) |
| @@ -18,12 +18,13 @@ | |||
| 18 | # * github_api_token | 18 | # * github_api_token |
| 19 | # * overwrite (optional, could be ture, false, delete, default to be false) | 19 | # * overwrite (optional, could be ture, false, delete, default to be false) |
| 20 | # | 20 | # |
| 21 | # Script to manage a release or its asset using the GitHub API v3. | ||
| 22 | # | ||
| 23 | # Example: | 21 | # Example: |
| 24 | # | 22 | # |
| 25 | # github-release.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 type=asset filename=./build.zip overwrite=true | 23 | # # Upload a file as asset. If there is a asset with the same filename, then overwrite it. |
| 24 | # github-release.sh github_api_token=TOKEN repo=stefanbuck/playground tag=v0.1.0 type=asset filename=./build.zip overwrite=true | ||
| 26 | # | 25 | # |
| 26 | # # Edit a release note with file content | ||
| 27 | # github-release.sh github_api_token=TOKEN repo=stefanbuck/playground tag=v0.1.0 type=edit filename=note | ||
| 27 | 28 | ||
| 28 | # Check dependencies. | 29 | # Check dependencies. |
| 29 | set -e | 30 | set -e |
| @@ -39,7 +40,7 @@ done | |||
| 39 | 40 | ||
| 40 | # Define variables. | 41 | # Define variables. |
| 41 | GH_API="https://api.github.com" | 42 | GH_API="https://api.github.com" |
| 42 | GH_REPO="$GH_API/repos/$owner/$repo" | 43 | GH_REPO="$GH_API/repos/$repo" |
| 43 | GH_TAGS="$GH_REPO/releases/tags/$tag" | 44 | GH_TAGS="$GH_REPO/releases/tags/$tag" |
| 44 | AUTH="Authorization: token $github_api_token" | 45 | AUTH="Authorization: token $github_api_token" |
| 45 | 46 | ||
| @@ -47,7 +48,7 @@ if [ "$tag" = 'LATEST' ]; then | |||
| 47 | GH_TAGS="$GH_REPO/releases/latest" | 48 | GH_TAGS="$GH_REPO/releases/latest" |
| 48 | fi | 49 | fi |
| 49 | if [ "$type" = '' ]; then | 50 | if [ "$type" = '' ]; then |
| 50 | sed -E -n -e ' /^$/ q; 11,$ s/^# *//p' "$0" | 51 | sed -E -n -e ' /^$/ q; /# --/,$ s/^# *//p' "$0" |
| 51 | exit 0 | 52 | exit 0 |
| 52 | fi | 53 | fi |
| 53 | 54 | ||
| @@ -85,7 +86,7 @@ upload_asset() { | |||
| 85 | echo "Uploading asset... " | 86 | echo "Uploading asset... " |
| 86 | 87 | ||
| 87 | # Construct url | 88 | # Construct url |
| 88 | GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$release_id/assets?name=$(basename $filename)" | 89 | GH_ASSET="https://uploads.github.com/repos/$repo/releases/$release_id/assets?name=$(basename $filename)" |
| 89 | 90 | ||
| 90 | curl --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET | 91 | curl --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET |
| 91 | } | 92 | } |