runner-images/bin/joj3-forge-convert
张泊明518370910136 e943821d26
All checks were successful
push / build (push) Successful in 48s
chore: debug log file
2025-09-21 05:52:06 -07:00

91 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
set -x
export PATH="/usr/bin:/bin:/usr/local/bin"
unset IFS
unset PYTHONPATH
unset PYTHONHOME
unset HTTP_PROXY
unset HTTPS_PROXY
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
echo "FATAL: Invalid course name: $course" >&2
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-joj.git" "$config_repo_path"
git -C "$config_repo_path" config user.name "$git_user"
git -C "$config_repo_path" config user.email "$git_email"
fi
if ! [ -d "$grading_repo_path" ]; then
git clone "$git_server/$course/$course-joj.git" "$grading_repo_path"
git -C "$grading_repo_path" config user.name "$git_user"
git -C "$grading_repo_path" config user.email "$git_email"
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
git -C "$config_repo_path" reset --hard
git -C "$config_repo_path" pull --rebase
if [ -e "$config_repo_path/home/tt/.config/teapot/teapot.env" ]; then
echo "FATAL: Forbidden file found in '/home/tt/.config/teapot/teapot.env'. Check the latest README to set TEAPOT_GITEA_TOKEN in secrets instead." >&2
exit 1
fi
rsync -a "$config_repo_path/home/tt/.ssh/" "/home/tt/.ssh"
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
commit_hash=$(git -C "$config_repo_path" rev-parse HEAD)
git -C "$config_repo_path" commit -m "chore: $commit_hash trigger 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
whoami
pwd
ls -lha
ls -lha ..
touch joint-teapot.log
if ! (cd /tmp && joint-teapot joj3-check-gitea-token "$teapot_config_dir/teapot.env"); then
echo "FATAL: TEAPOT_GITEA_TOKEN invalid, cannot get current Gitea user" >&2
exit 1
fi
else
echo "FATAL: TEAPOT_GITEA_TOKEN not set" >&2
exit 1
fi
}
main "$@"