scripts: upload_prebuilts: Handle version prefixes other than "chroot-"

Previously, upload_prebuilts assumed that the version prefix was "chroot-",
and chopped off the first 7 characters of the prefix+version string to
get the version alone. This updates the code to be a bit more robust,
instead looking for the expected format of the version and stripping
the prefix that precedes it.

BUG=b:289990183
TEST=./run_tests scripts/upload_prebuilts_unittest.py

Change-Id: Id36dd69c0e7529885151f26f41d86b5ce573de5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4669938
Commit-Queue: Bob Haarman <inglorion@chromium.org>
Tested-by: Bob Haarman <inglorion@chromium.org>
Reviewed-by: Lizzy Presland <zland@google.com>
diff --git a/scripts/upload_prebuilts.py b/scripts/upload_prebuilts.py
index 0425f14..1c685b0 100644
--- a/scripts/upload_prebuilts.py
+++ b/scripts/upload_prebuilts.py
@@ -25,6 +25,7 @@
 import multiprocessing
 import os
 from pathlib import Path
+import re
 import tempfile
 from typing import Optional, Tuple
 
@@ -491,7 +492,12 @@
         assert boardname == constants.CHROOT_BUILDER_BOARD
         assert prepackaged is not None
 
-        version_str = self._version[len("chroot-") :]
+        # _version consists of a prefix followed by the actual version.
+        # We want the version without the prefix. It starts with the
+        # year, month, and date in YYYY.MM.DD format, so we match that.
+        m = re.match(r"(.*-)?(\d\d\d\d\.\d\d\.\d\d.*)", self._version)
+        assert m, "version does not match format .*YYYY.MM.DD.*"
+        version_str = m[2]
         remote_tarfile = toolchain.GetSdkURL(
             for_gsutil=True, suburl="cros-sdk-%s.tar.xz" % (version_str,)
         )