diff --git a/.drone.yml b/.drone.yml index 9f009f4..e834e25 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,6 +26,13 @@ steps: commands: - make prepare-test - make test + - name: scoreboard + environment: + GITEA_ACCESS_TOKEN: + from_secret: gitea-token + GITEA_ORG_NAME: FOCS-dev + commands: + - bash scripts/submit_scoreboard_failedtable.sh - name: store commands: - cp build/joj3 /home/drone/.local/bin/joj3 diff --git a/.gitignore b/.gitignore index 4c5caca..3b63635 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,5 @@ $RECYCLE.BIN/ build/ !examples/**/*.out tmp/ +repos/ +score.json diff --git a/cmd/joj3/main_test.go b/cmd/joj3/main_test.go index 0f35e6b..1ea8029 100644 --- a/cmd/joj3/main_test.go +++ b/cmd/joj3/main_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/scoreboard" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" ) @@ -62,6 +63,8 @@ func readStageResults(t *testing.T, path string) []stage.StageResult { } func TestMain(t *testing.T) { + scoreboard := scoreboard.Scoreboard{} + scoreboard.Init() var tests []string root := "../../tmp/submodules/JOJ3-examples/examples/" err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { @@ -107,6 +110,7 @@ func TestMain(t *testing.T) { defer os.Remove(outputFile) main() stageResults := readStageResults(t, outputFile) + scoreboard.AddScore(strings.TrimPrefix(tt, "/examples/"), stageResults) regex := true expectedFile := "expected_regex.json" if _, err := os.Stat(expectedFile); os.IsNotExist(err) { @@ -117,4 +121,7 @@ func TestMain(t *testing.T) { compareStageResults(t, stageResults, expectedStageResults, regex) }) } + if !t.Failed() { + scoreboard.SaveFile("../../score.json") + } } diff --git a/internal/scoreboard/scoreboard.go b/internal/scoreboard/scoreboard.go new file mode 100644 index 0000000..63e5abd --- /dev/null +++ b/internal/scoreboard/scoreboard.go @@ -0,0 +1,40 @@ +package scoreboard + +import ( + "encoding/json" + "os" + + "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" +) + +type TestRecord struct { + TestName string `json:"testname"` + StageResults []stage.StageResult `json:"stageresults"` +} + +type ScoreboardData struct { + TestRecords []TestRecord `json:"testrecords"` +} + +type Scoreboard struct { + scoreboard ScoreboardData +} + +func (b *Scoreboard) Init() { + b.scoreboard.TestRecords = make([]TestRecord, 0) +} + +func (b *Scoreboard) AddScore(testname string, results []stage.StageResult) { + b.scoreboard.TestRecords = append(b.scoreboard.TestRecords, + TestRecord{TestName: testname, StageResults: results}) +} + +func (b *Scoreboard) SaveFile(filePath string) { + json_file, _ := os.Create(filePath) + defer json_file.Close() + + encoder := json.NewEncoder(json_file) + encoder.SetEscapeHTML(false) + encoder.SetIndent("", " ") + _ = encoder.Encode(b.scoreboard) +} diff --git a/scripts/submit_scoreboard_failedtable.sh b/scripts/submit_scoreboard_failedtable.sh new file mode 100644 index 0000000..1e6d892 --- /dev/null +++ b/scripts/submit_scoreboard_failedtable.sh @@ -0,0 +1,25 @@ +#!/bin/bash +export ORIG_HOME=$(grep ^${USER}: /etc/passwd |cut -d : -f 6) +PATH=$PATH:$ORIG_HOME/.local/bin + +# if echo "${DRONE_REPO_NAME}" | grep -q '-'; then +# SUBMITTER_NAME=$(echo "${DRONE_REPO_NAME}" | cut -d'-' -f1); +# else +# SUBMITTER_NAME=${DRONE_REPO_NAME}; +# fi +SUBMITTER_NAME=${DRONE_REPO_NAME} + +mkdir repos + +echo 'CANVAS_ACCESS_TOKEN=""' > .env +echo 'CANVAS_COURSE_ID=0' >> .env +echo 'GITEA_ACCESS_TOKEN=$GITEA_ACCESS_TOKEN' >> .env +echo 'GITEA_ORG_NAME=$GITEA_ORG_NAME' >> .env +echo 'MATTERMOST_TEAM=""' >> .env +echo 'MATTERMOST_ACCESS_TOKEN=""' >> .env +echo 'MATTERMOST_TEACHING_TEAM=[]' >> .env + +joint-teapot JOJ3-scoreboard "score.json" $SUBMITTER_NAME "" "JOJ3-examples" "JOJ3_dev.csv" +joint-teapot JOJ3-failed-table "score.json" "JOJ3-examples" $DRONE_REPO_NAME $DRONE_REMOTE_URL "JOJ3-failed.md" +rm score.json +rm .env