-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.sh
78 lines (60 loc) · 1.87 KB
/
submit.sh
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
#!/usr/bin/env bash
set -e
# Change USERNAME, PASSWORD
USERNAME="njusicpl24037"
PASSWORD="I]0~Vm7h"
echo "--------Begin to Submit--------"
if [[ $USERNAME == "21xxxxxxx" || $PASSWORD == "xxxxxxxxx" ]]; then
echo "Fail. You need to change USERNAME and PASSWORD"
exit -1
fi
COURSE=PTC2022
MODULE=$(git rev-parse --abbrev-ref HEAD | tr '[a-z]' '[A-Z]')
WORKSPACE=$(basename $(realpath .))
FILE=submit.zip
if [[ $(git status --porcelain) ]]; then
echo "Error: Git repository is dirty."
echo "Commit all your changes before submitting."
echo "Hint: run 'git status' to show changed files."
exit -1
fi
# Construct assignmentId
ANTLRTMP="labN"
BRANCH=$(git symbolic-ref --short -q HEAD)
NUMBER=$(echo $BRANCH | tr -cd "[0-9]")
ID=$(echo $ANTLRTMP | sed "s/N/${NUMBER}/g")
echo "In branch: $BRANCH "
echo "Submit to assignment: $ID"
# Compress the whole folder instead of git storage only.
cd ..
rm -f $FILE
zip -r "$FILE" $(ls -d "$WORKSPACE/.git" 2>/dev/null) > /dev/null
if [ $? -ne 0 ]; then
echo ""
echo "Fail to zip for submit.zip!"
else
echo ""
echo "generate submit.zip"
fi
# construct json for cul
TMPRAW='{"username":"XXXUSERXXX","password":"YYYPWDYYY"}'
DATARAW=$(echo $TMPRAW | sed "s/XXXUSERXXX/$USERNAME/g" | sed "s/YYYPWDYYY/$PASSWORD/g")
URL=http://back.compilers.cpl.icu
# extract token
RAW=$(curl "$URL/auth/login" \
-H 'Content-Type: application/json' \
--data-raw $DATARAW )
TOKEN=$(echo $RAW | sed 's/,/\n/g' | grep "token" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/\"//g')
RES=$(curl "$URL/submissions" \
-H "Authorization: Bearer $TOKEN" \
-F "assignmentId=$ID" \
-F "file=@$FILE" )
FLAG0=$?
TIME=$(echo $RES | sed 's/,/\n/g' | grep "createdAt" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g' | sed 's/\"//g')
if [[ $FLAG0 -ne 0 || -z $TIME ]]; then
echo ""
echo "T_T Commit Fail! T_T"
else
echo ""
echo "^v^ Commit Success! ^v^ "
fi