summaryrefslogtreecommitdiff
path: root/lookup
diff options
context:
space:
mode:
Diffstat (limited to 'lookup')
-rwxr-xr-xlookup132
1 files changed, 132 insertions, 0 deletions
diff --git a/lookup b/lookup
new file mode 100755
index 0000000..df0d5bb
--- /dev/null
+++ b/lookup
@@ -0,0 +1,132 @@
+#!/usr/bin/env bash
+
+# shellcheck disable=1090
+
+set -e -u -o pipefail
+
+main() {
+ lookup=$1
+
+ # default_repo=https://github.com/yaml/yaml-test-suite
+ # default_commit=origin/data
+ repo=
+ commit=
+ env=
+
+ if [[ $lookup == data ]]; then
+ debug "Looking up test-suite data repo/commit"
+ elif [[ $lookup == env ]]; then
+ debug "Looking up test-suite env"
+ fi
+
+ base=$(cd ../.. && pwd)
+ head=$(get-head-commit)
+
+ if [[ ${LIBYAML_TEST_SUITE_ENV-} ]]; then
+ lookup-env
+ else
+ [[ $env ]] || lookup-log
+ [[ $env ]] || lookup-local
+ fi
+
+ if [[ $lookup == data ]]; then
+ [[ $repo && $commit ]] ||
+ die "Can't find yaml-test-suite env to use"
+ echo "$repo $commit"
+ elif [[ $lookup == env ]]; then
+ [[ $env ]] ||
+ die "Can't find yaml-test-suite env to use"
+ echo "$env"
+ fi
+}
+
+get-head-commit() {
+ debug "Getting libyaml HEAD commit"
+
+ [[ -d $base/.git ]] ||
+ die "'$base' is not a git repository"
+
+ head=$(cd "$base" && git rev-parse HEAD)
+
+ [[ $head ]] ||
+ die "Can't find HEAD commit in '$base'"
+
+ debug "HEAD commit is '$head'"
+
+ echo "$head"
+}
+
+lookup-env() {
+ local lookup=$LIBYAML_TEST_SUITE_ENV
+
+ debug "Trying LIBYAML_TEST_SUITE_ENV=$lookup"
+
+ case $lookup in
+ /*)
+ env=$lookup
+ source "$env"
+ found
+ ;;
+ pin-*)
+ env=env/$lookup
+ [[ -e $env ]] ||
+ die "Specified LIBYAML_TEST_SUITE_ENV=$lookup but '$env' not found"
+ source "$env"
+ found
+ ;;
+ time)
+ die "LIBYAML_TEST_SUITE_ENV=time not yet implemented"
+ ;;
+ *)
+ die "Unsupported value 'LIBYAML_TEST_SUITE_ENV=$lookup'"
+ ;;
+ esac
+}
+
+lookup-log() {
+ debug "Looking for '*** yaml-test-suite' in most recent 'git log' message"
+
+ found=$(
+ cd "$base" || exit
+ git log --format=%B -n1 |
+ (grep -A999999 '^\*\*\*\ yaml-test-suite' || true) |
+ tail -n+2
+ )
+ if [[ $found ]]; then
+ env=env/tmp-$head
+ echo "$found" > "$env"
+ source "$env"
+ found
+ fi
+}
+
+lookup-local() {
+ debug "Looking for local env for '$head'"
+
+ local e=env/pin-$head
+
+ if [[ -e $e ]]; then
+ env=$e
+ source "./env/pin-$head"
+ found
+ fi
+}
+
+found() {
+ debug "Found '$env'"
+
+ repo=$LIBYAML_TEST_SUITE_DATA_REPO
+ commit=$LIBYAML_TEST_SUITE_DATA_COMMIT
+}
+
+whitelist() (:)
+blacklist() (:)
+die() { echo "Died: $*" >&2; exit 1; }
+warn() ( echo "$*" >&2 )
+debug() (
+ if [[ ${LIBYAML_TEST_SUITE_DEBUG-} ]]; then
+ warn "[DEBUG] $*"
+ fi
+)
+
+main "$@"