Skip to content

Commit 13fa5ab

Browse files
committed
firebase-dataconnect/scripts/missingversions.py added
1 parent 9496674 commit 13fa5ab

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2025 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Run this script in the root directory of this Git repository to
18+
# determine the versions of the Data Connect Toolkit that are missing
19+
# from the DataConnectExecutableVersions.json file. The final output
20+
# of this script will be the gradle command to run to update the json
21+
# file.
22+
#
23+
# Make sure to run "pip install packaging" before running this script.
24+
25+
import json
26+
import os
27+
from packaging.version import Version
28+
import re
29+
import subprocess
30+
import tempfile
31+
32+
regex = re.compile(r".*dataconnect-emulator-linux-v(\d+\.\d+\.\d+)")
33+
json_path = os.path.abspath("firebase-dataconnect/gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/plugin/DataConnectExecutableVersions.json")
34+
min_version = Version("1.3.4")
35+
bucket = "gs://firemat-preview-drop/emulator/"
36+
37+
args = ["gsutil", "ls", "-r", bucket]
38+
print("Getting versions by running: " + subprocess.list2cmdline(args))
39+
with tempfile.TemporaryFile() as f:
40+
subprocess.check_call(args, stdout=f)
41+
f.seek(0)
42+
filenames = f.read().decode("utf8", errors="strict").splitlines()
43+
44+
filename_matches = [regex.fullmatch(filename) for filename in filenames]
45+
versions_set = set(match.group(1) for match in filename_matches if match is not None)
46+
all_versions = sorted(versions_set, key=Version)
47+
versions = [version for version in all_versions if Version(version) >= min_version]
48+
49+
try:
50+
invalid_version_index = versions.index("1.15.0")
51+
except ValueError:
52+
pass
53+
else:
54+
versions.pop(invalid_version_index)
55+
56+
print(f"Found {len(versions)} versions greater than {min_version}: {versions!r}")
57+
print()
58+
59+
with open(json_path, "rb") as f:
60+
known_versions_map = json.load(f)
61+
known_versions_set = frozenset(version_info["version"] for version_info in known_versions_map["versions"])
62+
known_versions = sorted(known_versions_set, key=Version)
63+
print(f"Found {len(known_versions)} versions in {os.path.basename(json_path)}: {known_versions!r}")
64+
print()
65+
66+
missing_versions = [version for version in versions if version not in known_versions]
67+
print(f"Found {len(missing_versions)} missing versions in {os.path.basename(json_path)}: {missing_versions!r}")
68+
print()
69+
70+
print(f"Run this gradle command to update {json_path}:")
71+
print(f"./gradlew :firebase-dataconnect:connectors:updateJson -Pversions={",".join(missing_versions)} -PdefaultVersion={versions[-1]}")

0 commit comments

Comments
 (0)