From d5a96515ec9d512528af2076fccc80badc1621c4 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 14 Sep 2024 16:43:21 -0400 Subject: [PATCH 01/13] chore: rename parser secret -> dummy --- internal/parsers/all.go | 1 + internal/parsers/{secret => dummy}/meta.go | 6 +++--- internal/parsers/{secret => dummy}/parser.go | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) rename internal/parsers/{secret => dummy}/meta.go (52%) rename internal/parsers/{secret => dummy}/parser.go (61%) diff --git a/internal/parsers/all.go b/internal/parsers/all.go index 8e4e29a..95cbdc6 100644 --- a/internal/parsers/all.go +++ b/internal/parsers/all.go @@ -5,6 +5,7 @@ import ( _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/cppcheck" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/cpplint" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/diff" + _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/dummy" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/healthcheck" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/keyword" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/resultstatus" diff --git a/internal/parsers/secret/meta.go b/internal/parsers/dummy/meta.go similarity index 52% rename from internal/parsers/secret/meta.go rename to internal/parsers/dummy/meta.go index 457a77a..fd9ba75 100644 --- a/internal/parsers/secret/meta.go +++ b/internal/parsers/dummy/meta.go @@ -1,9 +1,9 @@ -package secret +package dummy import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" -var name = "secret" +var name = "dummy" func init() { - stage.RegisterParser(name, &Secret{}) + stage.RegisterParser(name, &Dummy{}) } diff --git a/internal/parsers/secret/parser.go b/internal/parsers/dummy/parser.go similarity index 61% rename from internal/parsers/secret/parser.go rename to internal/parsers/dummy/parser.go index a7902d7..da53cb2 100644 --- a/internal/parsers/secret/parser.go +++ b/internal/parsers/dummy/parser.go @@ -1,16 +1,16 @@ -package secret +package dummy import ( "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" ) type Conf struct { - Secret string + Comment string } -type Secret struct{} +type Dummy struct{} -func (*Secret) Run(results []stage.ExecutorResult, confAny any) ( +func (*Dummy) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { conf, err := stage.DecodeConf[Conf](confAny) @@ -19,7 +19,7 @@ func (*Secret) Run(results []stage.ExecutorResult, confAny any) ( } var res []stage.ParserResult for range results { - res = append(res, stage.ParserResult{Score: 0, Comment: conf.Secret}) + res = append(res, stage.ParserResult{Score: 0, Comment: conf.Comment}) } return res, false, nil } From d03927457ace8fd8dc21a3566252affdf2c62278 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 15 Sep 2024 08:26:33 -0400 Subject: [PATCH 02/13] feat: score & comment conf in result-status and dummy parser --- examples/diff/basic | 2 +- examples/diff/complex | 2 +- examples/healthcheck/asciimsg | 2 +- internal/parsers/dummy/parser.go | 3 ++- internal/parsers/resultstatus/parser.go | 12 +++++++----- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/diff/basic b/examples/diff/basic index af99032..4d0d2bf 160000 --- a/examples/diff/basic +++ b/examples/diff/basic @@ -1 +1 @@ -Subproject commit af990327ab095c22a383448ad70d915f8d10490b +Subproject commit 4d0d2bfdf8d2998f77b105d9d376ad52f3279fff diff --git a/examples/diff/complex b/examples/diff/complex index ac7a2fc..ce71d96 160000 --- a/examples/diff/complex +++ b/examples/diff/complex @@ -1 +1 @@ -Subproject commit ac7a2fc912fb51af156cd4babb7e72148ebe1c14 +Subproject commit ce71d96228ce42703278ff271356867994f6cb20 diff --git a/examples/healthcheck/asciimsg b/examples/healthcheck/asciimsg index 36bb5fb..d303867 160000 --- a/examples/healthcheck/asciimsg +++ b/examples/healthcheck/asciimsg @@ -1 +1 @@ -Subproject commit 36bb5fb15f100078bd3af1027017825932f8c24b +Subproject commit d303867e62383755b963fb7a519631106e82924e diff --git a/internal/parsers/dummy/parser.go b/internal/parsers/dummy/parser.go index da53cb2..02c3a08 100644 --- a/internal/parsers/dummy/parser.go +++ b/internal/parsers/dummy/parser.go @@ -5,6 +5,7 @@ import ( ) type Conf struct { + Score int Comment string } @@ -19,7 +20,7 @@ func (*Dummy) Run(results []stage.ExecutorResult, confAny any) ( } var res []stage.ParserResult for range results { - res = append(res, stage.ParserResult{Score: 0, Comment: conf.Comment}) + res = append(res, stage.ParserResult{Score: conf.Score, Comment: conf.Comment}) } return res, false, nil } diff --git a/internal/parsers/resultstatus/parser.go b/internal/parsers/resultstatus/parser.go index 3b1aad3..cb1774f 100644 --- a/internal/parsers/resultstatus/parser.go +++ b/internal/parsers/resultstatus/parser.go @@ -7,22 +7,24 @@ import ( "github.com/criyle/go-judge/envexec" ) -type Conf struct{} +type Conf struct { + Score int + Comment string +} type ResultStatus struct{} func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { - // TODO: more conf options - _, err := stage.DecodeConf[Conf](confAny) + conf, err := stage.DecodeConf[Conf](confAny) if err != nil { return nil, true, err } forceQuit := false var res []stage.ParserResult for _, result := range results { - comment := "" + comment := conf.Comment if result.Status != stage.Status(envexec.StatusAccepted) { forceQuit = true comment = fmt.Sprintf( @@ -30,7 +32,7 @@ func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) ( ) } res = append(res, stage.ParserResult{ - Score: 0, + Score: conf.Score, Comment: comment, }) } From 1253404c49a57bc9c62c3cb06901f6e2ff27f1c6 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 17:22:39 -0400 Subject: [PATCH 03/13] feat: use conf.toml -> conf.json --- cmd/joj3/conf.go | 2 +- examples/clangtidy/sillycode | 2 +- examples/compile/error | 2 +- examples/compile/success | 2 +- examples/cppcheck/sillycode | 2 +- examples/cpplint/sillycode | 2 +- examples/diff/basic | 2 +- examples/diff/complex | 2 +- examples/healthcheck/asciifile | 2 +- examples/healthcheck/asciimsg | 2 +- examples/healthcheck/forbiddenfile | 2 +- examples/healthcheck/meta | 2 +- examples/healthcheck/release | 2 +- examples/healthcheck/reposize | 2 +- examples/healthcheck/repoverify | 2 +- examples/keyword/clangtidy/sillycode | 2 +- examples/keyword/cpplint/sillycode | 2 +- examples/sample/error | 2 +- examples/sample/success | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 9ada30b..436e807 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -85,6 +85,6 @@ func commitMsgToConf() (conf Conf, err error) { msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) // TODO: parse msg to conf name - conf, err = parseConfFile("conf.toml") + conf, err = parseConfFile("conf.json") return } diff --git a/examples/clangtidy/sillycode b/examples/clangtidy/sillycode index 6084f4d..235d198 160000 --- a/examples/clangtidy/sillycode +++ b/examples/clangtidy/sillycode @@ -1 +1 @@ -Subproject commit 6084f4dc39929257f35eb2467b5aa105ceb03e81 +Subproject commit 235d1980bb55c8ec231ab03933cf8e8335344b81 diff --git a/examples/compile/error b/examples/compile/error index 4e5fab9..fc02680 160000 --- a/examples/compile/error +++ b/examples/compile/error @@ -1 +1 @@ -Subproject commit 4e5fab93e5a0ce67c8f40fef1e8f4cab7018fc5d +Subproject commit fc02680432a9003d623970187acce73276ce03b5 diff --git a/examples/compile/success b/examples/compile/success index 1512cb5..3a0760f 160000 --- a/examples/compile/success +++ b/examples/compile/success @@ -1 +1 @@ -Subproject commit 1512cb5f20473a598d7504a08dacff3d6406b983 +Subproject commit 3a0760f2442723eb77eafacbf89b0d25d62eb607 diff --git a/examples/cppcheck/sillycode b/examples/cppcheck/sillycode index 40fe2db..578be03 160000 --- a/examples/cppcheck/sillycode +++ b/examples/cppcheck/sillycode @@ -1 +1 @@ -Subproject commit 40fe2dbef18ac5188f72fe788426e3d9c8aa88ae +Subproject commit 578be035a0aedc0d9b5ffe5f40d4162e6483b6d0 diff --git a/examples/cpplint/sillycode b/examples/cpplint/sillycode index 1ec92f3..80ec230 160000 --- a/examples/cpplint/sillycode +++ b/examples/cpplint/sillycode @@ -1 +1 @@ -Subproject commit 1ec92f39ce2fac82356e79ae08c457784769d49c +Subproject commit 80ec230f63267a10777ae58ebb632709fc562e85 diff --git a/examples/diff/basic b/examples/diff/basic index 4d0d2bf..13a3d05 160000 --- a/examples/diff/basic +++ b/examples/diff/basic @@ -1 +1 @@ -Subproject commit 4d0d2bfdf8d2998f77b105d9d376ad52f3279fff +Subproject commit 13a3d05163213ce44c1ec638d4a409ed9db90530 diff --git a/examples/diff/complex b/examples/diff/complex index ce71d96..7f6f6e8 160000 --- a/examples/diff/complex +++ b/examples/diff/complex @@ -1 +1 @@ -Subproject commit ce71d96228ce42703278ff271356867994f6cb20 +Subproject commit 7f6f6e881d39e870e51afb3fd36fdbef20b9cb35 diff --git a/examples/healthcheck/asciifile b/examples/healthcheck/asciifile index a236c7e..1492b43 160000 --- a/examples/healthcheck/asciifile +++ b/examples/healthcheck/asciifile @@ -1 +1 @@ -Subproject commit a236c7ea934de5e59525fa27e4211f4a48dbbf93 +Subproject commit 1492b43605a17850071d4e6674151719ae55e761 diff --git a/examples/healthcheck/asciimsg b/examples/healthcheck/asciimsg index d303867..415ab7e 160000 --- a/examples/healthcheck/asciimsg +++ b/examples/healthcheck/asciimsg @@ -1 +1 @@ -Subproject commit d303867e62383755b963fb7a519631106e82924e +Subproject commit 415ab7e9d8e74a5290eec18bec54b3a6d727d3d7 diff --git a/examples/healthcheck/forbiddenfile b/examples/healthcheck/forbiddenfile index 62c43fe..02de953 160000 --- a/examples/healthcheck/forbiddenfile +++ b/examples/healthcheck/forbiddenfile @@ -1 +1 @@ -Subproject commit 62c43fe51666417c7cbb227d6daaeee7189b6944 +Subproject commit 02de953cbc841afb3f53d0d4096b423f91d78593 diff --git a/examples/healthcheck/meta b/examples/healthcheck/meta index 5c2cd9e..3161962 160000 --- a/examples/healthcheck/meta +++ b/examples/healthcheck/meta @@ -1 +1 @@ -Subproject commit 5c2cd9e6b31c6f223ac5d3ee5b07f11fbd378427 +Subproject commit 3161962adba8d6f2663963eb5c39578cb7874ab8 diff --git a/examples/healthcheck/release b/examples/healthcheck/release index fc9828b..01b362e 160000 --- a/examples/healthcheck/release +++ b/examples/healthcheck/release @@ -1 +1 @@ -Subproject commit fc9828bde135e53a7ef3e6367c708d9a000afc74 +Subproject commit 01b362e3bd5156211f8152237b101301560433b8 diff --git a/examples/healthcheck/reposize b/examples/healthcheck/reposize index a49a6aa..0648e32 160000 --- a/examples/healthcheck/reposize +++ b/examples/healthcheck/reposize @@ -1 +1 @@ -Subproject commit a49a6aa29d3dcb0509e8de540db0781aca596f26 +Subproject commit 0648e32a8932e561e102f336766ca18165866ab8 diff --git a/examples/healthcheck/repoverify b/examples/healthcheck/repoverify index 2f455dc..5e25b93 160000 --- a/examples/healthcheck/repoverify +++ b/examples/healthcheck/repoverify @@ -1 +1 @@ -Subproject commit 2f455dca9d28e39926e68b9b13eef39b0a9f67fc +Subproject commit 5e25b932fc3950f382c8533e018520b04542af4a diff --git a/examples/keyword/clangtidy/sillycode b/examples/keyword/clangtidy/sillycode index 9938ef0..1f53f4d 160000 --- a/examples/keyword/clangtidy/sillycode +++ b/examples/keyword/clangtidy/sillycode @@ -1 +1 @@ -Subproject commit 9938ef006e25c8caea24493172e60a58380c8df4 +Subproject commit 1f53f4df209662a30f7005a925fff0f0e3d94b13 diff --git a/examples/keyword/cpplint/sillycode b/examples/keyword/cpplint/sillycode index 96d0234..244a63f 160000 --- a/examples/keyword/cpplint/sillycode +++ b/examples/keyword/cpplint/sillycode @@ -1 +1 @@ -Subproject commit 96d02348a20a5a244cd4f82e94a04dccfe3f009c +Subproject commit 244a63f54397196f9f9a08114f4eef279093f2a6 diff --git a/examples/sample/error b/examples/sample/error index aa5bf33..980baf1 160000 --- a/examples/sample/error +++ b/examples/sample/error @@ -1 +1 @@ -Subproject commit aa5bf333e30c9c0175e021c001d85f90092d7d1a +Subproject commit 980baf11df313e659fb4b1dea1a126add15ac547 diff --git a/examples/sample/success b/examples/sample/success index ed17357..1d886f8 160000 --- a/examples/sample/success +++ b/examples/sample/success @@ -1 +1 @@ -Subproject commit ed17357671e1c6f8aa7f534a482d9b2fac76d959 +Subproject commit 1d886f8754d0a22471405580d231b2691b929bfd From d597c73dd2576d06b72a0bfbe25b11527d28e89f Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 17:45:42 -0400 Subject: [PATCH 04/13] feat: use tag & json loader only --- cmd/joj3/conf.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 436e807..49bf175 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -61,11 +61,21 @@ type OptionalCmd struct { } func parseConfFile(path string) (conf Conf, err error) { - m := multiconfig.NewWithPath(path) - if err = m.Load(&conf); err != nil { + d := &multiconfig.DefaultLoader{} + d.Loader = multiconfig.MultiLoader( + &multiconfig.TagLoader{}, + &multiconfig.JSONLoader{Path: path}, + ) + d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{}) + if err = d.Load(&conf); err != nil { slog.Error("parse stages conf", "error", err) return } + if err = d.Validate(&conf); err != nil { + slog.Error("validate stages conf", "error", err) + return + } + slog.Error("parse stages conf", "conf", conf) return } From 2291264df0772c02c5b3003dfa6581c8ba52201e Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 19:13:48 -0400 Subject: [PATCH 05/13] fix: remove typo log --- cmd/joj3/conf.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 49bf175..769b324 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -75,7 +75,6 @@ func parseConfFile(path string) (conf Conf, err error) { slog.Error("validate stages conf", "error", err) return } - slog.Error("parse stages conf", "conf", conf) return } From 61dada5c4004b2a83ba1bf4fb77d6bd423d32755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B3=8A=E6=98=8E518370910136?= Date: Fri, 20 Sep 2024 08:03:01 +0800 Subject: [PATCH 06/13] ci: use gitea actions instead of drone (#40) Reviewed-on: https://focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/pulls/40 --- .drone.yml | 31 --------------------------- .gitea/workflows/test.yaml | 44 ++++++++++++++++++++++++++++++++++++++ Makefile | 10 ++++++++- internal/stage/model.go | 9 ++++---- 4 files changed, 57 insertions(+), 37 deletions(-) delete mode 100644 .drone.yml create mode 100644 .gitea/workflows/test.yaml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 9f009f4..0000000 --- a/.drone.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -kind: pipeline -type: ssh -name: CI -server: - host: 111.186.59.59 - user: drone - ssh_key: - from_secret: joj3-test - -steps: - - name: prepare - commands: - - go env -w GOPROXY=https://goproxy.cn,direct - - whoami - - pwd - - env - - go version - - go env - - git status -v - - git log -1 - - name: build - commands: - - make - - name: test - commands: - - make prepare-test - - make test - - name: store - commands: - - cp build/joj3 /home/drone/.local/bin/joj3 diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml new file mode 100644 index 0000000..a7a5081 --- /dev/null +++ b/.gitea/workflows/test.yaml @@ -0,0 +1,44 @@ +--- +name: checks +on: + - push + - pull_request + +jobs: + build: + container: + image: focs.ji.sjtu.edu.cn:5000/gitea/runner-images:ubuntu-latest + volumes: + - /home/actions/.ssh:/root/.ssh + steps: + - name: Check out repository code + uses: https://gitea.com/BoYanZh/checkout@focs + - name: Setup Go 1.23.1 + run: | + wget -q https://studygolang.com/dl/golang/go1.23.1.linux-amd64.tar.gz + rm -rf /usr/local/go + tar -C /usr/local -xzf go1.23.1.linux-amd64.tar.gz + rm -rf go1.23.1.linux-amd64.tar.gz + echo "PATH=$PATH:/usr/local/go/bin:/root/go/bin" >> $GITHUB_ENV + - name: Display Go version + run: go version + - name: Prepare + run: | + go env -w GO111MODULE=on + go env -w GOPROXY=https://goproxy.io,direct + chown -R root:root /root/.ssh + - name: Setup golangci-lint + run: | + wget -q https://ghp.ci/https://github.com/golangci/golangci-lint/releases/download/v1.61.0/golangci-lint-1.61.0-linux-amd64.tar.gz + tar -C /tmp -xzf golangci-lint-1.61.0-linux-amd64.tar.gz + rm -rf golangci-lint-1.61.0-linux-amd64.tar.gz + mkdir -p /root/go/bin + mv /tmp/golangci-lint-1.61.0-linux-amd64/golangci-lint /root/go/bin + - name: Lint + run: make lint + - name: Build + run: make build + - name: Test + run: | + make prepare-test + make ci-test diff --git a/Makefile b/Makefile index cea7f45..f54d3c0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all build clean prepare-test test +.PHONY: all build clean lint prepare-test test ci-test BUILD_DIR = ./build TMP_DIR = ./tmp @@ -15,9 +15,17 @@ clean: rm -rf $(TMP_DIR)/* rm -rf *.out +lint: + golangci-lint run + prepare-test: git submodule update --init --remote test: ./scripts/prepare_test_repos.sh $(TMP_DIR) go test -coverprofile cover.out -v ./... + +ci-test: + ./scripts/prepare_test_repos.sh $(TMP_DIR) + ./scripts/run_foreach_test_repos.sh $(TMP_DIR) "sed -i '2i \ \ \"sandboxExecServer\": \"172.17.0.1:5051\",' conf.json" + go test -coverprofile cover.out -v ./... diff --git a/internal/stage/model.go b/internal/stage/model.go index cb33462..dba945a 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -3,7 +3,6 @@ package stage import ( "fmt" "strconv" - "time" "github.com/criyle/go-judge/envexec" ) @@ -126,8 +125,8 @@ func (r ExecutorResult) String() string { Status Status ExitStatus int Error string - Time time.Duration - RunTime time.Duration + Time uint64 + RunTime uint64 Memory envexec.Size Files map[string]string FileIDs map[string]string @@ -137,8 +136,8 @@ func (r ExecutorResult) String() string { Status: r.Status, ExitStatus: r.ExitStatus, Error: r.Error, - Time: time.Duration(r.Time), - RunTime: time.Duration(r.RunTime), + Time: r.Time, + RunTime: r.RunTime, Memory: envexec.Size(r.Memory), Files: make(map[string]string), FileIDs: r.FileIDs, From 9e5c933fbd48d26f40e1b8a949d167420672e565 Mon Sep 17 00:00:00 2001 From: Mack Wang Date: Fri, 20 Sep 2024 15:08:26 +0800 Subject: [PATCH 07/13] fix: check only latest commit for non-ascii chars (#38) according to [this](https://focs.ji.sjtu.edu.cn/mm/focs-team/pl/nsfhoutszfds5c9wpfrmfxb51c) discussion in *joj-dev* Reviewed-on: https://focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/pulls/38 Co-authored-by: Mack Wang Co-committed-by: Mack Wang --- examples/healthcheck/asciimsg | 2 +- pkg/healthcheck/commit.go | 55 ++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/examples/healthcheck/asciimsg b/examples/healthcheck/asciimsg index 415ab7e..f2848d6 160000 --- a/examples/healthcheck/asciimsg +++ b/examples/healthcheck/asciimsg @@ -1 +1 @@ -Subproject commit 415ab7e9d8e74a5290eec18bec54b3a6d727d3d7 +Subproject commit f2848d61097578d2439d3995820ea02a96ccad67 diff --git a/pkg/healthcheck/commit.go b/pkg/healthcheck/commit.go index ada9e5a..a9abe76 100644 --- a/pkg/healthcheck/commit.go +++ b/pkg/healthcheck/commit.go @@ -7,7 +7,6 @@ import ( "unicode" "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/object" ) // nonAsciiMsg checks for non-ASCII characters in the commit message. @@ -28,38 +27,52 @@ func NonAsciiMsg(root string) error { slog.Error("getting reference", "err", err) return fmt.Errorf("error getting reference: %v", err) } - commits, err := repo.Log(&git.LogOptions{From: ref.Hash()}) + + commit, err := repo.CommitObject(ref.Hash()) if err != nil { - slog.Error("getting commits", "err", err) - return fmt.Errorf("error getting commits from reference %s: %v", ref.Hash(), err) + slog.Error("getting latest commit", "err", err) + return fmt.Errorf("error getting latest commit: %v", err) } - var msgs []string - err = commits.ForEach(func(c *object.Commit) error { - msgs = append(msgs, c.Message) + msg := commit.Message + if msg == "" { return nil - }) - if err != nil { - slog.Error("iterating commits", "err", err) - return fmt.Errorf("error iterating commits: %v", err) } - var nonAsciiMsgs []string - for _, msg := range msgs { - if msg == "" { + var isCommitLegal bool = true + // List of prefixes to ignore in the commit message + ignoredPrefixes := []string{ + "Co-authored-by:", + "Reviewed-by:", + "Co-committed-by:", + "Reviewed-on:", + } + + // Split message by lines and ignore specific lines with prefixes + lines := strings.Split(msg, "\n") + for _, line := range lines { + trimmedLine := strings.TrimSpace(line) + ignore := false + for _, prefix := range ignoredPrefixes { + if strings.HasPrefix(trimmedLine, prefix) { + ignore = true + break + } + } + if ignore { continue } - if strings.HasPrefix(msg, "Merge pull request") { - continue - } - for _, c := range msg { + // Check for non-ASCII characters in the rest of the lines + for _, c := range line { if c > unicode.MaxASCII { - nonAsciiMsgs = append(nonAsciiMsgs, msg) + isCommitLegal = false + break } } } - if len(nonAsciiMsgs) > 0 { - return fmt.Errorf("Non-ASCII characters in commit messages:\n%s", strings.Join(nonAsciiMsgs, "\n")) + + if !isCommitLegal { + return fmt.Errorf("Non-ASCII characters in commit messages:\n%s", msg) } return nil } From 5083b02a6f2fcfd5756e09be4b5ec494c9fa0c25 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 21 Sep 2024 20:51:42 -0400 Subject: [PATCH 08/13] docs: binary & executor & parser --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index 98a94e8..2b0e2f6 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,12 @@ Check the `Result` at . - `Score int`: score of the stage. - `Comment string`: comment on the stage. +## Binaries (under `/cmd` and `/pkg`) + +### Sample + +Just a sample on how to write an executable that can be called by the executor. + ### HealthCheck The repohealth check will return a json list to for check result. The structure follows the score-comment pattern. @@ -95,3 +101,53 @@ The repohealth check will return a json list to for check result. The structure HealthCheck currently includes, `reposize`, `forbidden file`, `Metafile existence`, `non-ascii character` in file and message, `release tag`, and `ci files invariance` check. The workflow is `joj3` pass cli args to healthcheck binary. See `./cmd/healthcheck/main.go` to view all flags. + +## Executors (under `/internal/executors`) + +### Dummy + +Do not execute any command. Just return empty `ExecutorResult` slice. + +### Sandbox + +Run the commands in `go-judge` and output the `ExecutorResult` slice. + +## Parsers (under `/internal/parsers`) + +### Clang Tidy + +Parser for `clang-tidy`, check `/examples/clangtidy` on how to call `clang-tidy` with proper parameters. + +### Cppcheck + +Parser for `cppcheck`, check `/examples/cppcheck` on how to call `cppcheck` with proper parameters. + +### Cpplint + +Parser for `cpplint`, check `/examples/cpplint` on how to call `cpplint` with proper parameters. + +### Diff + +Compare the specified output of `ExecutorResult` with the content of the answer file. If they are the same, then score will be given. Just like a normal online judge system. + +### Dummy + +Does not parse the output of `ExecutorResult`. It just output what is set inside the configuration file as score and comment. Currently it is used to output metadata for `joint-teapot`. + +In `joint-teapot`, it will take the content before `-` of the comment of the first stage with name `metadata` as the exercise name and record in the scoreboard. (e.g. If the comment is `p2-s2-0xdeadbeef`, then the exercise name is `p2`.) + +### Healthcheck + +Parser for the `healthcheck` binary mentioned before. + +### Keyword + +Match the given keyword from the specified output of `ExecutorResult`. For each match, a deduction of score is given. Can be useful if we do not have a specific parser for a code quality tool. Check `/examples/keyword`. + +### Result Status + +Only check if all the status of the executor is `StatusAccepted`. Can be used to check whether the command run in the executor exit normally. + +### Sample + +Parser for the `sample` binary mentioned before. Only used as a sample. From 9765ea1007800c75ca2733f15ad9b792143a21fb Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 21 Sep 2024 20:59:11 -0400 Subject: [PATCH 09/13] fix: typo --- internal/parsers/cppcheck/score.go | 2 +- pkg/healthcheck/meta.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/parsers/cppcheck/score.go b/internal/parsers/cppcheck/score.go index d6028fb..dbdf81e 100644 --- a/internal/parsers/cppcheck/score.go +++ b/internal/parsers/cppcheck/score.go @@ -29,7 +29,7 @@ func severityFromString(severityString string) (Severity, error) { case "information": return INFORMATION, nil default: - return UNKNOWN, fmt.Errorf("unkown severity type \"%s\" for cppcheck", severityString) + return UNKNOWN, fmt.Errorf("unknown severity type \"%s\" for cppcheck", severityString) } } diff --git a/pkg/healthcheck/meta.go b/pkg/healthcheck/meta.go index 2e78d50..a78da6b 100644 --- a/pkg/healthcheck/meta.go +++ b/pkg/healthcheck/meta.go @@ -25,7 +25,7 @@ func getMetas(rootDir string, fileList []string) ([]string, string, error) { matched := false umatchedRes := "" - // TODO: it seems that there is no good find subsitution now + // TODO: it seems that there is no good find substitution now // modify current code if exist a better solution for i, regex := range regexList { for _, file := range files { From 5cf3d5f9ce98f0bb9e44ecb6613839a95772054f Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 21 Sep 2024 20:59:55 -0400 Subject: [PATCH 10/13] feat: less output in scripts --- scripts/prepare_test_repos.sh | 4 ++-- scripts/run_foreach_test_repos.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/prepare_test_repos.sh b/scripts/prepare_test_repos.sh index c679ab4..270567e 100755 --- a/scripts/prepare_test_repos.sh +++ b/scripts/prepare_test_repos.sh @@ -18,14 +18,14 @@ for submodule in $submodules; do else cd $repo_dir git fetch --all - cd - + cd - > /dev/null fi fi repo_names[$repo_name]=1 cd $repo_dir git checkout -q $branch git reset -q --hard origin/$branch - cd - + cd - > /dev/null submodule_dir="$submodules_dir/$repo_name/$submodule" mkdir -p $submodule_dir cp -rT $repo_dir $submodule_dir diff --git a/scripts/run_foreach_test_repos.sh b/scripts/run_foreach_test_repos.sh index 6789f3e..9710f5b 100755 --- a/scripts/run_foreach_test_repos.sh +++ b/scripts/run_foreach_test_repos.sh @@ -17,5 +17,5 @@ for submodule in $submodules; do mv -f "joj3_result.json" "expected.json" fi fi - cd - + cd - > /dev/null done From b7a1ad08339ed42879b8af81a7545d4b1d77f4bb Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 21 Sep 2024 21:12:06 -0400 Subject: [PATCH 11/13] fix: typo --- pkg/healthcheck/commit.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/healthcheck/commit.go b/pkg/healthcheck/commit.go index a9abe76..375046e 100644 --- a/pkg/healthcheck/commit.go +++ b/pkg/healthcheck/commit.go @@ -14,12 +14,12 @@ import ( // Otherwise, it iterates over each character in the message and checks if it is a non-ASCII character. // If a non-ASCII character is found, it returns an error indicating not to use non-ASCII characters in commit messages. // Otherwise, it returns nil indicating that the commit message is valid. +// It skips the non-ASCII characters check for lines starting with specific keywords like "Co-authored-by", "Reviewed-by", and "Co-committed-by". func NonAsciiMsg(root string) error { - // cmd := exec.Command("git", "log", "--encoding=UTF-8", "--format=%B") repo, err := git.PlainOpen(root) if err != nil { - slog.Error("openning git repo", "err", err) - return fmt.Errorf("error openning git repo: %v", err) + slog.Error("opening git repo", "err", err) + return fmt.Errorf("error opening git repo: %v", err) } ref, err := repo.Head() From a66dbc29e4e075abe11a73ca4b3dba72c78cf8fd Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 22 Sep 2024 01:36:07 -0400 Subject: [PATCH 12/13] feat: use CopyInDir instead of CopyInCwd --- README.md | 2 +- examples/clangtidy/sillycode | 2 +- examples/compile/error | 2 +- examples/compile/success | 2 +- examples/cppcheck/sillycode | 2 +- examples/cpplint/sillycode | 2 +- examples/diff/basic | 2 +- examples/diff/complex | 2 +- examples/healthcheck/asciifile | 2 +- examples/healthcheck/asciimsg | 2 +- examples/healthcheck/forbiddenfile | 2 +- examples/healthcheck/meta | 2 +- examples/healthcheck/release | 2 +- examples/healthcheck/reposize | 2 +- examples/healthcheck/repoverify | 2 +- examples/keyword/clangtidy/sillycode | 2 +- examples/keyword/cpplint/sillycode | 2 +- examples/sample/error | 2 +- examples/sample/success | 2 +- internal/executors/sandbox/convert.go | 10 ++++++---- internal/stage/model.go | 2 +- 21 files changed, 26 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2b0e2f6..6200597 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Check `Cmd` at . Some difference: -- `CopyInCwd bool`: set to `true` to add everything in the current working directory to `CopyIn`. +- `CopyInDir string`: set to non-empty string to add everything in that directory to `CopyIn`. - `CopyInCached map[string]string`: key: file name in the sandbox, value: file name used in `CopyOutCached`. - `LocalFile`: now supports the relative path diff --git a/examples/clangtidy/sillycode b/examples/clangtidy/sillycode index 235d198..30b1798 160000 --- a/examples/clangtidy/sillycode +++ b/examples/clangtidy/sillycode @@ -1 +1 @@ -Subproject commit 235d1980bb55c8ec231ab03933cf8e8335344b81 +Subproject commit 30b179812335b427a431c303ed3453779f898796 diff --git a/examples/compile/error b/examples/compile/error index fc02680..b16b4a9 160000 --- a/examples/compile/error +++ b/examples/compile/error @@ -1 +1 @@ -Subproject commit fc02680432a9003d623970187acce73276ce03b5 +Subproject commit b16b4a9679bb97d8703a3c70d3b75dd06e9fd4df diff --git a/examples/compile/success b/examples/compile/success index 3a0760f..ca21e3e 160000 --- a/examples/compile/success +++ b/examples/compile/success @@ -1 +1 @@ -Subproject commit 3a0760f2442723eb77eafacbf89b0d25d62eb607 +Subproject commit ca21e3ef7980339e433c6531d8e2aae9678eff2d diff --git a/examples/cppcheck/sillycode b/examples/cppcheck/sillycode index 578be03..866e732 160000 --- a/examples/cppcheck/sillycode +++ b/examples/cppcheck/sillycode @@ -1 +1 @@ -Subproject commit 578be035a0aedc0d9b5ffe5f40d4162e6483b6d0 +Subproject commit 866e73258c2d8f87b0000754a16f9b9c7de0c0fa diff --git a/examples/cpplint/sillycode b/examples/cpplint/sillycode index 80ec230..af355d9 160000 --- a/examples/cpplint/sillycode +++ b/examples/cpplint/sillycode @@ -1 +1 @@ -Subproject commit 80ec230f63267a10777ae58ebb632709fc562e85 +Subproject commit af355d91abf1ed62f19e0703dad55d18eb1252f8 diff --git a/examples/diff/basic b/examples/diff/basic index 13a3d05..cc5d991 160000 --- a/examples/diff/basic +++ b/examples/diff/basic @@ -1 +1 @@ -Subproject commit 13a3d05163213ce44c1ec638d4a409ed9db90530 +Subproject commit cc5d991cb401b0c8cfd8e03a76fb9994158d2819 diff --git a/examples/diff/complex b/examples/diff/complex index 7f6f6e8..f29fbda 160000 --- a/examples/diff/complex +++ b/examples/diff/complex @@ -1 +1 @@ -Subproject commit 7f6f6e881d39e870e51afb3fd36fdbef20b9cb35 +Subproject commit f29fbdac51f851e782f0db13f8640c6ba0aec49d diff --git a/examples/healthcheck/asciifile b/examples/healthcheck/asciifile index 1492b43..146b2f8 160000 --- a/examples/healthcheck/asciifile +++ b/examples/healthcheck/asciifile @@ -1 +1 @@ -Subproject commit 1492b43605a17850071d4e6674151719ae55e761 +Subproject commit 146b2f829a91594c89f1d1379d312b91c5f97a55 diff --git a/examples/healthcheck/asciimsg b/examples/healthcheck/asciimsg index f2848d6..ffd9ab1 160000 --- a/examples/healthcheck/asciimsg +++ b/examples/healthcheck/asciimsg @@ -1 +1 @@ -Subproject commit f2848d61097578d2439d3995820ea02a96ccad67 +Subproject commit ffd9ab13c7e403d0afc7f1dfc86ec131f9992498 diff --git a/examples/healthcheck/forbiddenfile b/examples/healthcheck/forbiddenfile index 02de953..b93a025 160000 --- a/examples/healthcheck/forbiddenfile +++ b/examples/healthcheck/forbiddenfile @@ -1 +1 @@ -Subproject commit 02de953cbc841afb3f53d0d4096b423f91d78593 +Subproject commit b93a0254c2842e4d9c3a4b8f832cd6b17bf284f9 diff --git a/examples/healthcheck/meta b/examples/healthcheck/meta index 3161962..b469371 160000 --- a/examples/healthcheck/meta +++ b/examples/healthcheck/meta @@ -1 +1 @@ -Subproject commit 3161962adba8d6f2663963eb5c39578cb7874ab8 +Subproject commit b4693716ee97bd5d9814c512b036aabeb12c7fd6 diff --git a/examples/healthcheck/release b/examples/healthcheck/release index 01b362e..50ec9cc 160000 --- a/examples/healthcheck/release +++ b/examples/healthcheck/release @@ -1 +1 @@ -Subproject commit 01b362e3bd5156211f8152237b101301560433b8 +Subproject commit 50ec9ccbb6d7fe9b5352a018b6ac6445ac5c354f diff --git a/examples/healthcheck/reposize b/examples/healthcheck/reposize index 0648e32..9c010a0 160000 --- a/examples/healthcheck/reposize +++ b/examples/healthcheck/reposize @@ -1 +1 @@ -Subproject commit 0648e32a8932e561e102f336766ca18165866ab8 +Subproject commit 9c010a0f8d501223f94d677a4aed70f0162092e2 diff --git a/examples/healthcheck/repoverify b/examples/healthcheck/repoverify index 5e25b93..99d95c2 160000 --- a/examples/healthcheck/repoverify +++ b/examples/healthcheck/repoverify @@ -1 +1 @@ -Subproject commit 5e25b932fc3950f382c8533e018520b04542af4a +Subproject commit 99d95c2841517f36a2063c641ea2e1b9b6190c76 diff --git a/examples/keyword/clangtidy/sillycode b/examples/keyword/clangtidy/sillycode index 1f53f4d..1f962c7 160000 --- a/examples/keyword/clangtidy/sillycode +++ b/examples/keyword/clangtidy/sillycode @@ -1 +1 @@ -Subproject commit 1f53f4df209662a30f7005a925fff0f0e3d94b13 +Subproject commit 1f962c75faccc9e703a8cd46e0a939551306bd4c diff --git a/examples/keyword/cpplint/sillycode b/examples/keyword/cpplint/sillycode index 244a63f..507ae70 160000 --- a/examples/keyword/cpplint/sillycode +++ b/examples/keyword/cpplint/sillycode @@ -1 +1 @@ -Subproject commit 244a63f54397196f9f9a08114f4eef279093f2a6 +Subproject commit 507ae70e81c08a6becdc8219a2c62b5aa8c3db69 diff --git a/examples/sample/error b/examples/sample/error index 980baf1..31b3191 160000 --- a/examples/sample/error +++ b/examples/sample/error @@ -1 +1 @@ -Subproject commit 980baf11df313e659fb4b1dea1a126add15ac547 +Subproject commit 31b319157fb221636fcdf8d6a752a4a5e46d6a6d diff --git a/examples/sample/success b/examples/sample/success index 1d886f8..7a98095 160000 --- a/examples/sample/success +++ b/examples/sample/success @@ -1 +1 @@ -Subproject commit 1d886f8754d0a22471405580d231b2691b929bfd +Subproject commit 7a98095a322419939bffa8636207090493108a3c diff --git a/internal/executors/sandbox/convert.go b/internal/executors/sandbox/convert.go index 827dd15..c739f79 100644 --- a/internal/executors/sandbox/convert.go +++ b/internal/executors/sandbox/convert.go @@ -28,7 +28,7 @@ func convertPBCmd(cmd []stage.Cmd) []*pb.Request_CmdType { CpuSetLimit: c.CPUSetLimit, DataSegmentLimit: c.DataSegmentLimit, AddressSpaceLimit: c.AddressSpaceLimit, - CopyIn: convertPBCopyIn(c.CopyIn, c.CopyInCwd), + CopyIn: convertPBCopyIn(c.CopyIn, c.CopyInDir), CopyOut: convertPBCopyOut(c.CopyOut), CopyOutCached: convertPBCopyOut(c.CopyOutCached), CopyOutMax: c.CopyOutMax, @@ -39,9 +39,11 @@ func convertPBCmd(cmd []stage.Cmd) []*pb.Request_CmdType { return ret } -func convertPBCopyIn(copyIn map[string]stage.CmdFile, copyInCwd bool) map[string]*pb.Request_File { - if copyInCwd { - _ = filepath.Walk(".", +func convertPBCopyIn( + copyIn map[string]stage.CmdFile, copyInDir string, +) map[string]*pb.Request_File { + if copyInDir != "" { + _ = filepath.Walk(copyInDir, func(path string, info os.FileInfo, err error) error { if err != nil { return nil diff --git a/internal/stage/model.go b/internal/stage/model.go index dba945a..224b687 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -46,7 +46,7 @@ type Cmd struct { CopyIn map[string]CmdFile `json:"copyIn"` CopyInCached map[string]string `json:"copyInCached"` - CopyInCwd bool `json:"copyInCwd"` + CopyInDir string `json:"copyInDir"` CopyOut []string `json:"copyOut"` CopyOutCached []string `json:"copyOutCached"` From 8992d9df7ade14d22d04da2d664e2f183efc8007 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 22 Sep 2024 01:37:10 -0400 Subject: [PATCH 13/13] docs: update usage of `make prepare-test` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6200597..07ca674 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ # make sure you are in go-judge directory $ ./tmp/go-judge -http-addr 0.0.0.0:5050 -grpc-addr 0.0.0.0:5051 -monitor-addr 0.0.0.0:5052 -enable-grpc -enable-debug -enable-metrics ``` -6. Pull submodules. It might be slow, so only run it when necessary. +6. Pull submodules. It might be slow, so only run it when the test branches are out of date. ```bash $ # make sure you are in JOJ3 directory