diff options
Diffstat (limited to 'release')
-rwxr-xr-x | release | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/release b/release deleted file mode 100755 index 868b0a8..0000000 --- a/release +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh - -base_dir=$( - dirname "$( - readlink -f "$0" - )" -) -git_dir=$( - pwd -) - -api_url='https://api.github.com' -auth='Authorization: token '"$( - gpg -d -o - "${base_dir}/pw.gpg" 2>/dev/null -)" - -if [ -n "$(git status --porcelain 2>&1)" ]; then - >&2 echo 'Error: git state is not clean.' - exit 1 -fi - -if [ -n "$1" ]; then - tag="$1" - shift -else - tag="v$(date +'%Y%m%d')" -fi - -if [ $# -ne 0 ] || [ -z "${tag}" ]; then - >&2 echo 'usage:' - >&2 echo ' release $tag' - >&2 echo 'or' - >&2 echo ' release' - exit 1 -fi - -owner=$(basename "$(dirname "${git_dir}")") -repo=$(basename "${git_dir}") - -repo_url="${api_url}/repos/${owner}/${repo}" -tags_url="${repo_url}/releases/tags/${tag}" - ->&2 printf 'Try to authenticate ...' -response=$( - curl -sH "${auth}" "${repo_url}" -) - -if echo "${response}" | \ - grep -qF '"Bad credentials"'; then - >&2 printf '\nError: Bad credentials.\n' - >&2 printf '%s\n' "${response}" - exit 1 -fi ->&2 printf ' ok.\n' - ->&2 printf 'Creating tag ...' -if ! git tag -s -m "Release ${tag}" "${tag}"; then - >&2 printf '\nError: Failed to create tag %s.\n' "${tag}" - exit 1 -fi ->&2 printf ' ok.\n' - -tmp_dir=$(mktemp -d) -trap 'rm -rf --one-file-system "${tmp_dir:?}"' EXIT - ->&2 printf 'Creating and signing tarball ...' -git archive --prefix="${repo}-${tag}/" "${tag}" | \ - xz -9 > \ - "${tmp_dir}/${repo}-${tag}.tar.xz" -if ! gpg --detach-sign --local-user erich@eckner.net --local-user arch@eckner.net "${tmp_dir}/${repo}-${tag}.tar.xz"; then - >&2 printf '\nError: Failed to sign release tarball.\n' - exit 1 -fi ->&2 printf ' ok.\n' - ->&2 printf 'Pushing tags ...' -if ! git push --tags; then - >&2 printf '\nError: Failed to push tags.\n' - exit 1 -fi ->&2 printf ' ok.\n' - ->&2 printf 'Creating release from tag ...' -response=$( - printf '"%s": "%s"\n' \ - 'tag_name' "${tag}" \ - 'name' "${tag}" \ - 'body' "Release ${tag}" | \ - sed ' - s/^/ / - 1 i { - $! s/$/,/ - $ a } - ' | \ - curl -sH "${auth}" -d @- "${repo_url}/releases" -) -eval $( - printf '%s\n' "${response}" | \ - grep -m1 '"id":' | \ - tr : = | \ - tr -cd '[[:alnum:]]=' -) -if [ -z "${id}" ]; then - >&2 printf '\nError: Failed to create/get release id for tag %s.\n' "${tag}" - >&2 printf '%s\n' "${response}" - exit 1 -fi ->&2 printf ' ok.\n' - ->&2 printf 'Uploading tarball and signature ...' -for suffix in '' '.sig'; do - - upload_url="https://uploads.github.com/repos/${owner}/${repo}/releases/${id}/assets?name=${repo}-${tag}.tar.xz${suffix}" - - curl \ - --data-binary @"${tmp_dir}/${repo}-${tag}.tar.xz${suffix}" \ - -H "${auth}" \ - -H "Content-Type: application/octet-stream" \ - "${upload_url}" - printf '\n' - -done ->&2 printf ' ok.\n' |