-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch-releases
More file actions
executable file
·52 lines (42 loc) · 1.13 KB
/
watch-releases
File metadata and controls
executable file
·52 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
set -euo pipefail
_dir="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# Do not pipe gh output to a pager
unset PAGER
print_recent_releases() {
gh release list --limit=10
}
get_releases() {
template='
{{- range . -}}
{{ " - " }}{{- .tag_name -}} {{- "\n"}}
{{- end -}}
'
gh api '/repos/{owner}/{repo}/releases' --template="$template"
}
if [ -z "$(print_recent_releases)" ]; then
echo 'This repository has no releases'
exit
fi
if ! [ "$(gh api '/repos/{owner}/{repo}/commits/{branch}/status' --jq='.state')" = 'pending' ]; then
echo 'Commit status is not "pending", so here are the ten most recent releases:'
print_recent_releases
exit
fi
prev_releases="$(get_releases)"
"$_dir"/watch-commit-status
# `diff` exits `1` when differences are found
set +e
# Diff, only displaying changed groups, and hiding any control characters
diff="$(diff \
--ignore-all-space \
--changed-group-format='%<%>' \
<(echo "$prev_releases") <(get_releases)
)"
set -e
if [ -z "$diff" ]; then
echo 'There are no new releases since running this command, so here are the most recent releases:'
print_recent_releases
exit
fi
echo "$diff"