runner-images/bin/joj3-forge-convert

44 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/bash
set -ex
if [ -z "$1" ]; then
echo "error: course name is required" >&2
exit 1
fi
COURSE="$1"
CONFIG_REPO_PATH="/home/tt/.cache/$COURSE-config"
GRADING_REPO_PATH="/home/tt/.cache/$COURSE-joj"
GIT_USER="bot-$COURSE"
GIT_EMAIL="bot-$COURSE@focs.ji.sjtu.edu.cn"
if ! [ -d "$CONFIG_REPO_PATH" ]; then
git clone "ssh://git@focs.ji.sjtu.edu.cn:2222/$COURSE/$COURSE-joj.git" "$CONFIG_REPO_PATH"
fi
# TODO: move this into if statement
git -C "$CONFIG_REPO_PATH" config user.name "$GIT_USER"
git -C "$CONFIG_REPO_PATH" config user.email "$GIT_EMAIL"
if ! [ -d "$GRADING_REPO_PATH" ]; then
git clone "ssh://git@focs.ji.sjtu.edu.cn:2222/$COURSE/$COURSE-joj.git" "$GRADING_REPO_PATH"
git -C "$GRADING_REPO_PATH" switch --orphan grading
echo "# $COURSE JOJ grading" >"$GRADING_REPO_PATH/Readme.md"
echo "This branch is automatically updated by JOJ, **never edit any file in this branch!**" >>"$GRADING_REPO_PATH/Readme.md"
git -C "$GRADING_REPO_PATH" add Readme.md
git -C "$GRADING_REPO_PATH" commit -m"docs: readme"
git -C "$GRADING_REPO_PATH" push -u origin grading
fi
# TODO: move this into if statement
git -C "$GRADING_REPO_PATH" config user.name "$GIT_USER"
git -C "$GRADING_REPO_PATH" config user.email "$GIT_EMAIL"
git -C "$CONFIG_REPO_PATH" pull --rebase
rsync -r --delete "$CONFIG_REPO_PATH/home/tt/.config/" /home/tt/.config
joj3-forge convert /home/tt/.config/joj
rsync -r --delete /home/tt/.config/joj/ "$CONFIG_REPO_PATH/home/tt/.config/joj"
git -C "$CONFIG_REPO_PATH" add home/tt/.config/joj
if ! git -C "$CONFIG_REPO_PATH" diff --staged --quiet; then
git -C "$CONFIG_REPO_PATH" commit -m "chore: joj3-forge convert [skip ci]"
git -C "$CONFIG_REPO_PATH" push
fi