Skip to content

Commit 4e5eca0

Browse files
author
Cloud User
committed
resyncing specs test?
1 parent 65f7c54 commit 4e5eca0

File tree

61 files changed

+13615
-1370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+13615
-1370
lines changed

.evergreen/all.patch

Lines changed: 2014 additions & 0 deletions
Large diffs are not rendered by default.

.evergreen/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,22 @@ post:
4242
- func: "upload mo artifacts"
4343
- func: "upload test results"
4444
- func: "cleanup"
45+
46+
tasks:
47+
- name: resync_specs
48+
commands:
49+
- command: subprocess.exec
50+
params:
51+
binary: bash
52+
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
53+
args:
54+
- .evergreen/scripts/resync-all-specs.sh
55+
working_dir: src
56+
57+
buildvariants:
58+
- name: resync_specs
59+
display_name: "Resync Specs"
60+
run_on: rhel80-small
61+
patchable: true
62+
tasks:
63+
- name: resync_specs

.evergreen/resync-specs.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ then
4545
fi
4646

4747
# Ensure the JSON files are up to date.
48-
cd $SPECS/source
49-
make
50-
cd -
48+
if ! [ -n "${CI:-}" ]
49+
then
50+
cd $SPECS/source
51+
make
52+
cd -
53+
fi
5154
# cpjson unified-test-format/tests/invalid unified-test-format/invalid
5255
# * param1: Path to spec tests dir in specifications repo
5356
# * param2: Path to where the corresponding tests live in Python.

