Last active
August 3, 2021 22:00
-
-
Save nol166/39fe7b03841be0e0d860b76dc60d84f9 to your computer and use it in GitHub Desktop.
Alignment script for the fullstack-online repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash | |
# This script is used align the module with the ground repository. | |
# TODO --dry-run: add do not actually create any files | |
# prompt the user for the module name and ground repository | |
module_name=$1 | |
ground_repository=$2 | |
ground_activities_directory=$ground_repository/01-Class-Content/$module_name/01-Activities | |
ground_lesson_plans_directory=$ground_repository/02-Lesson-Plans/Part-Time | |
online_activities_directory=$PWD/01-Class-Content/$module_name/01-Activities | |
online_lesson_plans_directory=$PWD/02-Lesson-Plans/$module_name | |
module_number=$(echo $module_name | cut -d "-" -f 1) | |
module_overview_planner=$online_lesson_plans_directory/README.md | |
# remove any 0s from the module number | |
module_number_sans_zero=$((module_number + 0)) | |
# run git fetch to get all the latest changes assuming we are inside the online repo | |
git fetch | |
# check what branch we are on and if its not develop, then check out develop | |
# otherwise we are on develop and we are good to go | |
git branch | grep '*' | cut -d ' ' -f2 >/dev/null | |
if [ $? -ne 0 ]; then | |
git checkout develop && git pull | |
echo "Switched to develop branch" | |
else | |
echo "Already on develop branch" | |
fi | |
# module name | |
if [ -z "$module_name" ]; then | |
echo "Please enter the module name:" | |
read module_name | |
fi | |
# ground repo path | |
if [ -z "$ground_repository" ]; then | |
echo "Please enter the path for the ground repository:" | |
read ground_repository | |
fi | |
# attempt to check out the feature branch for this module | |
git branch | grep "feature/m$module_number_sans_zero-alignment" >/dev/null | |
if [ $? -ne 0 ]; then | |
echo "The branch feature/m$module_number_sans_zero-alignment does not exist, would you like to create it?" | |
read create_branch | |
if [ "$create_branch" == "y" ]; then | |
echo "" | |
git checkout -b feature/m$module_number_sans_zero-alignment | |
echo "Created branch feature/m$module_number_sans_zero-alignment" | |
else | |
echo "Please create the branch feature/m$module_number_sans_zero-alignment" | |
exit 1 | |
fi | |
else | |
git checkout feature/m$module_number_sans_zero-alignment | |
echo "Checking out feature/m$module_number_sans_zero-alignment" | |
fi | |
# # push the branch to the remote | |
# echo "Do you want to push the branch feature/m$module_number_sans_zero-alignment to the remote?" | |
# read push_branch | |
# if [ "$push_branch" == "y" ]; then | |
# git push origin feature/m$module_number_sans_zero-alignment | |
# echo "Pushed branch feature/m$module_number_sans_zero-alignment to the remote" | |
# else | |
# echo "" | |
# echo "Please remember to push the branch later" | |
# echo "" | |
# fi | |
# prompt for a jira ticket | |
echo "Please enter the JIRA ticket number for this alignment:" | |
read jira_ticket_number | |
echo "" | |
# if a branch doesn't exist for the jira ticket number, create it. If it does exist, then check it out | |
git branch | grep "$jira_ticket_number-Module-$module_number_sans_zero-Alignment" >/dev/null | |
if [ $? -ne 0 ]; then | |
echo "The branch $jira_ticket_number-Module-$module_number_sans_zero-Alignment does not exist, would you like to create it?" | |
read create_branch | |
if [ "$create_branch" == "y" ]; then | |
echo "" | |
git checkout -b $jira_ticket_number-Module-$module_number_sans_zero-Alignment | |
echo "Created branch $jira_ticket_number-Module-$module_number_sans_zero-Alignment" | |
else | |
echo "Please create the branch $jira_ticket_number-Module-$module_number_sans_zero-Alignment" | |
exit 1 | |
fi | |
else | |
git checkout $jira_ticket_number-Module-$module_number_sans_zero-Alignment | |
echo "Checking out $jira_ticket_number-Module-$module_number_sans_zero-Alignment" | |
fi | |
# check if the module exists in online | |
if [ -d $PWD/01-Class-Content/$module_name ]; then | |
module_exists=true | |
echo "Verifying that $module_name exists in the fullstack-online directory" | |
else | |
module_exists=false | |
echo "$module_name does not exist in the fullstack-online directory" | |
exit | |
fi | |
# check if the module exists in ground | |
if [ -d $ground_repository/01-Class-Content/$module_name ]; then | |
module_exists_ground=true | |
echo "Verifying that $module_name exists in the fullstack-ground directory" | |
else | |
module_exists_ground=false | |
echo "The module $module_name does not exist in the fullstack-ground directory" | |
exit | |
fi | |
echo "Do you want to continue? (y/n)" | |
read continue | |
if [ "$continue" = "y" ]; then | |
echo "Continuing..." | |
else | |
echo "Exiting..." | |
exit | |
fi | |
# navigate to the module directory inside the ground repository (if it exists) | |
if [ -n "$module_exists_ground" ]; then | |
echo "" | |
echo "Moving into $module_name activities folder" | |
cd "$ground_repository/01-Class-Content/$module_name/01-Activities" | |
# if a folder exists with the string "Evr_Git" | |
if [ -d *"Evr_"* ]; then | |
echo "Moving files from Evr_Git to Git-Guide" | |
cp -r *"Evr_"* $online_activities_directory/Git-Guide/ | |
fi | |
fi | |
# grab the relevant lesson plan files | |
online_required_lp1=$online_lesson_plans_directory/$module_number.1-REQUIRED.md | |
ground_pt_lp3=$(find $ground_lesson_plans_directory -name "$module_number.3-LESSON-PLAN.md" -print0) | |
echo $online_required_lp1 | |
echo $ground_pt_lp3 | |
echo $module_overview_planner | |
# open the lps in vscode | |
if [ -f $online_required_lp1 ] && [ -f $ground_pt_lp3 ]; then | |
echo "Opening the files in code" | |
code $online_required_lp1 $ground_pt_lp3 $module_overview_planner | |
else | |
echo "One or both of the lesson plans do not exist" | |
exit | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment