Skip to content

[Spec Resync] 06-24-2025 #2401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,014 changes: 2,014 additions & 0 deletions .evergreen/all.patch

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,22 @@ post:
- func: "upload mo artifacts"
- func: "upload test results"
- func: "cleanup"

tasks:
- name: resync_specs
commands:
- command: subprocess.exec
params:
binary: bash
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
args:
- .evergreen/scripts/resync-all-specs.sh
working_dir: src

buildvariants:
- name: resync_specs
display_name: "Resync Specs"
run_on: rhel80-small
patchable: true
tasks:
- name: resync_specs
9 changes: 6 additions & 3 deletions .evergreen/resync-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ then
fi

# Ensure the JSON files are up to date.
cd $SPECS/source
make
cd -
if ! [ -n "${CI:-}" ]
then
cd $SPECS/source
make
cd -
fi
# cpjson unified-test-format/tests/invalid unified-test-format/invalid
# * param1: Path to spec tests dir in specifications repo
# * param2: Path to where the corresponding tests live in Python.
Expand Down
63 changes: 63 additions & 0 deletions .evergreen/scripts/create-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

tools="../drivers-evergreen-tools"
git clone https://github.com/mongodb-labs/drivers-evergreen-tools.git $tools
body="$(cat "$1")"

pushd $tools/.evergreen/github_app

owner="mongodb"
repo="mongo-python-driver"

# Bootstrap the app.
echo "bootstrapping"
source utils.sh
bootstrap drivers/comment-bot

# Run the app.
source ./secrets-export.sh

# Get a github access token for the git checkout.
echo "Getting github token..."

token=$(bash ./get-access-token.sh $repo $owner)
if [ -z "${token}" ]; then
echo "Failed to get github access token!"
popd
exit 1
fi
echo "Getting github token... done."
popd

# Make the git checkout and create a new branch.
echo "Creating the git checkout..."
branch="spec-resync-"$(date '+%m-%d-%Y')

#git config user.email "167856002+mongodb-dbx-release-bot[bot]@users.noreply.github.com"
#git config user.name "mongodb-dbx-release-bot[bot]"
git remote set-url origin https://x-access-token:${token}@github.com/$owner/$repo.git
git checkout -b $branch "origin/master"
git add ./test
git apply -R .evergreen/specs.patch
git commit -am "resyncing specs test?"
echo "Creating the git checkout... done."

echo "THIS IS THE BODY"
echo "$body"
git push origin $branch
echo "{\"title\":\"[Spec Resync] $(date '+%m-%d-%Y')\",\"body\":\"$(cat "$1")\",\"head\":\"${branch}\",\"base\":\"master\"}"
resp=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d "{\"title\":\"[Spec Resync] $(date '+%m-%d-%Y')\",\"body\":\"$(cat "$1")\",\"head\":\"${branch}\",\"base\":\"master\"}" \
--url https://api.github.com/repos/$owner/$repo/pulls)
echo $resp
echo $resp | jq '.html_url'
echo "Creating the PR... done."

rm -rf $tools

# use file names or reg-ex patterns
# or automate which version of the spec we support (like schema version)
44 changes: 44 additions & 0 deletions .evergreen/scripts/resync-all-specs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import pathlib
import subprocess

print("in resync all specs py")
directory = pathlib.Path("./test")
succeeded: list[str] = []
errored: dict[str, str] = {}
print("right before for loop?")
for entry in os.scandir(directory):
if not entry.is_dir():
continue

print(entry.path)
spec_name = entry.path.split("/")[-1]
if spec_name in ["asynchronous"]:
continue
process = subprocess.run(
["bash", "./.evergreen/resync-specs.sh", spec_name],
capture_output=True,
text=True)
print(process.returncode)
if process.returncode == 0:
succeeded.append(spec_name)
else:
errored[spec_name] = process.stdout
pr_body = ""
if len(succeeded) == 0 and len(errored.keys()) == 0:
# no changes made and no errors
pass
if len(succeeded) > 0:
pr_body += "The following specs were changed:\n- "
pr_body += "\n- ".join(succeeded)
pr_body += "\n"
if len(errored) > 0:
pr_body += "\n\nThe following spec syncs encountered errors:"
for k, v in errored.items():
# pr_body += f"\n- {k}\n{v}"
pr_body += f"\n- {k}"
print("THIS IS PR BODY")
print(pr_body)