.evergreen/scripts/create-pr.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
tools="../drivers-evergreen-tools"
4+
git clone https://github.com/mongodb-labs/drivers-evergreen-tools.git $tools
5+
body="$(cat "$1")"
6+
7+
pushd $tools/.evergreen/github_app
8+
9+
owner="mongodb"
10+
repo="mongo-python-driver"
11+
12+
# Bootstrap the app.
13+
echo "bootstrapping"
14+
source utils.sh
15+
bootstrap drivers/comment-bot
16+
17+
# Run the app.
18+
source ./secrets-export.sh
19+
20+
# Get a github access token for the git checkout.
21+
echo "Getting github token..."
22+
23+
token=$(bash ./get-access-token.sh $repo $owner)
24+
if [ -z "${token}" ]; then
25+
echo "Failed to get github access token!"
26+
popd
27+
exit 1
28+
fi
29+
echo "Getting github token... done."
30+
popd
31+
32+
# Make the git checkout and create a new branch.
33+
echo "Creating the git checkout..."
34+
branch="spec-resync-"$(date '+%m-%d-%Y')
35+
36+
#git config user.email "167856002+mongodb-dbx-release-bot[bot]@users.noreply.github.com"
37+
#git config user.name "mongodb-dbx-release-bot[bot]"
38+
git remote set-url origin https://x-access-token:${token}@github.com/$owner/$repo.git
39+
git checkout -b $branch "origin/master"
40+
git add ./test
41+
git apply -R .evergreen/specs.patch
42+
git commit -am "resyncing specs test?"
43+
echo "Creating the git checkout... done."
44+
45+
echo "THIS IS THE BODY"
46+
echo "$body"
47+
git push origin $branch
48+
echo "{\"title\":\"[Spec Resync] $(date '+%m-%d-%Y')\",\"body\":\"$(cat "$1")\",\"head\":\"${branch}\",\"base\":\"master\"}"
49+
resp=$(curl -L \
50+
-X POST \
51+
-H "Accept: application/vnd.github+json" \
52+
-H "Authorization: Bearer $token" \
53+
-H "X-GitHub-Api-Version: 2022-11-28" \
54+
-d "{\"title\":\"[Spec Resync] $(date '+%m-%d-%Y')\",\"body\":\"$(cat "$1")\",\"head\":\"${branch}\",\"base\":\"master\"}" \
55+
--url https://api.github.com/repos/$owner/$repo/pulls)
56+
echo $resp
57+
echo $resp | jq '.html_url'
58+
echo "Creating the PR... done."
59+
60+
rm -rf $tools
61+
62+
# use file names or reg-ex patterns
63+
# or automate which version of the spec we support (like schema version)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import pathlib
3+
import subprocess
4+
import argparse
5+
6+
7+
def resync_specs(directory: pathlib.Path, succeeded: list[str], errored: dict[str, str]) -> None:
8+
for entry in os.scandir(directory):
9+
if not entry.is_dir():
10+
continue
11+
12+
print(entry.path)
13+
spec_name = entry.path.split("/")[-1]
14+
if spec_name in ["asynchronous"]:
15+
continue
16+
process = subprocess.run(
17+
["bash", "./.evergreen/resync-specs.sh", spec_name],
18+
capture_output=True,
19+
text=True)
20+
print(process.returncode)
21+
if process.returncode == 0:
22+
succeeded.append(spec_name)
23+
print(process.stdout)
24+
print(process.stderr)
25+
else:
26+
errored[spec_name] = process.stdout
27+
28+
def write_summary(succeeded: list[str], errored: dict[str, str]) -> None:
29+
pr_body = ""
30+
if len(succeeded) > 0:
31+
pr_body += "The following specs were changed:\n- "
32+
process = subprocess.run(
33+
["git diff --name-only | awk -F'/' '{print $2}' | sort | uniq"],
34+
shell=True,
35+
capture_output=True,
36+
text=True)
37+
pr_body += process.stdout.replace("\n", "\n- ")
38+
# pr_body += "\n- ".join(succeeded)
39+
pr_body += "\n"
40+
if len(errored) > 0:
41+
pr_body += "\n\nThe following spec syncs encountered errors:"
42+
for k, v in errored.items():
43+
pr_body += f"\n- {k}\n```{v}\n```"
44+
45+
if pr_body != "":
46+
with open("spec_sync.txt", "w") as f:
47+
# replacements made for to be json
48+
f.write(pr_body.replace("\n", "\\n").replace("\t", "\\t"))
49+
50+
def main():
51+
directory = pathlib.Path("./test")
52+
succeeded: list[str] = []
53+
errored: dict[str, str] = {}
54+
resync_specs(directory, succeeded, errored)
55+
write_summary(succeeded, errored)
56+
57+
if __name__ == "__main__":
58+
parser = argparse.ArgumentParser(description="Python Script to resync all specs and generate summary for PR.")
59+
parser.add_argument("filename", help="Name of file for the summary to be written into.")
60+
args = parser.parse_args()
61+
main()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# Run spec syncing script and create PR
3+
4+
# SETUP
5+
SPEC_DEST="$(realpath -s "./test")"
6+
SRC_URL="https://github.com/mongodb/specifications.git"
7+
# needs to be set for resunc-specs.sh
8+
SPEC_SRC="$(realpath -s "../specifications")"
9+
SCRIPT="$(realpath -s "./.evergreen/resync-specs.sh")"
10+
BRANCH_NAME="spec-resync-"$(date '+%m-%d-%Y')
11+
12+
# Clone the spec repo if the directory does not exist
13+
if [[ ! -d $SPEC_SRC ]]; then
14+
git clone $SRC_URL $SPEC_SRC
15+
if [[ $? -ne 0 ]]; then
16+
echo "Error: Failed to clone repository."
17+
exit 1
18+
fi
19+
fi
20+
21+
# Set environment variable to the cloned spec repo for resync-specs.sh
22+
export MDB_SPECS="$SPEC_SRC"
23+
24+
# Check that resync-specs.sh exists and is executable
25+
if [[ ! -x $SCRIPT ]]; then
26+
echo "Error: $SCRIPT not found or is not executable."
27+
exit 1
28+
fi
29+
30+
PR_DESC="spec_sync.txt"
31+
32+
# run python script that actually does all the resyncing
33+
/opt/devtools/bin/python3.11 ./.evergreen/scripts/resync-all-specs.py "$PR_DESC"
34+
35+
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"
40+
fi

0 commit comments

Comments
 (0)