#!/bin/bash
set -euo pipefail

export CREATE_POD_SPECS_DEBUG=1

function check() {
	local expect=$1
	local got=$2
	echo -n "checking whether '$expect' equals '$got'... " 1>&2
	if [[ "$got" != "$expect" ]]; then
		echo "NO" 1>&2
		exit 1
	fi
	echo "yes"
}

# A tag publishes as the tag without its leading "v".
got=$(GITHUB_REF_TYPE=tag GITHUB_REF_NAME=v3.30.0 ./MOBILE/ios/createpodspecs)
check "3.30.0" "$got"

got=$(GITHUB_REF_TYPE=tag GITHUB_REF_NAME=v3.30.0-alpha ./MOBILE/ios/createpodspecs)
check "3.30.0-alpha" "$got"

# Any other build (branch push or the nightly rolling cron) publishes as
# 0.0.0-<short commit>.
got=$(GITHUB_REF_TYPE=branch GITHUB_SHA=abcdef1234567890 ./MOBILE/ios/createpodspecs)
check "0.0.0-abcdef12" "$got"
