Compare commits
No commits in common. "master" and "joj-repo" have entirely different histories.
|
@ -1,48 +0,0 @@
|
|||
name: push
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
build:
|
||||
runs-on: golang-ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@focs
|
||||
- name: Display Go version
|
||||
run: go version
|
||||
- name: Prepare
|
||||
run: |
|
||||
go env -w GO111MODULE=on
|
||||
go env -w GOPROXY=https://goproxy.cn,direct
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
||||
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519.pub
|
||||
ssh-keyscan -p 2222 focs.ji.sjtu.edu.cn >> ~/.ssh/known_hosts
|
||||
ssh -T git@focs.ji.sjtu.edu.cn -p 2222
|
||||
shell: bash
|
||||
- name: Determine build command
|
||||
id: build_command
|
||||
run: |
|
||||
if echo "${{ gitea.event.head_commit.message }}" | grep -q "force build"; then
|
||||
echo "build_command=make force-build" >> $GITEA_ENV
|
||||
else
|
||||
echo "build_command=make build" >> $GITEA_ENV
|
||||
fi
|
||||
- name: Build
|
||||
env:
|
||||
TZ: Asia/Shanghai
|
||||
run: ${{ env.build_command }}
|
||||
- name: Test
|
||||
run: make test
|
||||
- name: Check images
|
||||
run: docker images
|
||||
- name: Remove dangling images
|
||||
run: docker image prune -f
|
||||
- name: Docker Login
|
||||
run: |
|
||||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin focs.ji.sjtu.edu.cn:5000
|
||||
- name: Docker Push
|
||||
run: make push
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
/bin/joj3
|
||||
/bin/repo-health-checker
|
||||
.tags
|
||||
.tags.*
|
||||
|
|
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "JOJ3"]
|
||||
path = JOJ3
|
||||
url = ssh://git@focs.ji.sjtu.edu.cn:2222/JOJ/JOJ3.git
|
26
Dockerfile
26
Dockerfile
|
@ -1,26 +0,0 @@
|
|||
FROM focs.ji.sjtu.edu.cn:5000/gitea/runner-images:ubuntu-latest-slim
|
||||
|
||||
ENV TZ="Asia/Shanghai"
|
||||
|
||||
RUN sed -i s@/deb.debian.org/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list.d/debian.sources && \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends sudo python3-minimal python3-pip git git-lfs openssh-client rsync && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
userdel -r node && \
|
||||
useradd -u 1000 -ms /bin/bash tt && \
|
||||
useradd -u 1001 -ms /bin/bash student && \
|
||||
usermod -aG student tt && \
|
||||
echo "student ALL=(tt) NOPASSWD:SETENV:/usr/local/bin/joj3,/usr/local/bin/joj3-forge-convert\ntt ALL=(student) NOPASSWD:SETENV:ALL" > /etc/sudoers.d/joj
|
||||
|
||||
# install joint-teapot && joj3-forge
|
||||
RUN pip install --no-cache-dir --break-system-packages \
|
||||
--index-url https://pypi.tuna.tsinghua.edu.cn/simple \
|
||||
git+https://focs.ji.sjtu.edu.cn/git/JOJ/Joint-Teapot \
|
||||
git+https://focs.ji.sjtu.edu.cn/git/JOJ/JOJ3-config-generator
|
||||
|
||||
# install joj3 & repo-health-checker & joj3-forge-convert
|
||||
COPY bin/joj3 bin/repo-health-checker bin/joj3-forge-convert /usr/local/bin/
|
||||
|
||||
USER student
|
||||
WORKDIR /home/student
|
1
JOJ3
1
JOJ3
|
@ -1 +0,0 @@
|
|||
Subproject commit e1e49fb05a0d56c260c738546d77657d98751cba
|
26
Makefile
26
Makefile
|
@ -1,26 +0,0 @@
|
|||
.PHONY: all prepare force-build build test push
|
||||
|
||||
IMAGE_NAME := focs.ji.sjtu.edu.cn:5000/gitea/runner-images:focs-ubuntu-latest-slim
|
||||
|
||||
all: build
|
||||
|
||||
prepare:
|
||||
git submodule update --init --remote
|
||||
go env -w GOPROXY=https://goproxy.io,direct
|
||||
$(MAKE) -C JOJ3
|
||||
cp JOJ3/build/joj3 JOJ3/build/repo-health-checker bin/
|
||||
ls -lha bin
|
||||
# upx --best bin/joj3 bin/repo-health-checker
|
||||
# ls -lha bin
|
||||
|
||||
force-build: prepare
|
||||
docker build --no-cache -t $(IMAGE_NAME) .
|
||||
|
||||
build: prepare
|
||||
docker build -t $(IMAGE_NAME) .
|
||||
|
||||
test:
|
||||
docker run --rm $(IMAGE_NAME) sudo -u tt -E joj3 --help
|
||||
|
||||
push:
|
||||
docker push $(IMAGE_NAME)
|
|
@ -1,7 +0,0 @@
|
|||
# Runner Images
|
||||
|
||||
FOCS docker images used by [act_runner](https://gitea.com/gitea/act_runner) to run workflows.
|
||||
|
||||
Check <https://gitea.com/gitea/runner-images> for information about base images.
|
||||
|
||||
Actions for this branch will build and push `focs.ji.sjtu.edu.cn:5000/gitea/runner-images:focs-ubuntu-latest-slim` image. And everything is handled in actions.
|
|
@ -1,73 +0,0 @@
|
|||
#!/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
|
||||
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 "$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
|
||||
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 "$@"
|
103
joj-repo
Normal file
103
joj-repo
Normal file
|
@ -0,0 +1,103 @@
|
|||
#!/bin/bash
|
||||
|
||||
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
|
||||
#
|
||||
init() {
|
||||
|
||||
# backup current grading scoreboard
|
||||
[ -d $COURSE-joj ] && backup $COURSE-joj
|
||||
|
||||
git clone $GITEA/$ORG/$COURSE-joj.git
|
||||
|
||||
cd $COURSE-config
|
||||
|
||||
# check existence of grading branch
|
||||
git branch -a | grep -q grading && br=1
|
||||
|
||||
# clone grading branch or create one + push readme
|
||||
if [ "x$br" = "x1" ]; then
|
||||
git switch grading
|
||||
git pull
|
||||
else
|
||||
git switch --orphan grading
|
||||
|
||||
echo "# $COURSE JOJ grading" > Readme.md
|
||||
echo "This branch is automatically updated by JOJ, **never edit any file in this branch!**" >> Readme.md
|
||||
|
||||
git add Readme.md
|
||||
git commit -m"docs: readme"
|
||||
git push
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# update config repo + copy config files
|
||||
#
|
||||
update() {
|
||||
|
||||
[ -d "$COURSE-joj" ] || ( echo "ERROR: init first!" 1>&2 && exit )
|
||||
|
||||
|
||||
# genjson
|
||||
|
||||
rsync -a ./$HOME/ $LXCHOST:$HOME
|
||||
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# simple local backup
|
||||
#
|
||||
backup() {
|
||||
|
||||
[ -d $HOME/.local/share/joj ] || mkdir -p $HOME/.local/share/joj
|
||||
|
||||
BCK="$HOME/.local/share/joj/$1-$(date +%y%m%d-%H%M%S)"
|
||||
echo "WARNING: $1 already exits, backing it up to $BCK"
|
||||
mv "$1" "$BCK"
|
||||
|
||||
}
|
||||
|
||||
[ -z "$1" ] && echo "Usage: $0 update|init" && exit 1
|
||||
|
||||
[ -d $HOME/.cache ] || mkdir $HOME/.cache
|
||||
cd $HOME/.cache
|
||||
$1
|
Loading…
Reference in New Issue
Block a user