From 9065d4f8247ef8fdd4ebd9486f8f2a74411c10db Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 12 Sep 2024 16:08:40 +0800 Subject: [PATCH 01/21] fix: ignore pull request nonascii --- pkg/healthcheck/commit.go | 46 +++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/pkg/healthcheck/commit.go b/pkg/healthcheck/commit.go index ada9e5a..36f2be6 100644 --- a/pkg/healthcheck/commit.go +++ b/pkg/healthcheck/commit.go @@ -10,17 +10,13 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" ) -// nonAsciiMsg checks for non-ASCII characters in the commit message. -// If the message starts with "Merge pull request", it skips the non-ASCII characters check. -// 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. +// NonAsciiMsg checks for non-ASCII characters in the commit message. +// 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() @@ -45,16 +41,38 @@ func NonAsciiMsg(root string) error { } var nonAsciiMsgs []string + // List of prefixes to ignore in the commit message + ignoredPrefixes := []string{ + "Co-authored-by:", + "Reviewed-by:", + "Co-committed-by:", + "Reviewed-on:", + } + for _, msg := range msgs { if msg == "" { continue } - if strings.HasPrefix(msg, "Merge pull request") { - continue - } - for _, c := range msg { - if c > unicode.MaxASCII { - nonAsciiMsgs = append(nonAsciiMsgs, 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 + } + // Check for non-ASCII characters in the rest of the lines + for _, c := range line { + if c > unicode.MaxASCII { + nonAsciiMsgs = append(nonAsciiMsgs, msg) + break + } } } } -- 2.30.2 From a0cd1b66c2c8c1fd3a3f86d3b48d6a070ab89fcd Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 12 Sep 2024 16:10:44 +0800 Subject: [PATCH 02/21] chore: comment of code --- pkg/healthcheck/commit.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/healthcheck/commit.go b/pkg/healthcheck/commit.go index 36f2be6..8b1d579 100644 --- a/pkg/healthcheck/commit.go +++ b/pkg/healthcheck/commit.go @@ -10,7 +10,11 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" ) -// NonAsciiMsg checks for non-ASCII characters in the commit message. +// nonAsciiMsg checks for non-ASCII characters in the commit message. +// If the message starts with "Merge pull request", it skips the non-ASCII characters check. +// 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 { repo, err := git.PlainOpen(root) -- 2.30.2 From 92c35f92fc184e5b494ef53a24b7e71761c091d1 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 14 Sep 2024 16:43:21 -0400 Subject: [PATCH 03/21] 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 } -- 2.30.2 From 175685c074eb64c5715d148fd1349bb76d695251 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 15 Sep 2024 08:26:33 -0400 Subject: [PATCH 04/21] 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, }) } -- 2.30.2 From 72208487b0809e543c0765c2f10edc7660717b55 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 19 Sep 2024 10:03:17 +0800 Subject: [PATCH 05/21] feat: commitmsg parser --- cmd/joj3/conf.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 9ada30b..2bb892d 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -2,6 +2,7 @@ package main import ( "log/slog" + "strings" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" "github.com/go-git/go-git/v5" @@ -84,7 +85,23 @@ 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") + line := strings.Split(msg, "\n")[0] + + words := strings.TrimSpace(line) + head := string(words[0]) + + file := "conf.toml" + + if strings.HasSuffix(head, ":") || strings.HasSuffix(head, ".") { + head = head[:len(head)-1] + } + switch head { + case "feat", "fix", "refactor", "perf", "test", "build", "revert": + strings.Replace(file, "conf", "conf-cp", 1) + case "joj", "grading": + strings.Replace(file, "conf", "conf-oj", 1) + } + + conf, err = parseConfFile(file) return } -- 2.30.2 From d299849c788b2518c803903b0625138d65a5d958 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 19 Sep 2024 10:31:51 +0800 Subject: [PATCH 06/21] fix: bad hw pattern --- cmd/joj3/conf.go | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 2bb892d..5e332ec 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -1,7 +1,9 @@ package main import ( + "fmt" "log/slog" + "regexp" "strings" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" @@ -70,6 +72,17 @@ func parseConfFile(path string) (conf Conf, err error) { return } +func validateHw(hw string) error { + matched, err := regexp.MatchString(`^hw[0-9]+$`, hw) + if err != nil { + return fmt.Errorf("error compiling regex: %w", err) + } + if !matched { + return fmt.Errorf("error: hw does not match the required pattern") + } + return nil +} + func commitMsgToConf() (conf Conf, err error) { r, err := git.PlainOpen(".") if err != nil { @@ -87,19 +100,36 @@ func commitMsgToConf() (conf Conf, err error) { slog.Debug("commit msg to conf", "msg", msg) line := strings.Split(msg, "\n")[0] - words := strings.TrimSpace(line) - head := string(words[0]) + words := strings.Fields(line) - file := "conf.toml" + head := words[0] + var hw string if strings.HasSuffix(head, ":") || strings.HasSuffix(head, ".") { head = head[:len(head)-1] } + + file := "conf.toml" + switch head { case "feat", "fix", "refactor", "perf", "test", "build", "revert": - strings.Replace(file, "conf", "conf-cp", 1) + if len(words) < 2 { + return Conf{}, fmt.Errorf("error: hw not assigned") + } + hw = words[1] + if err = validateHw(hw); err != nil { + return + } + file = strings.Replace(file, "conf", "conf-"+hw+"-cq", 1) case "joj", "grading": - strings.Replace(file, "conf", "conf-oj", 1) + if len(words) < 2 { + return Conf{}, fmt.Errorf("error: hw not assigned") + } + hw = words[1] + if err = validateHw(hw); err != nil { + return + } + file = strings.Replace(file, "conf", "conf-"+hw+"-oj", 1) } conf, err = parseConfFile(file) -- 2.30.2 From e8506eeb51b35e21f3777cd62f227df8d0834409 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 19 Sep 2024 10:41:59 +0800 Subject: [PATCH 07/21] fix: empty commit --- cmd/joj3/conf.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 5e332ec..5a82acf 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -88,16 +88,26 @@ func commitMsgToConf() (conf Conf, err error) { if err != nil { return } + ref, err := r.Head() if err != nil { return } + commit, err := r.CommitObject(ref.Hash()) if err != nil { return } + + file := "conf.toml" + msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) + if msg == "" { + conf, err = parseConfFile(file) + return + } + line := strings.Split(msg, "\n")[0] words := strings.Fields(line) @@ -109,8 +119,6 @@ func commitMsgToConf() (conf Conf, err error) { head = head[:len(head)-1] } - file := "conf.toml" - switch head { case "feat", "fix", "refactor", "perf", "test", "build", "revert": if len(words) < 2 { -- 2.30.2 From a186c63d769b38cc88bcbac3c196c84b7374a732 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 19 Sep 2024 11:04:50 +0800 Subject: [PATCH 08/21] fix: use default conf if anything fail --- cmd/joj3/conf.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 5a82acf..3afa8ad 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -121,23 +121,27 @@ func commitMsgToConf() (conf Conf, err error) { switch head { case "feat", "fix", "refactor", "perf", "test", "build", "revert": - if len(words) < 2 { - return Conf{}, fmt.Errorf("error: hw not assigned") + // TODO: Decide strategy to give students error + // if len(words) < 2 { + // return Conf{}, fmt.Errorf("error: hw not assigned") + // } + if len(words) >= 2 { + hw = words[1] + if err = validateHw(hw); err == nil { + file = strings.Replace(file, "conf", "conf-"+hw+"-cq", 1) + } } - hw = words[1] - if err = validateHw(hw); err != nil { - return - } - file = strings.Replace(file, "conf", "conf-"+hw+"-cq", 1) case "joj", "grading": - if len(words) < 2 { - return Conf{}, fmt.Errorf("error: hw not assigned") + // TODO: Decide strategy to give students error + // if len(words) < 2 { + // return Conf{}, fmt.Errorf("error: hw not assigned") + // } + if len(words) >= 2 { + hw = words[1] + if err = validateHw(hw); err == nil { + file = strings.Replace(file, "conf", "conf-"+hw+"-oj", 1) + } } - hw = words[1] - if err = validateHw(hw); err != nil { - return - } - file = strings.Replace(file, "conf", "conf-"+hw+"-oj", 1) } conf, err = parseConfFile(file) -- 2.30.2 From 92f375ed013827c77969459a48714008ba896bdd Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 17:22:39 -0400 Subject: [PATCH 09/21] 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 -- 2.30.2 From f4bc61654c078260b5a23f2180d7fd040a9a7cfa Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 17:45:42 -0400 Subject: [PATCH 10/21] 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 } -- 2.30.2 From d8ec7d1d75511d2be4c42a151ccbaff34cf7267d Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Thu, 19 Sep 2024 19:13:48 -0400 Subject: [PATCH 11/21] 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 } -- 2.30.2 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 12/21] 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, -- 2.30.2 From 1eb096c1db314d6c625bf31ca5b9ca74f8fb2a78 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Fri, 20 Sep 2024 10:21:16 +0800 Subject: [PATCH 13/21] fix: bad hw pattern --- cmd/joj3/conf.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 3afa8ad..8f647cb 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -98,8 +98,14 @@ func commitMsgToConf() (conf Conf, err error) { if err != nil { return } + msg := commit.Message + slog.Debug("commit msg to conf", "msg", msg) + line := strings.Split(msg, "\n")[0] - file := "conf.toml" + words := strings.Fields(line) + + head := words[0] + var hw string msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) -- 2.30.2 From e2b280b70c1ee9b77c7733c995391ff08758b052 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 19 Sep 2024 10:41:59 +0800 Subject: [PATCH 14/21] fix: empty commit --- cmd/joj3/conf.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 8f647cb..b5d8e7e 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -98,8 +98,16 @@ func commitMsgToConf() (conf Conf, err error) { if err != nil { return } + + file := "conf.toml" + msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) + if msg == "" { + conf, err = parseConfFile(file) + return + } + line := strings.Split(msg, "\n")[0] words := strings.Fields(line) -- 2.30.2 From 2eae418bf36a76d0d0c2487a049b0cb5b92eaa12 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Fri, 20 Sep 2024 10:30:33 +0800 Subject: [PATCH 15/21] fix: toml2json --- cmd/joj3/conf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index d5b9d70..13ebb4d 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -108,7 +108,7 @@ func commitMsgToConf() (conf Conf, err error) { return } - file := "conf.toml" + file := "conf.json" msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) -- 2.30.2 From 424cfef91de881ae310134dd1883b8a7d20a449a Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Fri, 20 Sep 2024 10:49:18 +0800 Subject: [PATCH 16/21] fix: wrong code --- cmd/joj3/conf.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 13ebb4d..0556478 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -124,20 +124,6 @@ func commitMsgToConf() (conf Conf, err error) { head := words[0] var hw string - msg := commit.Message - slog.Debug("commit msg to conf", "msg", msg) - if msg == "" { - conf, err = parseConfFile(file) - return - } - - line := strings.Split(msg, "\n")[0] - - words := strings.Fields(line) - - head := words[0] - var hw string - if strings.HasSuffix(head, ":") || strings.HasSuffix(head, ".") { head = head[:len(head)-1] } -- 2.30.2 From 0409bee600a15a16c94eb8007c1ac498bd758511 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Fri, 20 Sep 2024 12:55:17 +0800 Subject: [PATCH 17/21] feat: multiple configs --- cmd/joj3/conf.go | 113 ++++++++++++++++++++++++++++++++++++----------- cmd/joj3/main.go | 3 +- 2 files changed, 90 insertions(+), 26 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 0556478..038a4ac 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -3,7 +3,9 @@ package main import ( "fmt" "log/slog" + "os" "regexp" + "strconv" "strings" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" @@ -11,6 +13,14 @@ import ( "github.com/koding/multiconfig" ) +type JobType int + +const ( + HC JobType = iota + CQ + OJ +) + type Conf struct { SandboxExecServer string `default:"localhost:5051"` SandboxToken string `default:""` @@ -81,7 +91,7 @@ func parseConfFile(path string) (conf Conf, err error) { return } -func validateHw(hw string) error { +func _validateHw(hw string) error { matched, err := regexp.MatchString(`^hw[0-9]+$`, hw) if err != nil { return fmt.Errorf("error compiling regex: %w", err) @@ -92,7 +102,36 @@ func validateHw(hw string) error { return nil } -func commitMsgToConf() (conf Conf, err error) { +func _getExList(pattern string) (hwList []string, err error) { + re, err := regexp.Compile(pattern) + if err != nil { + return nil, fmt.Errorf("failed to compile regex: %w", err) + } + + files, err := os.ReadDir(".") + if err != nil { + return nil, fmt.Errorf("error reading directory: %w", err) + } + + for _, file := range files { + if !file.IsDir() && re.MatchString(file.Name()) { + hwList = append(hwList, file.Name()) + } + } + + return hwList, nil +} + +func _contains(list []string, item string) bool { + for _, v := range list { + if v == item { + return true + } + } + return false +} + +func commitMsgToConf() (confs []Conf, jobtype JobType, err error) { r, err := git.PlainOpen(".") if err != nil { return @@ -108,51 +147,75 @@ func commitMsgToConf() (conf Conf, err error) { return } + var conf Conf + var exList []string + jobtype = HC file := "conf.json" msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) + + // INFO: default config + conf, err = parseConfFile(file) + confs = append(confs, conf) if msg == "" { - conf, err = parseConfFile(file) return } line := strings.Split(msg, "\n")[0] - words := strings.Fields(line) - head := words[0] + var hw string + // INFO: get worktype if strings.HasSuffix(head, ":") || strings.HasSuffix(head, ".") { head = head[:len(head)-1] } - switch head { case "feat", "fix", "refactor", "perf", "test", "build", "revert": - // TODO: Decide strategy to give students error - // if len(words) < 2 { - // return Conf{}, fmt.Errorf("error: hw not assigned") - // } - if len(words) >= 2 { - hw = words[1] - if err = validateHw(hw); err == nil { - file = strings.Replace(file, "conf", "conf-"+hw+"-cq", 1) - } - } + jobtype = CQ case "joj", "grading": - // TODO: Decide strategy to give students error - // if len(words) < 2 { - // return Conf{}, fmt.Errorf("error: hw not assigned") - // } - if len(words) >= 2 { - hw = words[1] - if err = validateHw(hw); err == nil { - file = strings.Replace(file, "conf", "conf-"+hw+"-oj", 1) + jobtype = OJ + } + + // INFO: get configs + if len(words) >= 2 { + hw = words[1] + if err = _validateHw(hw); err == nil { + file = strings.Replace(file, "conf", "conf-"+hw, 1) + } + var exTot []string + + // INFO: get all hw ex if no args provided + exTot, err = _getExList(file) + if len(words) == 2 { + exList = exTot + } else { + var tmpList []string + for idx := 2; idx < len(words); idx++ { + word := words[idx] + num, err := strconv.Atoi(word) + if err != nil { + return confs, HC, fmt.Errorf("error: bad ex number") + } + file := fmt.Sprintf("conf-"+hw+"-ex%d.json", num) + if !_contains(exList, file) { + return confs, HC, fmt.Errorf("error: bad ex number") + } + tmpList = append(tmpList, file) } + exList = tmpList } } - conf, err = parseConfFile(file) + for _, ex := range exList { + conf, err = parseConfFile(ex) + if err != nil { + return + } + confs = append(confs, conf) + } + return } diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index 8d9f91c..c4039ee 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -71,11 +71,12 @@ func outputResult(conf Conf, results []stage.StageResult) error { } func mainImpl() error { - conf, err := commitMsgToConf() + conf, jobtype, err := commitMsgToConf() if err != nil { slog.Error("no conf found", "error", err) return err } + // TODO: implementation for multiple configs setupSlog(conf) executors.InitWithConf(conf.SandboxExecServer, conf.SandboxToken) stages, err := generateStages(conf) -- 2.30.2 From 8d0000016a0d4666fe5ec031764ef367a34a0fdd Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Fri, 20 Sep 2024 15:30:00 +0800 Subject: [PATCH 18/21] Revert "feat: multiple configs" This reverts commit 0409bee600a15a16c94eb8007c1ac498bd758511. --- cmd/joj3/conf.go | 117 +++++++++++------------------------------------ cmd/joj3/main.go | 3 +- 2 files changed, 28 insertions(+), 92 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 038a4ac..0556478 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -3,9 +3,7 @@ package main import ( "fmt" "log/slog" - "os" "regexp" - "strconv" "strings" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" @@ -13,14 +11,6 @@ import ( "github.com/koding/multiconfig" ) -type JobType int - -const ( - HC JobType = iota - CQ - OJ -) - type Conf struct { SandboxExecServer string `default:"localhost:5051"` SandboxToken string `default:""` @@ -91,7 +81,7 @@ func parseConfFile(path string) (conf Conf, err error) { return } -func _validateHw(hw string) error { +func validateHw(hw string) error { matched, err := regexp.MatchString(`^hw[0-9]+$`, hw) if err != nil { return fmt.Errorf("error compiling regex: %w", err) @@ -102,36 +92,7 @@ func _validateHw(hw string) error { return nil } -func _getExList(pattern string) (hwList []string, err error) { - re, err := regexp.Compile(pattern) - if err != nil { - return nil, fmt.Errorf("failed to compile regex: %w", err) - } - - files, err := os.ReadDir(".") - if err != nil { - return nil, fmt.Errorf("error reading directory: %w", err) - } - - for _, file := range files { - if !file.IsDir() && re.MatchString(file.Name()) { - hwList = append(hwList, file.Name()) - } - } - - return hwList, nil -} - -func _contains(list []string, item string) bool { - for _, v := range list { - if v == item { - return true - } - } - return false -} - -func commitMsgToConf() (confs []Conf, jobtype JobType, err error) { +func commitMsgToConf() (conf Conf, err error) { r, err := git.PlainOpen(".") if err != nil { return @@ -147,75 +108,51 @@ func commitMsgToConf() (confs []Conf, jobtype JobType, err error) { return } - var conf Conf - var exList []string - jobtype = HC file := "conf.json" msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) - - // INFO: default config - conf, err = parseConfFile(file) - confs = append(confs, conf) if msg == "" { + conf, err = parseConfFile(file) return } line := strings.Split(msg, "\n")[0] - words := strings.Fields(line) - head := words[0] + words := strings.Fields(line) + + head := words[0] var hw string - // INFO: get worktype if strings.HasSuffix(head, ":") || strings.HasSuffix(head, ".") { head = head[:len(head)-1] } + switch head { case "feat", "fix", "refactor", "perf", "test", "build", "revert": - jobtype = CQ - case "joj", "grading": - jobtype = OJ - } - - // INFO: get configs - if len(words) >= 2 { - hw = words[1] - if err = _validateHw(hw); err == nil { - file = strings.Replace(file, "conf", "conf-"+hw, 1) - } - var exTot []string - - // INFO: get all hw ex if no args provided - exTot, err = _getExList(file) - if len(words) == 2 { - exList = exTot - } else { - var tmpList []string - for idx := 2; idx < len(words); idx++ { - word := words[idx] - num, err := strconv.Atoi(word) - if err != nil { - return confs, HC, fmt.Errorf("error: bad ex number") - } - file := fmt.Sprintf("conf-"+hw+"-ex%d.json", num) - if !_contains(exList, file) { - return confs, HC, fmt.Errorf("error: bad ex number") - } - tmpList = append(tmpList, file) + // TODO: Decide strategy to give students error + // if len(words) < 2 { + // return Conf{}, fmt.Errorf("error: hw not assigned") + // } + if len(words) >= 2 { + hw = words[1] + if err = validateHw(hw); err == nil { + file = strings.Replace(file, "conf", "conf-"+hw+"-cq", 1) + } + } + case "joj", "grading": + // TODO: Decide strategy to give students error + // if len(words) < 2 { + // return Conf{}, fmt.Errorf("error: hw not assigned") + // } + if len(words) >= 2 { + hw = words[1] + if err = validateHw(hw); err == nil { + file = strings.Replace(file, "conf", "conf-"+hw+"-oj", 1) } - exList = tmpList } } - for _, ex := range exList { - conf, err = parseConfFile(ex) - if err != nil { - return - } - confs = append(confs, conf) - } - + conf, err = parseConfFile(file) return } diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index c4039ee..8d9f91c 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -71,12 +71,11 @@ func outputResult(conf Conf, results []stage.StageResult) error { } func mainImpl() error { - conf, jobtype, err := commitMsgToConf() + conf, err := commitMsgToConf() if err != nil { slog.Error("no conf found", "error", err) return err } - // TODO: implementation for multiple configs setupSlog(conf) executors.InitWithConf(conf.SandboxExecServer, conf.SandboxToken) stages, err := generateStages(conf) -- 2.30.2 From 2d08a435a88c79b009ff4812c2eb6bdfca1ae8cb Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Mon, 23 Sep 2024 12:27:56 +0800 Subject: [PATCH 19/21] feat: decide which stage to run based on commit msg --- cmd/joj3/conf.go | 105 ++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 38 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 0556478..bb5f484 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -11,25 +11,35 @@ import ( "github.com/koding/multiconfig" ) +type JobType int + +const ( + HC JobType = iota + CQ + OJ +) + +type Stage struct { + Name string + Executor struct { + Name string + With struct { + Default stage.Cmd + Cases []OptionalCmd + } + } + Parser struct { + Name string + With interface{} + } +} + type Conf struct { SandboxExecServer string `default:"localhost:5051"` SandboxToken string `default:""` LogLevel int `default:"0"` OutputPath string `default:"joj3_result.json"` - Stages []struct { - Name string - Executor struct { - Name string - With struct { - Default stage.Cmd - Cases []OptionalCmd - } - } - Parser struct { - Name string - With interface{} - } - } + Stages []Stage } type OptionalCmd struct { @@ -63,24 +73,51 @@ type OptionalCmd struct { AddressSpaceLimit *bool } -func parseConfFile(path string) (conf Conf, err error) { +func parseConfFile(path string, jobtype JobType) (conf Conf, err error) { 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 } + + filteredStages := []Stage{} + + for _, stage := range conf.Stages { + if filterStage(stage, jobtype) { + filteredStages = append(filteredStages, stage) + } + } + + conf.Stages = filteredStages + return } +func filterStage(stage Stage, jobtype JobType, +) bool { + switch jobtype { + case HC: + return stage.Name == "healthcheck" + case CQ: + return stage.Name == "compile" || stage.Name == "healthcheck" + case OJ: + return true + default: + return false + } +} + func validateHw(hw string) error { matched, err := regexp.MatchString(`^hw[0-9]+$`, hw) if err != nil { @@ -109,11 +146,12 @@ func commitMsgToConf() (conf Conf, err error) { } file := "conf.json" + jobtype := HC msg := commit.Message slog.Debug("commit msg to conf", "msg", msg) if msg == "" { - conf, err = parseConfFile(file) + conf, err = parseConfFile(file, jobtype) return } @@ -128,31 +166,22 @@ func commitMsgToConf() (conf Conf, err error) { head = head[:len(head)-1] } - switch head { - case "feat", "fix", "refactor", "perf", "test", "build", "revert": - // TODO: Decide strategy to give students error - // if len(words) < 2 { - // return Conf{}, fmt.Errorf("error: hw not assigned") - // } - if len(words) >= 2 { - hw = words[1] - if err = validateHw(hw); err == nil { - file = strings.Replace(file, "conf", "conf-"+hw+"-cq", 1) - } + if len(words) == 3 { + hw = words[1] + if err = validateHw(hw); err != nil { + return } - case "joj", "grading": - // TODO: Decide strategy to give students error - // if len(words) < 2 { - // return Conf{}, fmt.Errorf("error: hw not assigned") - // } - if len(words) >= 2 { - hw = words[1] - if err = validateHw(hw); err == nil { - file = strings.Replace(file, "conf", "conf-"+hw+"-oj", 1) - } + + switch head { + case "feat", "fix", "refactor", "perf", "test", "build", "revert": + file = strings.Replace(file, "conf", "conf-"+hw, 1) + jobtype = CQ + case "joj", "grading": + file = strings.Replace(file, "conf", "conf-"+hw, 1) + jobtype = OJ } } - conf, err = parseConfFile(file) + conf, err = parseConfFile(file, jobtype) return } -- 2.30.2 From e4f21a3c92f461ef1b2f644f06e8822cddc8c176 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Mon, 23 Sep 2024 12:34:24 +0800 Subject: [PATCH 20/21] chore: update submodules --- 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 +- 18 files changed, 18 insertions(+), 18 deletions(-) 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 415ab7e..ffd9ab1 160000 --- a/examples/healthcheck/asciimsg +++ b/examples/healthcheck/asciimsg @@ -1 +1 @@ -Subproject commit 415ab7e9d8e74a5290eec18bec54b3a6d727d3d7 +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 -- 2.30.2 From 73f1688e419258406628a74bb367497c2aff4657 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Mon, 23 Sep 2024 12:57:17 +0800 Subject: [PATCH 21/21] fix: filter stages --- cmd/joj3/conf.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 544c9d0..bcf28d8 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -85,11 +85,25 @@ func parseConfFile(path string, jobtype JobType) (conf Conf, err error) { slog.Error("parse stages conf", "error", err) return } + + if err = d.Validate(&conf); err != nil { + slog.Error("validate stages conf", "error", err) + return + } + + filteredStages := []Stage{} + for _, stage := range conf.Stages { + if filterStage(stage, jobtype) { + filteredStages = append(filteredStages, stage) + } + } + + conf.Stages = filteredStages + return } -func filterStage(stage Stage, jobtype JobType, -) bool { +func filterStage(stage Stage, jobtype JobType) bool { switch jobtype { case HC: return stage.Name == "healthcheck" -- 2.30.2