summaryrefslogtreecommitdiff
path: root/.github/scripts/check-candidate-tag.sh
blob: 860f91f285064b5197724183d22830087efbe127 (plain)
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
#!/usr/bin/env bash

set -euo pipefail

if [ "$#" -ne 2 ]; then
  echo "Usage: check-candidate-tag.sh TAG EXPECTED_SHA" >&2
  exit 2
fi

tag=$1
expected_sha=$2
ref="refs/tags/$tag"

if git show-ref --verify --quiet "$ref"; then
  if ! current=$(git rev-parse --verify --quiet "$ref^{commit}"); then
    echo "::error::$tag does not identify a commit" >&2
    exit 1
  fi
  if [ "$current" != "$expected_sha" ]; then
    echo "::error::$tag already exists at $current; release tags are never moved" >&2
    exit 1
  fi
  printf 'exists=true\n'
  printf '%s already identifies %s; creation is idempotently satisfied.\n' "$tag" "$expected_sha" >&2
else
  status=$?
  if [ "$status" -ne 1 ]; then
    echo "::error::Could not inspect $ref (git show-ref exited $status)" >&2
    exit "$status"
  fi
  printf 'exists=false\n'
fi