with open("spec_sync.txt", "w") as f:
f.write(pr_body.replace("\n", "\\n"))
107 changes: 107 additions & 0 deletions .evergreen/scripts/resync-all-specs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env bash
# Run spec syncing script and create PR
SPEC_DEST="$(realpath -s "./test")"
SRC_URL="https://github.com/mongodb/specifications.git"
# needs to be set for resunc-specs.sh
SPEC_SRC="$(realpath -s "../specifications")"
SCRIPT="$(realpath -s "./.evergreen/resync-specs.sh")"
BRANCH_NAME="spec-resync-"$(date '+%m-%d-%Y')

# List of directories to skip
SKIP_DIRECTORIES=("asynchronous" "__pycache__")
# we have a list of specs that we manually override *if the git diff is that specific line, then don't change it
# *ask in python channel
SKIP_FILES=()
# ask steve for how to create PR from evergreen account(?)
# for now, treat it like a command line thing and git add *, git commit, git push

# Clone the repo if the directory does not exist
if [[ ! -d $SPEC_SRC ]]; then
git clone $SRC_URL $SPEC_SRC
if [[ $? -ne 0 ]]; then
echo "Error: Failed to clone repository."
exit 1
fi
fi

# Set environment variable to the cloned repo for resync-specs.sh
export MDB_SPECS="$SPEC_SRC"

# Check that resync script exists and is executable
if [[ ! -x $SCRIPT ]]; then
echo "Error: $SCRIPT not found or is not executable."
exit 1
fi

/opt/devtools/bin/python3.11 ./.evergreen/scripts/resync-all-specs.py


## List to store names of specs that were changed or errored during change
#changed_specs=()
#errored_specs=()
#
## Create branch and switch to it
##git checkout -b $BRANCH_NAME 2>/dev/null || git checkout $BRANCH_NAME
#
#for item in "$SPEC_DEST"/*; do
# item_name=$(basename "$item")
# if [[ " ${SKIP_DIRECTORIES[*]} " =~ ${item_name} ]]; then
# continue
# fi
#
# # Check that item is not a python file
# if [[ $item != *.py ]]; then
# echo " doing $item_name"
# output=$($SCRIPT "$item_name" 2>&1)
# # Check if the script ran successfully
# if [[ $? -ne 0 ]]; then
# echo "an error occurred"
## errored_specs+=("$item_name\n\`\`\`$output\`\`\`\n\n")
# errored_specs+=("$item_name\n")
# fi
# fi
#done
#
## change this to python, call the python script here, then pass it forward to create-pr script.
#
## Output the list of changed specs
#if git diff --quiet && [[ ${#errored_specs[@]} -eq 0 ]]; then
# # no changes made and no errors
# exit 0
#fi
#
#pr_body='Spec sync results:\n\n'
#if ! git diff --quiet; then
# pr_body+="The following specs were changed:\n"
# pr_body+="$(git diff --name-only | awk -F'/' '{print $2}' | sort | uniq | tr '\n' '\\n')"
#fi
#
## Output the list of errored specs
#if [[ ${#errored_specs[@]} -gt 0 ]]; then
# pr_body+="\n\nThe following spec syncs encountered errors:\n"
# for spec in "${errored_specs[@]}"; do
# pr_body+=" - $spec\n"
# done
#else
# pr_body+="\nNo errors were encountered in any specs syncs.\n"
#fi
#
## Output the PR body (optional step for verification)
#echo "PR body"
#echo "$pr_body" | tr '\n' '\\n'
#echo "$pr_body" | tr '\n' '\\n' >> spec_sync.txt
#
echo "BEGINNING OF DIFF"
git diff
echo "END OF DIFF"
#
# call scrypt to create PR for us
.evergreen/scripts/create-pr.sh spec_sync.txt
#
#rm spec_sync.txt
#git add $SPEC_DEST
#git commit -m $BRANCH_NAME
#git push -u origin $BRANCH_NAME
#gh pr create --title "[Spec Resync] $(date '+%m-%d-%Y')" --body "Resyncing specs for review" --base main --head $BRANCH_NAME --draft

# just get it working, we can identify pain points later after we have something to work with
Loading
Loading