Skip to content

Commit 4e64cf2

Browse files
authored
Merge pull request #26 from jim380/jay/add-lint-in-ci
Add golangci-lint
2 parents 44cb128 + 3116091 commit 4e64cf2

23 files changed

+195
-68
lines changed

.github/workflows/ build-and-publish.yml renamed to .github/workflows/build-and-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
run: echo ${{ steps.docker_build.outputs.digest }}
8080

8181
- name: Create GitHub Release
82+
if: startsWith(github.ref, 'refs/tags/')
8283
uses: ncipollo/release-action@v1
8384
with:
8485
allowUpdates: true

.github/workflows/lint.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, labeled]
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
repository-projects: read
14+
packages: read
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
golangci-lint:
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 10
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
- name: Setup Go
30+
uses: actions/setup-go@v4
31+
with:
32+
go-version-file: go.mod
33+
cache: true
34+
- name: Run golangci-lint
35+
uses: golangci/golangci-lint-action@v3
36+
with:
37+
version: v1.56.0
38+
args: --timeout 10m --tests=false --out-format=github-actions
39+
skip-pkg-cache: true

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
---
21
name: Tests
32

43
on:
54
push:
65
branches:
7-
- main
6+
- master
87
pull_request:
98
types: [opened, synchronize, reopened, labeled]
9+
workflow_dispatch:
1010

1111
permissions:
1212
contents: read
1313
repository-projects: read
1414
packages: read
1515

1616
concurrency:
17-
group: ci-${{ github.ref }}-tests
17+
group: ${{ github.workflow }}-${{ github.ref }}
1818
cancel-in-progress: true
1919

2020
jobs:

config/main.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,13 @@ func GetLogLevel(lvl string) zapcore.Level {
146146
}
147147
}
148148

149-
func GetDenomList(chain string, chainList map[string][]string) []string {
150-
var found bool
151-
149+
func GetDenomList(chain string, chainList map[string][]string) ([]string, error) {
152150
for k, v := range chainList {
153151
if k == chain {
154-
found = true
155-
return v
152+
return v, nil
156153
}
157154
}
158-
if !found {
159-
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "chain("+chain+") denom not supported"))
160-
}
161-
return []string{}
155+
return []string{}, fmt.Errorf("chain(%s) denom not supported", chain)
162156
}
163157

