Skip to content

Commit 87d73cc

Browse files
committed
allow scripts to be run locally
1 parent f45fd46 commit 87d73cc

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

.evergreen/remove-unimplemented-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ rm $PYMONGO/test/crud/unified/updateMany-rawdata.json
4343
rm $PYMONGO/test/crud/unified/updateOne-rawdata.json
4444
rm $PYMONGO/test/index_management/index-rawdata.json
4545

46-
echo "done removing unimplemented tests"
46+
echo "Done removing unimplemented tests\n"

.evergreen/scripts/resync-all-specs.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import os
55
import pathlib
66
import subprocess
7+
from argparse import Namespace
78
from subprocess import CalledProcessError
9+
from typing import Optional
810

911

1012
def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
1113
"""Actually sync the specs"""
14+
print("Beginning to sync specs") # noqa: T201
1215
for spec in os.scandir(directory):
1316
if not spec.is_dir():
1417
continue
@@ -24,11 +27,13 @@ def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
2427
)
2528
except CalledProcessError as exc:
2629
errored[spec.name] = exc.stderr
30+
print("Done syncing specs") # noqa: T201
2731

2832

2933
def apply_patches():
34+
print("Beginning to apply patches") # noqa: T201
3035
subprocess.run(["bash", "./.evergreen/remove-unimplemented-tests.sh"], check=True) # noqa: S603, S607
31-
subprocess.run(["git apply -R --allow-empty ./.evergreen/patch/*"], shell=True, check=True) # noqa: S602, S607
36+
subprocess.run(["git apply -R --allow-empty ./.evergreen/spec-patch/*"], shell=True, check=True) # noqa: S602, S607
3237

3338

3439
def check_new_spec_directories(directory: pathlib.Path) -> list[str]:
@@ -61,7 +66,7 @@ def check_new_spec_directories(directory: pathlib.Path) -> list[str]:
6166
return list(spec_set - test_set)
6267

6368

64-
def write_summary(errored: dict[str, str], new: list[str]) -> None:
69+
def write_summary(errored: dict[str, str], new: list[str], filename: Optional[str]) -> None:
6570
"""Generate the PR description"""
6671
pr_body = ""
6772
process = subprocess.run(
@@ -86,24 +91,29 @@ def write_summary(errored: dict[str, str], new: list[str]) -> None:
8691
pr_body += "\n -".join(new)
8792
pr_body += "\n"
8893
if pr_body != "":
89-
with open("spec_sync.txt", "w") as f:
90-
# replacements made for proper json
91-
f.write(pr_body.replace("\n", "\\n").replace("\t", "\\t"))
94+
if filename is None:
95+
print(f"\n{pr_body}") # noqa: T201
96+
else:
97+
with open(filename, "w") as f:
98+
# replacements made for proper json
99+
f.write(pr_body.replace("\n", "\\n").replace("\t", "\\t"))
92100

93101

94-
def main():
102+
def main(args: Namespace):
95103
directory = pathlib.Path("./test")
96104
errored: dict[str, str] = {}
97105
resync_specs(directory, errored)
98106
apply_patches()
99107
new = check_new_spec_directories(directory)
100-
write_summary(errored, new)
108+
write_summary(errored, new, args.filename)
101109

102110

103111
if __name__ == "__main__":
104112
parser = argparse.ArgumentParser(
105113
description="Python Script to resync all specs and generate summary for PR."
106114
)
107-
parser.add_argument("filename", help="Name of file for the summary to be written into.")
115+
parser.add_argument(
116+
"--filename", help="Name of file for the summary to be written into.", default=None
117+
)
108118
args = parser.parse_args()
109-
main()
119+
main(args)

.evergreen/scripts/resync-all-specs.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
# SETUP
55
SRC_URL="https://github.com/mongodb/specifications.git"
6-
# needs to be set for resunc-specs.sh
7-
SPEC_SRC="$(realpath -s "../specifications")"
8-
SCRIPT="$(realpath -s "./.evergreen/resync-specs.sh")"
6+
# needs to be set for resync-specs.sh
7+
SPEC_SRC="$(realpath "../specifications")"
8+
SCRIPT="$(realpath "./.evergreen/resync-specs.sh")"
99

1010
# Clone the spec repo if the directory does not exist
1111
if [[ ! -d $SPEC_SRC ]]; then
@@ -28,11 +28,15 @@ fi
2828
PR_DESC="spec_sync.txt"
2929

3030
# run python script that actually does all the resyncing
31-
/opt/devtools/bin/python3.11 ./.evergreen/scripts/resync-all-specs.py "$PR_DESC"
32-
33-
34-
if [[ -f $PR_DESC ]]; then
35-
# changes were made -> call scrypt to create PR for us
36-
.evergreen/scripts/create-pr.sh "$PR_DESC"
37-
rm "$PR_DESC"
31+
if ! [ -n "${CI:-}" ]
32+
then
33+
# we're running locally
34+
python3 ./.evergreen/scripts/resync-all-specs.py
35+
else
36+
/opt/devtools/bin/python3.11 ./.evergreen/scripts/resync-all-specs.py "$PR_DESC"
37+
if [[ -f $PR_DESC ]]; then
38+
# changes were made -> call scrypt to create PR for us
39+
.evergreen/scripts/create-spec-pr.sh "$PR_DESC"
40+
rm "$PR_DESC"
41+
fi
3842
fi

0 commit comments

Comments
 (0)