aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--alias10
-rwxr-xr-xtools/github-release.sh19
2 files changed, 16 insertions, 13 deletions
diff --git a/alias b/alias
index d5da487..81c2a29 100644
--- a/alias
+++ b/alias
@@ -95,10 +95,13 @@ github_api() {
95gcg() { 95gcg() {
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}
98github_release_asset() { 98release() {
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}
102asset() {
103 curl -LO https://github.com/$1/$2/releases/download/$3/$4
104}
102 105
103# tig 106# tig
104alias cdt='cd ~/git/tig' 107alias cdt='cd ~/git/tig'
@@ -109,8 +112,7 @@ alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2
109upload_tig() { 112upload_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.
29set -e 30set -e
@@ -39,7 +40,7 @@ done
39 40
40# Define variables. 41# Define variables.
41GH_API="https://api.github.com" 42GH_API="https://api.github.com"
42GH_REPO="$GH_API/repos/$owner/$repo" 43GH_REPO="$GH_API/repos/$repo"
43GH_TAGS="$GH_REPO/releases/tags/$tag" 44GH_TAGS="$GH_REPO/releases/tags/$tag"
44AUTH="Authorization: token $github_api_token" 45AUTH="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"
48fi 49fi
49if [ "$type" = '' ]; then 50if [ "$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
52fi 53fi
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}