diff --git a/joj-repo b/joj-repo index 4997a8e..d259e94 100644 --- a/joj-repo +++ b/joj-repo @@ -1,8 +1,41 @@ #!/bin/bash -COURSE=$(hostname) -SEMESTER=${COURSE#*-} -COURSE=${COURSE%-*} +GITEA="ssh://git@focs.ji.sjtu.edu.cn:2222" +ORG=${GITHUB_ACTION_REPOSITORY%/*} +COURSE=${ORG/-*} + +LXCHOST="tt@172.17.0.1" + + +# +# parse commit message +# + +parse_commit() { + + message=$(git log -1 --pretty=format:%s ${GITHUB_WORKFLOW_SHA}) + + # add empty scope if none provided, then split "type(scope): message" + OLDIFS=$IFS; IFS=$'\n' + commit=( $(sed 's/\(^[^(]*\):/\1( ):/g; s/\([^(]*\)(\?\([^)]*\))\?: \(.*\)/\1\n\2\n\3/g' <<< ${message}) ) + IFS=$OLDIFS + +} + + +# +# gen +# + +generate_json() { + + parse_commit + for i in ${commit[1]}; do + echo joj-conf-generator $HOME/.config/joj/$i + done + +} + # # initial repo/config setup @@ -11,7 +44,7 @@ init() { [ -d $COURSE-config ] && backup $COURSE-config - git clone ssh://git@focs.ji.sjtu.edu.cn:2222/$COURSE-$SEMESTER/$COURSE-joj.git $COURSE-config + git clone $GITEA/$ORG/$COURSE-joj.git $COURSE-config cd $COURSE-config @@ -28,12 +61,12 @@ init() { # clone grading branch or create one + push readme if [ "x$br" = "x1" ]; then - git clone -b grading ssh://git@focs.ji.sjtu.edu.cn:2222/$COURSE-$SEMESTER/$COURSE-joj.git + git clone -b grading $GITEA/$COURSE-$SEMESTER/$COURSE-joj.git cd $COURSE-joj git switch grading git pull else - git clone ssh://git@focs.ji.sjtu.edu.cn:2222/$COURSE-$SEMESTER/$COURSE-joj.git + git clone $GITEA/$COURSE-$SEMESTER/$COURSE-joj.git cd $COURSE-joj git switch --orphan grading @@ -48,20 +81,22 @@ init() { } + # # update config repo + copy config files # update() { [ -d "$COURSE-joj" ] || ( echo "ERROR: init first!" 1>&2 && exit ) - cd $HOME/.cache/$COURSE-config - git pull - rsync -r ./$HOME/ $HOME +# genjson + + rsync -a ./$HOME/ $LXCHOST:$HOME } + # # simple local backup #