runner-images/bin/joj3-forge-convert
张泊明518370910136 6bef79f3d3
All checks were successful
push / build (push) Successful in 1m48s
fix: typo
2025-06-25 09:16:34 -04:00

69 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
set -x
export PATH="/usr/bin:/bin:/usr/local/bin"
unset IFS
main() {
local org_name
local repo_name
local course
org_name=$(basename "$(dirname "$(pwd)")")
repo_name=$(basename "$(pwd)")
course=${repo_name%-*}
if ! [[ "$course" =~ ^[a-zA-Z0-9_-]+$ ]]; then
exit 1
fi
local config_repo_path="/home/tt/.cache/$course-config"
local grading_repo_path="/home/tt/.cache/$course-joj"
local git_user="bot-$course"
local git_email="bot-$course@focs.ji.sjtu.edu.cn"
local git_server="ssh://git@focs.ji.sjtu.edu.cn:2222"
if ! [ -d "$config_repo_path" ]; then
git clone "$git_server/$course/$course-config.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 "$git_server/$course/$course-joj.git" "$grading_repo_path"
git -C "$grading_repo_path" switch --orphan grading
cat >"$grading_repo_path/Readme.md" <<EOF
# $course JOJ grading
This branch is automatically updated by JOJ, **never edit any file in this branch!**
EOF
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 -a --delete "$config_repo_path/home/tt/.config/" "/home/tt/.config"
joj3-forge convert "/home/tt/.config/joj"
rsync -a --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
if [ -n "${TEAPOT_GITEA_TOKEN:-}" ]; then
local teapot_config_dir="/home/tt/.config/teapot"
mkdir -p "$teapot_config_dir"
cat >"$teapot_config_dir/teapot.env" <<EOF
GITEA_ORG_NAME=$org_name
GITEA_ACCESS_TOKEN=$TEAPOT_GITEA_TOKEN
EOF
fi
}
main "$@"