From 175685c074eb64c5715d148fd1349bb76d695251 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 15 Sep 2024 08:26:33 -0400 Subject: [PATCH 1/7] 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 92f375ed013827c77969459a48714008ba896bdd Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 17:22:39 -0400 Subject: [PATCH 2/7] 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 f4bc61654c078260b5a23f2180d7fd040a9a7cfa Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 17:45:42 -0400 Subject: [PATCH 3/7] 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 d8ec7d1d75511d2be4c42a151ccbaff34cf7267d Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 19:13:48 -0400 Subject: [PATCH 4/7] 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 c5d6433cb0bf59852935c866711c4db9b8479785 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 5/7] 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 7cbce3cb547dd781a5bb202d88ada244b8325f94 Mon Sep 17 00:00:00 2001 From: Mack Wang Date: Sun, 15 Sep 2024 16:37:32 +0800 Subject: [PATCH 6/7] =?UTF-8?q?test:=20=E3=81=93=E3=82=8C=E3=81=AF?= =?UTF-8?q?=E9=81=95=E6=B3=95=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=B8=80=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/healthcheck/commit.go | 63 +++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/pkg/healthcheck/commit.go b/pkg/healthcheck/commit.go index 8b1d579..375046e 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,23 +27,19 @@ 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 + var isCommitLegal bool = true // List of prefixes to ignore in the commit message ignoredPrefixes := []string{ "Co-authored-by:", @@ -53,35 +48,31 @@ func NonAsciiMsg(root string) error { "Reviewed-on:", } - for _, msg := range msgs { - if msg == "" { + // 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 } - // 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 - } - // Check for non-ASCII characters in the rest of the lines - for _, c := range line { - if c > unicode.MaxASCII { - nonAsciiMsgs = append(nonAsciiMsgs, msg) - break - } + // Check for non-ASCII characters in the rest of the lines + for _, c := range line { + if c > unicode.MaxASCII { + 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 a423f5b7dd042635739723187f7d9adef60e580c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=9F=B5=E6=99=A8520370910012?= Date: Fri, 20 Sep 2024 11:10:27 +0800 Subject: [PATCH 7/7] fix: bad commit msg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous commit msg was for testing purposes only. Sorry for the disturbance :( Signed-off-by: 王韵晨520370910012 --- pkg/healthcheck/commit.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/healthcheck/commit.go b/pkg/healthcheck/commit.go index 375046e..5d4d5f8 100644 --- a/pkg/healthcheck/commit.go +++ b/pkg/healthcheck/commit.go @@ -5,7 +5,6 @@ import ( "log/slog" "strings" "unicode" - "github.com/go-git/go-git/v5" )