.githooks/upload-macos
34 lines · 1300 bytes · executable
1#!/bin/sh
2# Attach the macOS tarballs built by pre-push to the gitbay release.
3#
4# The release is created by the CI job the tag push triggers, so this waits for it
5# rather than assuming it is there. Run by hand as `.githooks/upload-macos <tag>`
6# if the detached run from the hook failed; the tarballs are already on disk and
7# uploading one twice replaces it rather than duplicating it.
8set -eu
9
10tag=${1:?usage: upload-macos <tag>}
11root=$(git rev-parse --show-toplevel)
12dist="$root/dist/macos/$tag"
13repo=$(git config --get remote.origin.url | sed 's#.*gitbay.org[:/]##; s#\.git$##')
14
15[ -d "$dist" ] || { echo "no build for $tag in $dist" >&2; exit 1; }
16
17# The release job builds two Linux targets before creating the release, so the
18# wait is minutes rather than seconds. Twenty minutes, then give up loudly.
19i=0
20until ssh git@gitbay.org release show "$repo" "$tag" >/dev/null 2>&1; do
21 i=$((i + 1))
22 if [ "$i" -gt 80 ]; then
23 echo "$(date -u +%FT%TZ) release $tag never appeared; rerun this script" >&2
24 exit 1
25 fi
26 sleep 15
27done
28
29for f in "$dist"/*.tar.gz "$dist"/*.sha256; do
30 [ -e "$f" ] || continue
31 ssh git@gitbay.org release asset add "$repo" "$tag" "$(basename "$f")" <"$f"
32 echo "$(date -u +%FT%TZ) attached $(basename "$f")"
33done
34echo "$(date -u +%FT%TZ) macOS assets attached to $tag"