Compare commits
6 Commits
d59de7bbd8
...
7cbce3cb54
Author | SHA1 | Date | |
---|---|---|---|
7cbce3cb54 | |||
c5d6433cb0 | |||
d8ec7d1d75 | |||
f4bc61654c | |||
92f375ed01 | |||
175685c074 |
31
.drone.yml
31
.drone.yml
|
@ -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
|
|
44
.gitea/workflows/test.yaml
Normal file
44
.gitea/workflows/test.yaml
Normal file
|
@ -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
|
10
Makefile
10
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
|
BUILD_DIR = ./build
|
||||||
TMP_DIR = ./tmp
|
TMP_DIR = ./tmp
|
||||||
|
@ -15,9 +15,17 @@ clean:
|
||||||
rm -rf $(TMP_DIR)/*
|
rm -rf $(TMP_DIR)/*
|
||||||
rm -rf *.out
|
rm -rf *.out
|
||||||
|
|
||||||
|
lint:
|
||||||
|
golangci-lint run
|
||||||
|
|
||||||
prepare-test:
|
prepare-test:
|
||||||
git submodule update --init --remote
|
git submodule update --init --remote
|
||||||
|
|
||||||
test:
|
test:
|
||||||
./scripts/prepare_test_repos.sh $(TMP_DIR)
|
./scripts/prepare_test_repos.sh $(TMP_DIR)
|
||||||
go test -coverprofile cover.out -v ./...
|
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 ./...
|
||||||
|
|
|
@ -61,11 +61,20 @@ type OptionalCmd struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfFile(path string) (conf Conf, err error) {
|
func parseConfFile(path string) (conf Conf, err error) {
|
||||||
m := multiconfig.NewWithPath(path)
|
d := &multiconfig.DefaultLoader{}
|
||||||
if err = m.Load(&conf); err != nil {
|
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)
|
slog.Error("parse stages conf", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err = d.Validate(&conf); err != nil {
|
||||||
|
slog.Error("validate stages conf", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +94,6 @@ func commitMsgToConf() (conf Conf, err error) {
|
||||||
msg := commit.Message
|
msg := commit.Message
|
||||||
slog.Debug("commit msg to conf", "msg", msg)
|
slog.Debug("commit msg to conf", "msg", msg)
|
||||||
// TODO: parse msg to conf name
|
// TODO: parse msg to conf name
|
||||||
conf, err = parseConfFile("conf.toml")
|
conf, err = parseConfFile("conf.json")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6084f4dc39929257f35eb2467b5aa105ceb03e81
|
Subproject commit 235d1980bb55c8ec231ab03933cf8e8335344b81
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4e5fab93e5a0ce67c8f40fef1e8f4cab7018fc5d
|
Subproject commit fc02680432a9003d623970187acce73276ce03b5
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1512cb5f20473a598d7504a08dacff3d6406b983
|
Subproject commit 3a0760f2442723eb77eafacbf89b0d25d62eb607
|
|
@ -1 +1 @@
|
||||||
Subproject commit 40fe2dbef18ac5188f72fe788426e3d9c8aa88ae
|
Subproject commit 578be035a0aedc0d9b5ffe5f40d4162e6483b6d0
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1ec92f39ce2fac82356e79ae08c457784769d49c
|
Subproject commit 80ec230f63267a10777ae58ebb632709fc562e85
|
|
@ -1 +1 @@
|
||||||
Subproject commit af990327ab095c22a383448ad70d915f8d10490b
|
Subproject commit 13a3d05163213ce44c1ec638d4a409ed9db90530
|
|
@ -1 +1 @@
|
||||||
Subproject commit ac7a2fc912fb51af156cd4babb7e72148ebe1c14
|
Subproject commit 7f6f6e881d39e870e51afb3fd36fdbef20b9cb35
|
|
@ -1 +1 @@
|
||||||
Subproject commit a236c7ea934de5e59525fa27e4211f4a48dbbf93
|
Subproject commit 1492b43605a17850071d4e6674151719ae55e761
|
|
@ -1 +1 @@
|
||||||
Subproject commit 36bb5fb15f100078bd3af1027017825932f8c24b
|
Subproject commit 415ab7e9d8e74a5290eec18bec54b3a6d727d3d7
|
|
@ -1 +1 @@
|
||||||
Subproject commit 62c43fe51666417c7cbb227d6daaeee7189b6944
|
Subproject commit 02de953cbc841afb3f53d0d4096b423f91d78593
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5c2cd9e6b31c6f223ac5d3ee5b07f11fbd378427
|
Subproject commit 3161962adba8d6f2663963eb5c39578cb7874ab8
|
|
@ -1 +1 @@
|
||||||
Subproject commit fc9828bde135e53a7ef3e6367c708d9a000afc74
|
Subproject commit 01b362e3bd5156211f8152237b101301560433b8
|
|
@ -1 +1 @@
|
||||||
Subproject commit a49a6aa29d3dcb0509e8de540db0781aca596f26
|
Subproject commit 0648e32a8932e561e102f336766ca18165866ab8
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2f455dca9d28e39926e68b9b13eef39b0a9f67fc
|
Subproject commit 5e25b932fc3950f382c8533e018520b04542af4a
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9938ef006e25c8caea24493172e60a58380c8df4
|
Subproject commit 1f53f4df209662a30f7005a925fff0f0e3d94b13
|
|
@ -1 +1 @@
|
||||||
Subproject commit 96d02348a20a5a244cd4f82e94a04dccfe3f009c
|
Subproject commit 244a63f54397196f9f9a08114f4eef279093f2a6
|
|
@ -1 +1 @@
|
||||||
Subproject commit aa5bf333e30c9c0175e021c001d85f90092d7d1a
|
Subproject commit 980baf11df313e659fb4b1dea1a126add15ac547
|
|
@ -1 +1 @@
|
||||||
Subproject commit ed17357671e1c6f8aa7f534a482d9b2fac76d959
|
Subproject commit 1d886f8754d0a22471405580d231b2691b929bfd
|
|
@ -5,6 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
|
Score int
|
||||||
Comment string
|
Comment string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ func (*Dummy) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
}
|
}
|
||||||
var res []stage.ParserResult
|
var res []stage.ParserResult
|
||||||
for range results {
|
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
|
return res, false, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,22 +7,24 @@ import (
|
||||||
"github.com/criyle/go-judge/envexec"
|
"github.com/criyle/go-judge/envexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct{}
|
type Conf struct {
|
||||||
|
Score int
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
|
||||||
type ResultStatus struct{}
|
type ResultStatus struct{}
|
||||||
|
|
||||||
func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) (
|
func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
[]stage.ParserResult, bool, error,
|
[]stage.ParserResult, bool, error,
|
||||||
) {
|
) {
|
||||||
// TODO: more conf options
|
conf, err := stage.DecodeConf[Conf](confAny)
|
||||||
_, err := stage.DecodeConf[Conf](confAny)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, true, err
|
return nil, true, err
|
||||||
}
|
}
|
||||||
forceQuit := false
|
forceQuit := false
|
||||||
var res []stage.ParserResult
|
var res []stage.ParserResult
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
comment := ""
|
comment := conf.Comment
|
||||||
if result.Status != stage.Status(envexec.StatusAccepted) {
|
if result.Status != stage.Status(envexec.StatusAccepted) {
|
||||||
forceQuit = true
|
forceQuit = true
|
||||||
comment = fmt.Sprintf(
|
comment = fmt.Sprintf(
|
||||||
|
@ -30,7 +32,7 @@ func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
res = append(res, stage.ParserResult{
|
res = append(res, stage.ParserResult{
|
||||||
Score: 0,
|
Score: conf.Score,
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package stage
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/criyle/go-judge/envexec"
|
"github.com/criyle/go-judge/envexec"
|
||||||
)
|
)
|
||||||
|
@ -126,8 +125,8 @@ func (r ExecutorResult) String() string {
|
||||||
Status Status
|
Status Status
|
||||||
ExitStatus int
|
ExitStatus int
|
||||||
Error string
|
Error string
|
||||||
Time time.Duration
|
Time uint64
|
||||||
RunTime time.Duration
|
RunTime uint64
|
||||||
Memory envexec.Size
|
Memory envexec.Size
|
||||||
Files map[string]string
|
Files map[string]string
|
||||||
FileIDs map[string]string
|
FileIDs map[string]string
|
||||||
|
@ -137,8 +136,8 @@ func (r ExecutorResult) String() string {
|
||||||
Status: r.Status,
|
Status: r.Status,
|
||||||
ExitStatus: r.ExitStatus,
|
ExitStatus: r.ExitStatus,
|
||||||
Error: r.Error,
|
Error: r.Error,
|
||||||
Time: time.Duration(r.Time),
|
Time: r.Time,
|
||||||
RunTime: time.Duration(r.RunTime),
|
RunTime: r.RunTime,
|
||||||
Memory: envexec.Size(r.Memory),
|
Memory: envexec.Size(r.Memory),
|
||||||
Files: make(map[string]string),
|
Files: make(map[string]string),
|
||||||
FileIDs: r.FileIDs,
|
FileIDs: r.FileIDs,
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"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.
|
// 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)
|
slog.Error("getting reference", "err", err)
|
||||||
return fmt.Errorf("error getting reference: %v", 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 {
|
if err != nil {
|
||||||
slog.Error("getting commits", "err", err)
|
slog.Error("getting latest commit", "err", err)
|
||||||
return fmt.Errorf("error getting commits from reference %s: %v", ref.Hash(), err)
|
return fmt.Errorf("error getting latest commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var msgs []string
|
msg := commit.Message
|
||||||
err = commits.ForEach(func(c *object.Commit) error {
|
if msg == "" {
|
||||||
msgs = append(msgs, c.Message)
|
|
||||||
return nil
|
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
|
// List of prefixes to ignore in the commit message
|
||||||
ignoredPrefixes := []string{
|
ignoredPrefixes := []string{
|
||||||
"Co-authored-by:",
|
"Co-authored-by:",
|
||||||
|
@ -53,35 +48,31 @@ func NonAsciiMsg(root string) error {
|
||||||
"Reviewed-on:",
|
"Reviewed-on:",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range msgs {
|
// Split message by lines and ignore specific lines with prefixes
|
||||||
if msg == "" {
|
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
|
continue
|
||||||
}
|
}
|
||||||
// Split message by lines and ignore specific lines with prefixes
|
// Check for non-ASCII characters in the rest of the lines
|
||||||
lines := strings.Split(msg, "\n")
|
for _, c := range line {
|
||||||
for _, line := range lines {
|
if c > unicode.MaxASCII {
|
||||||
trimmedLine := strings.TrimSpace(line)
|
isCommitLegal = false
|
||||||
ignore := false
|
break
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user