aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/github-release.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/github-release.sh')
-rwxr-xr-xtools/github-release.sh19
1 files changed, 10 insertions, 9 deletions
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}