Rework update_reference.sh to run correctly in CI.

We achieve this by skipping the build step and allowing running the
script from any directory.

Change-Id: I05c29dd80b961c7c6dcab8611a6135b16a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/22260
Commit-Queue: Matt Stark <msta@google.com>
Reviewed-by: Takuto Ikuta <tikuta@google.com>
diff --git a/tools/update_reference.sh b/tools/update_reference.sh
index 99bd0ee..ecf1899 100755
--- a/tools/update_reference.sh
+++ b/tools/update_reference.sh
@@ -5,20 +5,20 @@
     check=true
 fi
 
-# Check for the existance of the AUTHORS file as an easy way to determine if
-# it's being run from the correct directory.
-if test -f "AUTHORS"; then
+# Ensure we're always running in the correct directory.
+cd "$(dirname $(dirname "${BASH_SOURCE[0]}"))"
+
+# If NOBUILD is set, we skip building GN. This is useful for
+# CI, where we've just built it, and ninja is not present in the path.
+if [[ -z "${NOBUILD:-}" ]]; then
     echo Building gn...
     ninja -C out gn
-    echo Generating new docs/reference.md...
-    content=$(out/gn help --markdown all)
+fi
+echo Generating new docs/reference.md...
+content=$(out/gn help --markdown all)
 
-    if "${check}"; then
-        diff -u docs/reference.md <(echo "$content")
-    else
-        echo "$content" > docs/reference.md
-    fi
+if "${check}"; then
+    diff -u docs/reference.md <(echo "$content")
 else
-    echo Please run this command from the GN checkout root directory.
-    exit 1
+    echo "$content" > docs/reference.md
 fi