| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Decide whether a validated CLI release manifest may and should replace one |
| 5 | # public channel pointer. Newer tags advance the pointer, older tags never do, |
| 6 | # and equal tags repair the pointer when its exact metadata differs. |
| 7 | |
| 8 | if [ "$#" -ne 3 ]; then |
| 9 | echo "usage: $0 CHANNEL CANDIDATE_MANIFEST CURRENT_MANIFEST|-" >&2 |
| 10 | exit 2 |
| 11 | fi |
| 12 | |
| 13 | script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 14 | compare="$script_dir/compare-cli-release-tags.sh" |
| 15 | channel="$1" |
| 16 | candidate_file="$2" |
| 17 | current_file="$3" |
| 18 | |
| 19 | case "$channel" in |
| 20 | stable | preview) ;; |
| 21 | *) |
| 22 | echo "unsupported CLI pointer channel: $channel" >&2 |
| 23 | exit 2 |
| 24 | ;; |
| 25 | esac |
| 26 | if [ ! -f "$candidate_file" ]; then |
| 27 | echo "candidate CLI manifest is not a readable file: $candidate_file" >&2 |
| 28 | exit 2 |
| 29 | fi |
| 30 | |
| 31 | candidate_tag="$(jq -er '.tag_name | strings' "$candidate_file")" |
| 32 | bash "$compare" "$channel" "$candidate_tag" "" >/dev/null |
| 33 | if [ "$current_file" = "-" ]; then |
| 34 | echo update |
| 35 | exit 0 |
| 36 | fi |
| 37 | if [ ! -f "$current_file" ]; then |
| 38 | echo "current CLI manifest is not a readable file: $current_file" >&2 |
| 39 | exit 2 |
| 40 | fi |
| 41 | |
| 42 | current_tag="$(jq -er '.tag_name | strings' "$current_file")" |
| 43 | decision="$(bash "$compare" "$channel" "$candidate_tag" "$current_tag")" |
| 44 | if [ "$current_tag" != "$candidate_tag" ] && [ "$decision" = "skip" ]; then |
| 45 | echo skip |
| 46 | elif cmp -s "$candidate_file" "$current_file"; then |
| 47 | echo skip |
| 48 | else |
| 49 | echo update |
| 50 | fi |
| 51 |