Skip to content

Commit

Permalink
fix: github action to lint (#102)
Browse files Browse the repository at this point in the history
* fix linter action

* remove slinky from workflow
  • Loading branch information
Vritra4 authored Jul 17, 2024
1 parent 139f2ef commit e1c04bb
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 52 deletions.
38 changes: 29 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ jobs:
golangci:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs/*
GOPRIVATE: github.com/initia-labs
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.1
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
- uses: technote-space/get-diff-action@v5
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
Expand All @@ -41,26 +44,43 @@ jobs:
go.sum
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- name: run go linters
# install golangci-lint
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- name: run go linters (long)
if: env.GIT_DIFF
id: lint_long
run: |
make tools
make lint
if: env.GIT_DIFF
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: run go linters (short)
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
run: |
make lint
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
LINT_DIFF: 1
# Use --check or --exit-code when available (Go 1.19?)
# https://github.com/golang/go/issues/27005
tidy:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs/*
GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
runs-on: ubuntu-latest
name: tidy
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- run: |
Expand Down
58 changes: 38 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- dogsled
- dupl
- errcheck
- golint
- ineffassign
- unconvert
- misspell
- govet
# - unused
# - deadcode
- exportloopref
- goconst
- gofmt
- goimports
- gosec
# - staticcheck
linters-settings:
gocyclo:
min-complexity: 11
errcheck:
ignore: fmt:.*,io/ioutil:^Read.*,github.com/spf13/cobra:MarkFlagRequired,github.com/spf13/viper:BindPFlag
golint:
min-confidence: 1.1
- gosimple
- govet
- ineffassign
- misspell
# - nakedret
- nolintlint
# - prealloc
- staticcheck
# - structcheck // to be fixed by golangci-lint
- stylecheck
- typecheck
- unconvert
- unused

issues:
exclude:
- composite
run:
tests: false
exclude-rules:
- linters:
- stylecheck
text: "ST1003:"
max-same-issues: 50

linters-settings:
dogsled:
max-blank-identifiers: 3
#golint:
# min-confidence: 0
goconst:
ignore-tests: true
#maligned:
# suggest-new: true
misspell:
locale: US
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ proto-check-breaking:
.PHONY: proto-all proto-gen proto-pulsar-gen proto-format proto-lint proto-check-breaking


###############################################################################
### Linting ###
###############################################################################

lint:
golangci-lint run --out-format=tab --timeout=15m --tests=false

lint-fix:
golangci-lint run --fix --out-format=tab --timeout=15m --tests=false

.PHONY: lint lint-fix


###############################################################################
### Tests
###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion contrib/launchtools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (systemKeys *SystemKeys) Finalize(buf *bufio.Reader) error {
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randString(n int) string {
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
rand := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint

b := make([]rune, n)
for i := range b {
Expand Down
2 changes: 1 addition & 1 deletion contrib/launchtools/steps/bridgeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/pkg/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
tmclient "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

"github.com/initia-labs/OPinit/contrib/launchtools"
Expand Down
4 changes: 2 additions & 2 deletions contrib/launchtools/steps/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func initializeChains(config *launchtools.Config, basePath string) func(*Relayer
pathName := fmt.Sprintf("chain%d", i)
fileName := fmt.Sprintf("%s/%s.json", basePath, pathName)

if err := os.WriteFile(fileName, bz, 0644); err != nil {
if err := os.WriteFile(fileName, bz, 0600); err != nil {
panic(errors.New("failed to write chain config"))
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func initializePaths(config *launchtools.Config, basePath string) func(*Relayer)
panic(errors.New("failed to create path config"))
}

if err := os.WriteFile(fmt.Sprintf("%s/paths.json", basePath), pathConfigJSON, 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s/paths.json", basePath), pathConfigJSON, 0600); err != nil {
panic(errors.New("failed to write path config"))
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/launchtools/steps/runapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func RunApp(_ *launchtools.Config) launchtools.LauncherStepFunc {
ctx.ServerContext().Config.Consensus.CreateEmptyBlocks = true
ctx.ServerContext().Config.Consensus.CreateEmptyBlocksInterval = CreateEmptyBlocksInterval

// create a channel to synchronise on app creation
// create a channel to synchronize on app creation
var syncDone = make(chan interface{})

// create cobra command context
Expand Down
13 changes: 10 additions & 3 deletions contrib/launchtools/steps/stopapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ func StopApp(_ *launchertypes.Config) launchertypes.LauncherStepFunc {
log.Info("cleanup")
log.Info("waiting for app to stop")

syscall.Kill(syscall.Getpid(), syscall.SIGINT)
err := syscall.Kill(syscall.Getpid(), syscall.SIGINT)
if err != nil {
log.Error("failed to raise a kill signal", "error", err)
}

// wait for the app to stop
ctx.GetErrorGroup().Wait()
log.Info("cleanup finished")
err = ctx.GetErrorGroup().Wait()
if err != nil {
log.Error("cleanup failed", "error", err)
return err
}

log.Info("cleanup finished")
return nil
}
}
4 changes: 2 additions & 2 deletions contrib/launchtools/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (l *LauncherContext) FinalizeOutput(config *Config) (string, error) {
return "", errors.Wrap(err, "failed to marshal artifacts")
}

if err := os.WriteFile(path.Join(l.artifactsDir, "artifacts.json"), bz, os.ModePerm); err != nil {
if err := os.WriteFile(path.Join(l.artifactsDir, "artifacts.json"), bz, 0600); err != nil {
return "", errors.Wrap(err, "failed to write artifacts to file")
}

Expand All @@ -276,7 +276,7 @@ func (l *LauncherContext) FinalizeOutput(config *Config) (string, error) {
return "", errors.Wrap(err, "failed to marshal config")
}

if err := os.WriteFile(path.Join(l.artifactsDir, "config.json"), configBz, os.ModePerm); err != nil {
if err := os.WriteFile(path.Join(l.artifactsDir, "config.json"), configBz, 0600); err != nil {
return "", errors.Wrap(err, "failed to write config to file")
}

Expand Down
4 changes: 2 additions & 2 deletions x/opchild/keeper/executor_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func Test_RegisterExecutorChangePlan(t *testing.T) {
_, input := createTestInput(t, false)

// Arguments
l1ProposalID := uint64(rand.Uint64())
height := uint64(rand.Uint64())
l1ProposalID := rand.Uint64()
height := rand.Uint64()
nextValAddr := valAddrsStr[0]
nextExecutorAddr := []string{addrsStr[0], addrsStr[1]}
consensusPubKey := "l7aqGv+Zjbm0rallfqfqz+3iN31iOmgJCafWV5pGs6o="
Expand Down
5 changes: 4 additions & 1 deletion x/opchild/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
}

pendingDeposits := []types.PendingDeposits{}
k.PendingDeposits.Walk(ctx, nil, func(key []byte, value types.CoinsWrapper) (stop bool, err error) {
err = k.PendingDeposits.Walk(ctx, nil, func(key []byte, value types.CoinsWrapper) (stop bool, err error) {
addr, err := k.addressCodec.BytesToString(key)
if err != nil {
return false, err
Expand All @@ -165,6 +165,9 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
})
return false, nil
})
if err != nil {
panic(err)
}

return &types.GenesisState{
Params: params,
Expand Down
8 changes: 4 additions & 4 deletions x/opchild/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func NewKeeper(
}

// GetAuthority returns the x/move module's authority.
func (ak Keeper) GetAuthority() string {
return ak.authority
func (k Keeper) GetAuthority() string {
return k.authority
}

// Logger returns a module-specific logger.
Expand All @@ -139,8 +139,8 @@ func (k Keeper) Logger(ctx context.Context) log.Logger {
}

// Router returns the gov keeper's router
func (keeper Keeper) Router() *baseapp.MsgServiceRouter {
return keeper.router
func (k Keeper) Router() *baseapp.MsgServiceRouter {
return k.router
}

// setDenomMetadata sets an OPinit token's denomination metadata
Expand Down
2 changes: 1 addition & 1 deletion x/opchild/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type AppModuleBasic struct {
cdc codec.Codec
}

func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { //nolint:staticcheck
func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(amino)
}

Expand Down
4 changes: 2 additions & 2 deletions x/opchild/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (msg MsgExecuteMessages) Validate(ac address.Codec) error {
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgExecuteMessages) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return sdktx.UnpackInterfaces(unpacker, m.Messages)
func (msg MsgExecuteMessages) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return sdktx.UnpackInterfaces(unpacker, msg.Messages)
}

/* MsgAddValidator */
Expand Down
4 changes: 2 additions & 2 deletions x/ophost/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func NewKeeper(
}

// GetAuthority returns the x/move module's authority.
func (ak Keeper) GetAuthority() string {
return ak.authority
func (k Keeper) GetAuthority() string {
return k.authority
}

// Logger returns a module-specific logger.
Expand Down
2 changes: 1 addition & 1 deletion x/ophost/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type AppModuleBasic struct {
cdc codec.Codec
}

func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { //nolint:staticcheck
func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(amino)
}

Expand Down

0 comments on commit e1c04bb

Please sign in to comment.