|
| 1 | +#!/bin/zsh |
| 2 | + |
| 3 | +set -e |
| 4 | +set -u |
| 5 | + |
| 6 | +# this script prepares a branch of LoopWorkspace based on current local branch. |
| 7 | +# It brings in the tip of all the submodule branches which should have just |
| 8 | +# been updated with the manual download, import, review and finalize scripts. |
| 9 | +# After all those PR are merged and the translation branches trimmed, |
| 10 | +# the next step is to prepare the PR to update LoopWorkspace dev branch |
| 11 | + |
| 12 | +source Scripts/define_common.sh |
| 13 | + |
| 14 | +section_divider |
| 15 | + |
| 16 | +echo "You must be in the LoopWorkspace folder ready to bring in " |
| 17 | +echo " all the latest versions of the submodules which were " |
| 18 | +echo " just translated" |
| 19 | +echo "" |
| 20 | +echo "This script will prepare a PR to LoopWorkspace '${target_loopworkspace_branch}' branch" |
| 21 | +echo "" |
| 22 | +echo "1. If the branch name is not already '${translation_branch}', then" |
| 23 | +echo " that branch will be created and used for this PR" |
| 24 | +echo "2. ./Scripts/update_submodule_refs.sh will be executed" |
| 25 | +echo "3. The commit message in the ${message_file} will be used" |
| 26 | +cat ${message_file} |
| 27 | +echo "4. Once the PR is prepared, additional commits can be added as needed" |
| 28 | + |
| 29 | +section_divider |
| 30 | + |
| 31 | +echo "Enter y to proceed, any other character exits" |
| 32 | +read query |
| 33 | + |
| 34 | +if [[ ${query} == "y" ]]; then |
| 35 | + |
| 36 | + current_branch=$(git branch --show-current 2>/dev/null) |
| 37 | + echo "current_branch = $current_branch" |
| 38 | + |
| 39 | + if [[ "${current_branch}" == "${translation_branch}" ]]; then |
| 40 | + echo "already on $translation_branch, ok to continue" |
| 41 | + |
| 42 | + elif [ -n "$(git branch --list "$translation_branch")" ]; then |
| 43 | + echo "Local branch '$translation_branch' exists." |
| 44 | + echo "You are on '$current_branch' and '$translation_branch' already exists" |
| 45 | + echo "quitting" |
| 46 | + exit 1 # exit with failure |
| 47 | + |
| 48 | + else |
| 49 | + echo "Local branch $translation_branch does not exist," |
| 50 | + echo "creating $translation_branch from the current branch, $current_branch." |
| 51 | + git switch -c "${translation_branch}" |
| 52 | + fi |
| 53 | + |
| 54 | + section_divider |
| 55 | + |
| 56 | + ./Scripts/update_submodule_refs.sh |
| 57 | + |
| 58 | + section_divider |
| 59 | + |
| 60 | + # only create a PR if there are changes |
| 61 | + if git commit -a -F "${message_file}"; then |
| 62 | + git push --set-upstream origin ${translation_branch} |
| 63 | + pr=$(gh pr create -B ${target_loopworkspace_branch} --fill 2>&1 | grep http) |
| 64 | + echo "PR = $pr" |
| 65 | + open $pr |
| 66 | + |
| 67 | + section_divider |
| 68 | + echo "After you review, ${pr}, get approvals and merge the PR" |
| 69 | + echo " be sure to trim the '${translation_branch}' branch," |
| 70 | + echo " and then run the export and upload scripts again from the updated '${target_loopworkspace_branch}' branch" |
| 71 | + section_divider |
| 72 | + |
| 73 | + else |
| 74 | + section_divider |
| 75 | + echo "No changes were found, no PR created" |
| 76 | + section_divider |
| 77 | + fi |
| 78 | + |
| 79 | +else |
| 80 | + section_divider |
| 81 | + echo "user opted to exit the script" |
| 82 | + section_divider |
| 83 | +fi |
0 commit comments