-
Notifications
You must be signed in to change notification settings - Fork 282
/
teach-class
executable file
·169 lines (143 loc) · 4.53 KB
/
teach-class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env bash
#
# Teach Class
# Set the exit on non zero
set -e
get_task() {
echo ""
echo "========================================================"
echo "This script manages the repos and activities"
echo "for the GitHub for Developers training."
echo "========================================================"
echo ""
echo "NOTE: If you have NOT run 0: Confirm setup, please run this task first"
echo " as it is needed to set all base environment variables!"
echo ""
echo ""
echo "What would you like to do? (Just the number please)"
echo "99: Exit"
echo " 0: Confirm setup"
echo " 1: Create a new caption-this class repository"
echo " 2: Add collabs and create files (also makes the repo private)"
echo " 3: Grade the day 1 repo"
echo " 4: Create conflict repos for each student"
echo " 5: Grade the conflict repos"
echo " 6: Create the github-games repos for each student"
echo " 7: Delete student repos for a specific class"
echo " 8: Grade client"
# Read the task that was input
read -r TASK
# Clean any whitespace that may be entered
TASK_NO_WHITESPACE="$(echo -e "$TASK" | tr -d '[:space:]')"
TASK=$TASK_NO_WHITESPACE
# Validate we got a number
REGEX='^[0-9]+$'
if ! [[ $TASK =~ $REGEX ]]; then
echo "ERROR: [$TASK] is not a number!"
exit 1
fi
# Run the task
do_task "$TASK"
}
do_task() {
# Read in the TASK
TASK=$1
# Set the collab repo
COLLAB_REPO=''
# See if we need to get the collab repo
# Skip tasks that don't need COLLAB_REPO
if [ "$TASK" -ne 0 ] && [ "$TASK" -ne 1 ] && [ "$TASK" -ne 99 ] && [ "$TASK" -ne 8 ]; then
echo "What is the name of the day 1 repo?"
# Read the collab repo
read -r COLLAB_REPO
# Clean any whitespace that may be entered
COLLAB_REPO_WHITESPACE="$(echo -e "$COLLAB_REPO" | tr -d '[:space:]')"
COLLAB_REPO=$COLLAB_REPO_WHITESPACE
elif [ "$TASK" -ne 0 ]; then
# shellcheck disable=SC1091
source "$HOME/.trainingmanualrc"
# Validate env variables
check_env
fi
# TASK 00
if [ "$TASK" -eq 99 ]; then
# echo 00: Done"
echo "We're all done..."
exit 0
# TASK 0
elif [ "$TASK" -eq 0 ]; then
# echo "0: Confirm Set-up"
echo "running script/class-setup"
./class-setup
echo "=============================="
echo "Set-up is complete"
echo "=============================="
exit
# TASK 1
elif [ "$TASK" -eq 1 ]; then
# echo "1: Create a new caption-this class repository"
echo "Running script/create-initial-repo"
./create-initial-repo
# TASK 2
elif [ "$TASK" -eq 2 ]; then
# echo "2: Add collabs and create files (also makes the repo private)"
echo "Running script/create-files"
./create-files "$COLLAB_REPO"
# TASK 3
elif [ "$TASK" -eq 3 ]; then
# echo "3: Grade the day 1 repo"
echo "Running script/check-caption-repo"
./check-caption-repo "$COLLAB_REPO"
# TASK 4
elif [ "$TASK" -eq 4 ]; then
# echo "4: Create conflict repos for each student"
echo "Running script/create-practice-repos"
./create-practice-repos "$COLLAB_REPO" "conflict-practice" "conflict-practice"
# TASK 5
elif [ "$TASK" -eq 5 ]; then
# echo "5: Grade the conflict repos"
echo "Running script/check-conflict-repos"
./check-conflict-repos "$COLLAB_REPO"
# TASK 6
elif [ "$TASK" -eq 6 ]; then
# echo "6: Create the github-games repos for each student"
echo "Running script/create-practice-repos"
./create-practice-repos "$COLLAB_REPO" "github-games" "github-games"
# TASK 7
elif [ "$TASK" -eq 7 ]; then
# echo "7: Expire student repos"
echo "Running script/clean-up-class"
./clean-up-class "$COLLAB_REPO"
# TASK 8
elif [ "$TASK" -eq 8 ]; then
# echo "8: Grade client"
echo "Running script/grade-client"
./grade-client
fi
}
check_env() {
# Check length of TEACHER_PAT
if [ -z "$TEACHER_PAT" ]; then
echo "ERROR! TEACHER_PAT not loaded or not correct length!"
echo "Please validate the .trainingmanualrc file!"
exit 1
fi
# Check we have a TOKEN_OWNER
if [ -z "$TOKEN_OWNER" ]; then
echo "ERROR! TOKEN_OWNER not loaded or not correct length!"
echo "Please validate the .trainingmanualrc file!"
exit 1
fi
# Check we have a INSTANCE_URL
if [ -z "$INSTANCE_URL" ]; then
echo "ERROR! INSTANCE_URL not loaded or not correct length!"
echo "Please validate the .trainingmanualrc file!"
exit 1
fi
}
# cd into the script directory so relative paths can be used
cd "${BASH_SOURCE%/*}/" || exit
# Resolve dependencies
./bootstrap
# Get the task to run
get_task