Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add yarn to docker in order to support web project #216

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ FROM alpine:3.20 as runner
# Do not install unnecessary tools to reduce image size.
RUN set -eux \
apk update && \
apk --no-cache add ca-certificates luacheck cppcheck shellcheck git openssh
apk --no-cache add ca-certificates luacheck cppcheck shellcheck git openssh yarn
WORKDIR /
# check binary
RUN cppcheck --version \
&& shellcheck --version \
&& luacheck --version \
&& git --version \
&& ssh -V \
&& yarn --version

COPY --from=builder /reviewbot /reviewbot
COPY --from=builder /go/bin/golangci-lint /usr/local/bin/
Expand Down
34 changes: 31 additions & 3 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,42 @@ customConfig: # custom config for specific orgs or repos
qbox/net-cache:
golangci-lint:
enable: true
args: ["run", "--enable-all", "--timeout=5m0s", "--allow-parallel-runners=true"] # disable staticcheck globally since we have a separate linter for it
args: [
"run",
"--enable-all",
"--timeout=5m0s",
"--allow-parallel-runners=true",
] # disable staticcheck globally since we have a separate linter for it
qbox/net-gslb:
golangci-lint:
enable: true
args: ["run", "--enable-all", "--timeout=5m0s", "--allow-parallel-runners=true"] # disable staticcheck globally since we have a separate linter for it
args: [
"run",
"--enable-all",
"--timeout=5m0s",
"--allow-parallel-runners=true",
] # disable staticcheck globally since we have a separate linter for it

qbox/kodo:
golangci-lint:
enable: true
workDir: "src/qiniu.com/kodo"
args: ["run", "--enable-all", "--timeout=5m0s", "--allow-parallel-runners=true"]
args:
[
"run",
"--enable-all",
"--timeout=5m0s",
"--allow-parallel-runners=true",
]

qbox/kodo-ops:
golangci-lint:
enable: true
command:
- "/bin/sh"
- "-c"
- "--"
args:
- |
cd website && yarn build && cd ..
golangci-lint run --enable-all --timeout=5m0s --allow-parallel-runners=true --print-issued-lines=false --out-format=line-number >> $ARTIFACT/lint.log 2>&1
60 changes: 50 additions & 10 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

func TestConfig(t *testing.T) {
var testCases = []struct {
testCases := []struct {
name string
expectError bool
rawConfig string
Expand Down Expand Up @@ -109,10 +109,10 @@
t.Run(tc.name, func(t *testing.T) {
configDir := t.TempDir()
configPath := filepath.Join(configDir, "config.yaml")
if err := os.WriteFile(configPath, []byte(tc.rawConfig), 0666); err != nil {
if err := os.WriteFile(configPath, []byte(tc.rawConfig), 0o600); err != nil {
t.Fatalf("fail to write prow config: %v", err)
}
defer os.Remove(configPath)

Check warning on line 115 in config/config_test.go

View check run for this annotation

qiniu-x / golangci-lint

config/config_test.go#L115

only one cuddle assignment allowed before defer statement (wsl)

c, err := NewConfig(configPath)
if tc.expectError {
Expand Down Expand Up @@ -173,9 +173,22 @@
qbox/net-tools:
golangci-lint:
enable: false

qbox/kodo-ops:
golangci-lint:
enable: true
command:
- "/bin/sh"
- "-c"
- "--"
args:
- |
cd website && yarn build && cd ..
golangci-lint run --enable-all --timeout=5m0s --allow-parallel-runners=true --print-issued-lines=false --out-format=line-number >> $ARTIFACT/lint.log 2>&1

`

if err := os.WriteFile(configPath, []byte(rawConfig), 0666); err != nil {
if err := os.WriteFile(configPath, []byte(rawConfig), 0o600); err != nil {
t.Fatalf("fail to write prow config: %v", err)
}
defer os.Remove(configPath)
Expand All @@ -200,6 +213,7 @@
want: Linter{
Enable: boolPtr(true),
WorkDir: "nginx",
Command: []string{"luacheck"},
},
},
{
Expand All @@ -211,6 +225,7 @@
Enable: boolPtr(true),
Args: []string{"run", "-D", "staticcheck"},
ConfigPath: "linters-config/.golangci.yml",
Command: []string{"golangci-lint"},
},
},
{
Expand All @@ -219,7 +234,8 @@
repo: "net-cache",
linter: "staticcheck",
want: Linter{
Enable: boolPtr(true),
Enable: boolPtr(true),
Command: []string{"staticcheck"},
},
},
{
Expand All @@ -228,7 +244,8 @@
repo: "net-gslb",
linter: "staticcheck",
want: Linter{
Enable: boolPtr(true),
Enable: boolPtr(true),
Command: []string{"staticcheck"},
},
},
{
Expand All @@ -237,7 +254,8 @@
repo: "net-gslb",
linter: "staticcheck",
want: Linter{
Enable: boolPtr(true),
Enable: boolPtr(true),
Command: []string{"staticcheck"},
},
},
{
Expand All @@ -249,6 +267,7 @@
Enable: boolPtr(true),
Args: []string{"run", "-D", "staticcheck"},
ConfigPath: "linters-config/.golangci.yml",
Command: []string{"golangci-lint"},
},
},
{
Expand All @@ -258,8 +277,8 @@
linter: "golangci-lint",
want: Linter{
Enable: boolPtr(true),
Args: []string{},
ConfigPath: "linters-config/.golangci.yml",
Command: []string{"golangci-lint"},
},
},
{
Expand All @@ -270,6 +289,7 @@
want: Linter{
Enable: boolPtr(true),
WorkDir: "src/qiniu.com/kodo",
Command: []string{"staticcheck"},
},
},
{
Expand All @@ -281,6 +301,7 @@
Enable: boolPtr(true),
ConfigPath: "repo.golangci.yml",
Args: []string{},
Command: []string{"golangci-lint"},
},
},
{
Expand All @@ -289,7 +310,22 @@
repo: "net-tools",
linter: "golangci-lint",
want: Linter{
Enable: boolPtr(false),
Enable: boolPtr(false),
Command: []string{"golangci-lint"},
Args: []string{"run", "-D", "staticcheck"},
},
},
{
name: "case11 - complex script",
org: "qbox",
repo: "kodo-ops",
linter: "golangci-lint",
want: Linter{
Enable: boolPtr(true),
Command: []string{"/bin/sh", "-c", "--"},
Args: []string{
"cd website && yarn build && cd ..\ngolangci-lint run --enable-all --timeout=5m0s --allow-parallel-runners=true --print-issued-lines=false --out-format=line-number >> $ARTIFACT/lint.log 2>&1\n",
},
},
},
}
Expand All @@ -305,8 +341,12 @@
t.Errorf("expected %v, got %v", tc.want.WorkDir, got.WorkDir)
}

if tc.want.Args != nil && len(got.Args) != len(tc.want.Args) {
t.Errorf("expected %v, got %v", tc.want.Args, got.Args)
if len(got.Command) != len(tc.want.Command) || !reflect.DeepEqual(got.Command, tc.want.Command) {
t.Errorf("expected %v, got %v", tc.want.Command, got.Command)
}

if len(got.Args) != len(tc.want.Args) || !reflect.DeepEqual(got.Args, tc.want.Args) {
t.Errorf("args expected %v, got %v", tc.want.Args, got.Args)
}

if !strings.HasSuffix(got.ConfigPath, tc.want.ConfigPath) {
Expand Down
Loading