summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-05-03 10:21:27 +0200
committerErich Eckner <git@eckner.net>2018-05-03 10:21:27 +0200
commit6c9bf4d7bbce6e4e11e68e4e528d10fc8a1fa743 (patch)
tree5967557741d978b2a155020e0c4c6a3668a52b6d
downloadgithub-api-client-6c9bf4d7bbce6e4e11e68e4e528d10fc8a1fa743.tar.xz
Initial commit
-rw-r--r--.gitignore1
-rwxr-xr-xupload-asset51
2 files changed, 52 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6685f28
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+pw.gpg
diff --git a/upload-asset b/upload-asset
new file mode 100755
index 0000000..607c5fd
--- /dev/null
+++ b/upload-asset
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+base_dir=$(
+ dirname "$(
+ readlink -f "$0"
+ )"
+)
+
+api_url='https://api.github.com'
+auth='Authorization: token '"$(
+ gpg -d -o - "${base_dir}/pw.gpg" 2>/dev/null
+)"
+
+owner='archlinux32'
+repo='archlinux32-keyring'
+tag='v20180411'
+file='test.asc'
+name='test.asc'
+
+repo_url="${api_url}/repos/${owner}/${repo}"
+tags_url="${repo_url}/releases/tags/${tag}"
+
+response=$(
+ curl -sH "${auth}" "${repo_url}"
+)
+
+if echo "${response}" | \
+ grep -qF '"Bad credentials"'; then
+ >&2 echo "${response}"
+ exit 1
+fi
+
+eval $(
+ curl -sH "${auth}" "${tags_url}" | \
+ grep -m1 '"id":' | \
+ tr : = | \
+ tr -cd '[[:alnum:]]='
+)
+
+if [ -z "${id}" ]; then
+ >&2 printf 'Error: Failed to get release id for tag %s.\n' "${tag}"
+ >&2 printf '%s\n' "${response}"
+ exit 1
+fi
+
+upload_url="https://uploads.github.com/repos/${owner}/${repo}/releases/${id}/assets?name=${name}"
+curl \
+ --data-binary @"${file}" \
+ -H "${auth}" \
+ -H "Content-Type: application/octet-stream" \
+ "${upload_url}"