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/cmd/joj3/conf.go b/cmd/joj3/conf.go index 9ada30b..769b324 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -61,11 +61,20 @@ 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 + } return } @@ -85,6 +94,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 af99032..13a3d05 160000 --- a/examples/diff/basic +++ b/examples/diff/basic @@ -1 +1 @@ -Subproject commit af990327ab095c22a383448ad70d915f8d10490b +Subproject commit 13a3d05163213ce44c1ec638d4a409ed9db90530 diff --git a/examples/diff/complex b/examples/diff/complex index ac7a2fc..7f6f6e8 160000 --- a/examples/diff/complex +++ b/examples/diff/complex @@ -1 +1 @@ -Subproject commit ac7a2fc912fb51af156cd4babb7e72148ebe1c14 +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 36bb5fb..415ab7e 160000 --- a/examples/healthcheck/asciimsg +++ b/examples/healthcheck/asciimsg @@ -1 +1 @@ -Subproject commit 36bb5fb15f100078bd3af1027017825932f8c24b +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 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, }) } 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, 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" )