Skip to content

Commit a4eaa88

Browse files
committed
feat: add linter to CI
1 parent 41a6184 commit a4eaa88

File tree

7 files changed

+95
-12
lines changed

7 files changed

+95
-12
lines changed

.github/workflows/build.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
14+
go-tests:
15+
name: Running Go tests
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.17'
22+
cache-dependency-path: ./go.mod
23+
- name: Tests
24+
run: go test -v $(go list ./...)
25+
26+
frontend:
27+
name: Front-end
28+
runs-on: ubuntu-latest
29+
needs: [ go-tests ]
30+
steps:
31+
- uses: actions/checkout@v3
32+
- uses: actions/setup-node@v3
33+
with:
34+
node-version: '20'
35+
cache: 'yarn'
36+
cache-dependency-path: ./web/yarn.lock
37+
- name: Build
38+
run: |
39+
yarn install
40+
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true npx craco build
41+
working-directory: ./web
42+
env:
43+
CI: false
44+
45+
backend:
46+
name: Back-end
47+
runs-on: ubuntu-latest
48+
needs: [ go-tests ]
49+
steps:
50+
- uses: actions/checkout@v3
51+
- uses: actions/setup-go@v4
52+
with:
53+
go-version: '1.17'
54+
cache-dependency-path: ./go.mod
55+
- run: go version
56+
- name: Build
57+
run: |
58+
go build -race -ldflags "-extldflags '-static'"
59+
working-directory: ./
60+
61+
linter:
62+
name: Go-Linter
63+
runs-on: ubuntu-latest
64+
needs: [ go-tests ]
65+
steps:
66+
- uses: actions/checkout@v3
67+
- uses: actions/setup-go@v4
68+
with:
69+
go-version: '1.17'
70+
cache: false
71+
72+
# gen a dummy config file
73+
- run: touch dummy.yml
74+
75+
- name: golangci-lint
76+
uses: golangci/golangci-lint-action@v3
77+
with:
78+
version: latest
79+
args: --disable-all -c dummy.yml -E=gofumpt --max-same-issues=0 --timeout 5m --modules-download-mode=mod

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ tmpFiles/
2222
*.tmp
2323
logs/
2424
lastupdate.tmp
25-
commentsRouter*.go
25+
commentsRouter*.go
26+
27+
# Build artifacts
28+
caswaf
29+
web/build
30+
web/nul

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func main() {
1818
AllowCredentials: true,
1919
}))
2020

21-
//beego.DelStaticPath("/static")
21+
// beego.DelStaticPath("/static")
2222
beego.SetStaticPath("/static", "web/build/static")
2323
// https://studygolang.com/articles/2303
2424
beego.InsertFilter("/", beego.BeforeRouter, routers.TransparentStatic) // must has this for default page

object/dataset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func UpdateDataset(id string, dataset *Dataset) bool {
8585
panic(err)
8686
}
8787

88-
//return affected != 0
88+
// return affected != 0
8989
return true
9090
}
9191

routers/router.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ func init() {
1111
}
1212

1313
func initAPI() {
14-
ns :=
15-
beego.NewNamespace("/api",
16-
beego.NSInclude(
17-
&controllers.ApiController{},
18-
),
19-
)
14+
ns := beego.NewNamespace("/api",
15+
beego.NSInclude(
16+
&controllers.ApiController{},
17+
),
18+
)
2019
beego.AddNamespace(ns)
2120

2221
beego.Router("/api/signin", &controllers.ApiController{}, "POST:Signin")

util/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "encoding/json"
44

55
func StructToJson(v interface{}) string {
66
data, err := json.MarshalIndent(v, "", " ")
7-
//data, err := json.Marshal(v)
7+
// data, err := json.Marshal(v)
88
if err != nil {
99
panic(err)
1010
}

util/string.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func ReadStringFromPath(path string) string {
8888
}
8989

9090
func WriteStringToPath(s string, path string) {
91-
err := ioutil.WriteFile(path, []byte(s), 0644)
91+
err := ioutil.WriteFile(path, []byte(s), 0o644)
9292
if err != nil {
9393
panic(err)
9494
}
@@ -104,7 +104,7 @@ func ReadBytesFromPath(path string) []byte {
104104
}
105105

106106
func WriteBytesToPath(b []byte, path string) {
107-
err := ioutil.WriteFile(path, b, 0644)
107+
err := ioutil.WriteFile(path, b, 0o644)
108108
if err != nil {
109109
panic(err)
110110
}

0 commit comments

Comments
 (0)