11#! /usr/bin/env bash
22# Run spec syncing script and create PR
3+
4+ # SETUP
35SPEC_DEST=" $( realpath -s " ./test" ) "
46SRC_URL=" https://github.com/mongodb/specifications.git"
57# needs to be set for resunc-specs.sh
68SPEC_SRC=" $( realpath -s " ../specifications" ) "
79SCRIPT=" $( realpath -s " ./.evergreen/resync-specs.sh" ) "
810BRANCH_NAME=" spec-resync-" $( date ' +%m-%d-%Y' )
911
10- # List of directories to skip
11- SKIP_DIRECTORIES=(" asynchronous" " __pycache__" )
12- # we have a list of specs that we manually override *if the git diff is that specific line, then don't change it
13- # *ask in python channel
14- SKIP_FILES=()
15- # ask steve for how to create PR from evergreen account(?)
16- # for now, treat it like a command line thing and git add *, git commit, git push
17-
18- # Clone the repo if the directory does not exist
12+ # Clone the spec repo if the directory does not exist
1913if [[ ! -d $SPEC_SRC ]]; then
2014 git clone $SRC_URL $SPEC_SRC
2115 if [[ $? -ne 0 ]]; then
@@ -24,76 +18,23 @@ if [[ ! -d $SPEC_SRC ]]; then
2418 fi
2519fi
2620
27- # Set environment variable to the cloned repo for resync-specs.sh
21+ # Set environment variable to the cloned spec repo for resync-specs.sh
2822export MDB_SPECS=" $SPEC_SRC "
2923
30- # Check that resync script exists and is executable
24+ # Check that resync-specs.sh exists and is executable
3125if [[ ! -x $SCRIPT ]]; then
3226 echo " Error: $SCRIPT not found or is not executable."
3327 exit 1
3428fi
3529
36- # List to store names of specs that were changed or errored during change
37- changed_specs=()
38- errored_specs=()
30+ PR_DESC=" spec_sync.txt"
3931
40- # Create branch and switch to it
41- # git checkout -b $BRANCH_NAME 2>/dev/null || git checkout $BRANCH_NAME
42-
43- for item in " $SPEC_DEST " /* ; do
44- item_name=$( basename " $item " )
45- if [[ " ${SKIP_DIRECTORIES[*]} " =~ ${item_name} ]]; then
46- continue
47- fi
32+ # run python script that actually does all the resyncing
33+ /opt/devtools/bin/python3.11 ./.evergreen/scripts/resync-all-specs.py " $PR_DESC "
4834
49- # Check that item is not a python file
50- if [[ $item != * .py ]]; then
51- echo " doing $item_name "
52- output=$( $SCRIPT " $item_name " 2>&1 )
53- # Check if the script ran successfully
54- if [[ $? -ne 0 ]]; then
55- echo " an error occurred"
56- errored_specs+=($" $item_name \n\`\`\` $output \`\`\` \n\n" )
57- fi
58- fi
59- done
60-
61- # Output the list of changed specs
62- if git diff --quiet && [[ ${# errored_specs[@]} -eq 0 ]]; then
63- # no changes made and no errors
64- exit 0
65- fi
6635
67- pr_body= $' Spec sync results: \n\n '
68- if ! git diff --quiet ; then
69- pr_body+= $' The following specs were changed: \n '
70- pr_body+= " $( git diff --name-only | awk -F ' / ' ' {print $2} ' | sort | uniq ) "
36+ if [[ -f $PR_DESC ]] ; then
37+ # changes were made -> call scrypt to create PR for us
38+ .evergreen/scripts/create-pr.sh " $PR_DESC "
39+ rm " $PR_DESC "
7140fi
72-
73- # Output the list of errored specs
74- if [[ ${# errored_specs[@]} -gt 0 ]]; then
75- pr_body+=$" \n\nThe following spec syncs encountered errors:\n"
76- for spec in " ${errored_specs[@]} " ; do
77- pr_body+=" - $spec \n"
78- done
79- else
80- pr_body+=$" \nNo errors were encountered in any specs syncs.\n"
81- fi
82-
83- # Output the PR body (optional step for verification)
84- echo " PR body"
85- echo " $pr_body "
86- echo " $pr_body " >> spec_sync.txt
87-
88- echo " BEGINNING OF DIFF"
89- git diff
90- echo " END OF DIFF"
91-
92- # call scrypt to create PR for us
93- .evergreen/scripts/create-pr.sh spec_sync.txt
94-
95- rm spec_sync.txt
96- # git add $SPEC_DEST
97- # git commit -m $BRANCH_NAME
98- # git push -u origin $BRANCH_NAME
99- # gh pr create --title "[Spec Resync] $(date '+%m-%d-%Y')" --body "Resyncing specs for review" --base main --head $BRANCH_NAME --draft
0 commit comments