|
| 1 | +#!/bin/bash |
| 2 | +# Run spec syncing script and create PR |
| 3 | + |
| 4 | +SPEC_DEST="../../test" |
| 5 | +SRC_URL="https://github.com/mongodb/specifications.git" |
| 6 | +# needs to be set for resunc-specs.sh |
| 7 | +SPEC_SRC="../../../specifications" |
| 8 | +SCRIPT="../resync-specs.sh" |
| 9 | +BRANCH_NAME="spec-resync-"$(date '+%m-%d-%Y') |
| 10 | + |
| 11 | +# List of directories to skip |
| 12 | +SKIP_DIRECTORIES=("asynchronous" "__pycache__") |
| 13 | +# we have a list of specs that we manually override *if the git diff is that specific line, then don't change it |
| 14 | +# *ask in python channel |
| 15 | +SKIP_FILES=() |
| 16 | +# ask steve for how to create PR from evergreen account(?) |
| 17 | +# for now, treat it like a command line thing and git add *, git commit, git push |
| 18 | + |
| 19 | +# Clone the repo if the directory does not exist |
| 20 | +if [[ ! -d $SPEC_SRC ]]; then |
| 21 | + git clone $SRC_URL $SPEC_SRC |
| 22 | + if [[ $? -ne 0 ]]; then |
| 23 | + echo "Error: Failed to clone repository." |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +fi |
| 27 | + |
| 28 | +# Set environment variable to the cloned repo for resync-specs.sh |
| 29 | +export MDB_SPECS="$SPEC_SRC" |
| 30 | + |
| 31 | +# Check that resync script exists and is executable |
| 32 | +if [[ ! -x $SCRIPT ]]; then |
| 33 | + echo "Error: $SCRIPT not found or is not executable." |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +# List to store names of specs that were changed or errored during change |
| 38 | +changed_specs=() |
| 39 | +errored_specs=() |
| 40 | + |
| 41 | +# Create branch and switch to it |
| 42 | +git checkout -b $BRANCH_NAME 2>/dev/null || git checkout $BRANCH_NAME |
| 43 | + |
| 44 | +for item in "$SPEC_DEST"/*; do |
| 45 | + item_name=$(basename "$item") |
| 46 | + if [[ " ${SKIP_DIRECTORIES[*]} " =~ ${item_name} ]]; then |
| 47 | + continue |
| 48 | + fi |
| 49 | + |
| 50 | + # Check that item is not a python file |
| 51 | + if [[ $item != *.py ]]; then |
| 52 | + |
| 53 | + output=$(./$SCRIPT "$item_name" 2>&1) |
| 54 | + |
| 55 | + # Check if the script ran successfully |
| 56 | + if [[ $? -ne 0 ]]; then |
| 57 | + errored_specs+=("$item_name") |
| 58 | + else |
| 59 | + # if script had output, then changes were made |
| 60 | + if [[ -n "$output" ]]; then |
| 61 | + changed_specs+=("$item_name") |
| 62 | + fi |
| 63 | + fi |
| 64 | + fi |
| 65 | +done |
| 66 | + |
| 67 | +pr_body="Spec sync results:\n\n" |
| 68 | +# Output the list of changed specs |
| 69 | +if [[ ${#changed_specs[@]} -gt 0 ]]; then |
| 70 | + pr_body+="The following specs were changed:\n" |
| 71 | + for spec in "${changed_specs[@]}"; do |
| 72 | + pr_body+=" - $spec\n" |
| 73 | + done |
| 74 | +else |
| 75 | + pr_body+="No changes detected in any specs.\n" |
| 76 | +fi |
| 77 | + |
| 78 | +# Output the list of errored specs |
| 79 | +if [[ ${#errored_specs[@]} -gt 0 ]]; then |
| 80 | + pr_body+="\nThe following spec syncs encountered errors:\n" |
| 81 | + for spec in "${errored_specs[@]}"; do |
| 82 | + pr_body+=" - $spec\n" |
| 83 | + done |
| 84 | +else |
| 85 | + pr_body+="\nNo errors were encountered in any specs syncs.\n" |
| 86 | +fi |
| 87 | + |
| 88 | +# Output the PR body (optional step for verification) |
| 89 | +echo -e "$pr_body" |
| 90 | + |
| 91 | +git add $SPEC_DEST |
| 92 | +git commit -m $BRANCH_NAME |
| 93 | +git push -u origin $BRANCH_NAME |
| 94 | +#gh pr create --title "[Spec Resync] $(date '+%m-%d-%Y')" --body "Resyncing specs for review" --base main --head $BRANCH_NAME --draft |
0 commit comments