164158
func GetChainList() map[string][]string {
@@ -171,7 +165,9 @@ func GetChainList() map[string][]string {
171165
byteValue, _ := io.ReadAll(jsonFile)
172166

173167
var chains []Chain
174-
json.Unmarshal(byteValue, &chains)
168+
if err := json.Unmarshal(byteValue, &chains); err != nil {
169+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
170+
}
175171

176172
chainList := make(map[string][]string)
177173
for _, chain := range chains {

exporter/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ func Start(config *config.Config, port string, logger *zap.Logger, restService c
1818
}
1919

2020
func CollectMetrics(cfg *config.Config, log *zap.Logger, restService controllers.RestServices, rpcService controllers.RpcServices) {
21-
denomList := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
21+
denomList, err := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
22+
if err != nil {
23+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
24+
}
2225

2326
registerGauges(denomList)
2427
counterVecs := registerLabels()

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ func main() {
7171
go dashboard.StartDashboard()
7272
}
7373

74-
denomList := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
74+
denomList, err := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
75+
if err != nil {
76+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
77+
}
7578

7679
// start the data fetcher in a separate thread
7780
fetcher.Start(&cfg, restServicesController, rpcServicesController, denomList, logger)

services/akash/akash.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async
3535
if err != nil {
3636
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
3737
}
38-
json.Unmarshal(res, &deployments)
38+
if err := json.Unmarshal(res, &deployments); err != nil {
39+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
40+
}
3941

4042
// get total deployments count
4143
totalDeploymentsCount, err := strconv.Atoi(deployments.Pagination.Total)
@@ -49,7 +51,9 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async
4951
if err != nil {
5052
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
5153
}
52-
json.Unmarshal(resActive, &activeDeployments)
54+
if err := json.Unmarshal(resActive, &activeDeployments); err != nil {
55+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
56+
}
5357

5458
activeDeploymentsCount, err := strconv.Atoi(activeDeployments.Pagination.Total)
5559
if err != nil {
@@ -74,7 +78,9 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa
7478
if err != nil {
7579
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
7680
}
77-
json.Unmarshal(res, &providers)
81+
if err := json.Unmarshal(res, &providers); err != nil {
82+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
83+
}
7884

7985
// handle pagination
8086
nextKey := providers.Pagination.NextKey
@@ -84,7 +90,9 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa
8490
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
8591
}
8692
var nextPage akash.ProvidersResponse
87-
json.Unmarshal(res, &nextPage)
93+
if err := json.Unmarshal(res, &nextPage); err != nil {
94+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
95+
}
8896

8997
// append to the response
9098
providers.Providers = append(providers.Providers, nextPage.Providers...)
@@ -175,7 +183,9 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide
175183
if err != nil {
176184
return fmt.Errorf("error querying auditors for provider owner: %w", err)
177185
}
178-
json.Unmarshal(res, &auditors)
186+
if err := json.Unmarshal(res, &auditors); err != nil {
187+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
188+
}
179189

180190
// handle pagination
181191
nextKey := auditors.Pagination.NextKey
@@ -185,7 +195,9 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide
185195
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
186196
}
187197
var nextPage akash.AuditorsResponse
188-
json.Unmarshal(res, &nextPage)
198+
if err := json.Unmarshal(res, &nextPage); err != nil {
199+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
200+
}
189201

190202
// append to the response
191203
auditors.Providers = append(auditors.Providers, nextPage.Providers...)
@@ -259,7 +271,9 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi
259271
if err != nil {
260272
return fmt.Errorf("error querying deployments for provider owner: %w", err)
261273
}
262-
json.Unmarshal(res, &deployments)
274+
if err := json.Unmarshal(res, &deployments); err != nil {
275+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
276+
}
263277

264278
// handle pagination
265279
nextKey := deployments.Pagination.NextKey
@@ -269,7 +283,9 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi
269283
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
270284
}
271285
var nextPage akash.DeploymentsResponse
272-
json.Unmarshal(res, &nextPage)
286+
if err := json.Unmarshal(res, &nextPage); err != nil {
287+
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
288+
}
273289

274290
// append to the response
275291
deployments.Deployments = append(deployments.Deployments, nextPage.Deployments...)

services/bank.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func (bs *BankService) GetBalanceInfo(cfg config.Config, rd *types.RESTData) {
4343
if err != nil {
4444
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
4545
}
46-
json.Unmarshal(res, &b)
46+
if err := json.Unmarshal(res, &b); err != nil {
47+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
48+
}
4749
if strings.Contains(string(res), "not found") {
4850
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
4951
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
@@ -61,7 +63,9 @@ func (bs *BankService) GetRewardsCommissionInfo(cfg config.Config, rd *types.RES
6163
if err != nil {
6264
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
6365
}
64-
json.Unmarshal(res, &rc)
66+
if err := json.Unmarshal(res, &rc); err != nil {
67+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
68+
}
6569
if strings.Contains(string(res), "not found") {
6670
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
6771
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {

services/block.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ func (bs *BlockService) GetInfo(cfg config.Config) types.Blocks {
3939
if err != nil {
4040
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error()))
4141
}
42-
json.Unmarshal(res, &bs.Block)
42+
if err := json.Unmarshal(res, &bs.Block); err != nil {
43+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
44+
}
4345
if strings.Contains(string(res), "not found") {
4446
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
4547
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
@@ -56,7 +58,9 @@ func (bs *BlockService) GetLastBlockTimestamp(cfg config.Config, currentHeight i
5658
if err != nil {
5759
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error()))
5860
}
59-
json.Unmarshal(res, &lastBlock)
61+
if err := json.Unmarshal(res, &lastBlock); err != nil {
62+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
63+
}
6064
if strings.Contains(string(res), "not found") {
6165
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
6266
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {

services/consensus.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func (css *ConsensusService) GetConsensusDump(cfg config.Config, rpc *types.RPCD
3030
if err != nil {
3131
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
3232
}
33-
json.Unmarshal(res, &cs)
33+
if err := json.Unmarshal(res, &cs); err != nil {
34+
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
35+
}
3436

3537
conspubMonikerMap := rest.GetConspubMonikerMapWrapper()
3638
// cs.Result.Validatorset.Validators is already sorted based on voting power

0 commit comments

Comments
 (0)