diff options
Diffstat (limited to 'tools/github-release.sh')
-rwxr-xr-x | tools/github-release.sh | 19 |
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. |
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 | } |