Fix with ci at head (#261)

* enable running with bazel head with latest bazel config

* fixing / buildifier

* doc fixes
diff --git a/rules/rbe_repo.bzl b/rules/rbe_repo.bzl
index 6a03d4c..98a1a04 100644
--- a/rules/rbe_repo.bzl
+++ b/rules/rbe_repo.bzl
@@ -135,7 +135,6 @@
 
 load(
     "@bazel_toolchains//rules:version_check.bzl",
-    "check_bazel_version",
     "extract_version_number",
     "parse_rc",
 )
@@ -196,8 +195,7 @@
     bazel_version = None
     bazel_rc_version = None
     if ctx.attr.bazel_version == "local":
-        check_bazel_version()
-        bazel_version = str(extract_version_number(native.bazel_version))
+        bazel_version = str(extract_version_number(ctx.attr.bazel_version_fallback))
         rc = parse_rc(native.bazel_version)
         bazel_rc_version = rc if rc != -1 else None
     if ctx.attr.bazel_version != "local":
@@ -451,6 +449,11 @@
             doc = ("Optional. An rc version to use. Note an installer for the rc " +
                    "must be available in https://releases.bazel.build."),
         ),
+        "bazel_version_fallback": attr.string(
+            default = "0.20.0",
+            doc = ("Version to fallback to if not provided explicitly and local " +
+                   "is non release version."),
+        ),
         "digest": attr.string(
             mandatory = True,
             doc = ("The digest (sha256 sum) of the rbe-ubuntu16-04 " +
@@ -515,7 +518,9 @@
       bazel_version: The version of Bazel to use to generate toolchain configs.
           `Use only (major, minor, patch), e.g., '0.20.0'. Default is "local"
           which means the same version of Bazel that is currently running will
-          be used.
+          be used. If local is a non release version, rbe_autoconfig will fallback
+          to using the latest release version (see default for bazel_version_fallback
+          in attrs of _rbe_autoconfig for current latest).
       bazel_rc: The rc (for the given version of Bazel) to use. Must be published
           in https://releases.bazel.build
       output_base: Optional. The directory (under the project root) where the
diff --git a/rules/version_check.bzl b/rules/version_check.bzl
index dce2994..2041b49 100644
--- a/rules/version_check.bzl
+++ b/rules/version_check.bzl
@@ -1,6 +1,6 @@
 """ Helpers to parse and check version of bazel."""
 
-def extract_version_number(bazel_version):
+def extract_version_number(bazel_version_fallback):
     """Extracts the semantic version number from a version string
 
     Args:
@@ -10,6 +10,7 @@
     Returns:
       The semantic version string, like "1.2.3".
     """
+    bazel_version = _check_bazel_version(bazel_version_fallback)
     for i in range(len(bazel_version)):
         c = bazel_version[i]
         if not (c.isdigit() or c == "."):
@@ -27,9 +28,12 @@
                 return int(rc)
             rc += c
 
-def check_bazel_version():
+def _check_bazel_version(bazel_version_fallback):
     if "bazel_version" not in dir(native):
         fail("\nCurrent Bazel version is lower than 0.2.1 and is not supported with rbe_autoconfig.")
     elif not native.bazel_version:
-        fail("\nCurrent running Bazel is not a release version and one " +
-             " was not defined explicitly in rbe_autoconfig target.")
+        print(("\nCurrent running Bazel is not a release version and one " +
+               "was not defined explicitly in rbe_autoconfig target. " +
+               "Falling back to '%s'") % bazel_version_fallback)
+        return bazel_version_fallback
+    return native.bazel_version