Skip to content

Commit

Permalink
Merge pull request #7 from initia-labs/feat/golangci
Browse files Browse the repository at this point in the history
feat: add golangci
  • Loading branch information
Benzbeeb authored Dec 11, 2024
2 parents 56cfd69 + e79bb8b commit fd65840
Show file tree
Hide file tree
Showing 22 changed files with 760 additions and 676 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/basic-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ on:

jobs:
lint:
env:
GOLANGCI_LINT_VERSION: v1.61.0
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.6"

- name: Check lint
run: go fmt ./...
go-version: ^1.22
- uses: technote-space/get-diff-action@v6.1.2
id: git_diff
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- name: Run golangci-lint
run: make lint
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.6"
go-version: ^1.22

- name: Run unit tests
run: go test -v ./...
18 changes: 9 additions & 9 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.6"
go-version: ^1.22

- name: Check lint
run: go fmt ./...
Expand All @@ -29,11 +29,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.6"
go-version: ^1.22

- name: Run Integration Tests
run: cd tests && go test -v ./...
Expand All @@ -49,11 +49,11 @@ jobs:
goarch: [amd64, arm64]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.6"
go-version: ^1.22

- name: Read enabled flags
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.6"
go-version: ^1.22

- name: Run Integration Tests
run: cd tests && go test -v ./...
2 changes: 1 addition & 1 deletion .github/workflows/on-workflow-end.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
notify-slack:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Get Slack member IDs
id: get-slack-id
Expand Down
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
linters:
disable-all: false
disable:
- thelper
- varnamelen
- tagliatelle
- wrapcheck
- typecheck
errcheck:
exclude-functions:
- fmt:.*
- io/ioutil:^Read.*
- github.com/spf13/cobra:MarkFlagRequired
- github.com/spf13/viper:BindPFlag
linters-settings:
gocyclo:
min-complexity: 11
golint:
min-confidence: 1.1
issues:
exclude:
- composite
- 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated:' # Exclude deprecated ripemd160 warning
run:
tests: false
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ release_version=$(filter-out $@,$(MAKECMDGOALS))

# Version check
check_version:
@if [ "$(GO_SYSTEM_VERSION)" != "$(REQUIRE_GO_VERSION)" ]; then \
@if [ $(shell echo "$(GO_SYSTEM_VERSION) < $(REQUIRE_GO_VERSION)" | bc -l) -eq 1 ]; then \
echo "ERROR: Go version $(REQUIRE_GO_VERSION) is required for Weave."; \
exit 1; \
fi
Expand All @@ -35,6 +35,20 @@ build: check_version $(BUILDDIR)
install: check_version
go install -ldflags "$(LDFLAGS)" .

.PHONY: lint lint-fix

# Run golangci-lint to check code quality
lint: check_version
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint is required but not installed. Install it by following instructions at https://golangci-lint.run/welcome/install/"; exit 1; }
golangci-lint run --out-format=tab --timeout=15m

# Run golangci-lint and automatically fix issues where possible (use with caution)
lint-fix: check_version
@echo "Warning: This will automatically modify your files to fix linting issues"
@read -p "Are you sure you want to continue? [y/N] " -n 1 -r; echo; if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then exit 1; fi
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint is required but not installed. Install it by following instructions at https://golangci-lint.run/welcome/install/"; exit 1; }
golangci-lint run --fix --out-format=tab --timeout=15m

test: check_version
go clean -testcache
go test -v ./...
Expand Down
8 changes: 2 additions & 6 deletions client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const (
)

// GRPCClient defines the logic for making gRPC requests.
type GRPCClient struct {
conn *grpc.ClientConn
}
type GRPCClient struct{}

// NewGRPCClient initializes and returns a new GRPCClient instance.
func NewGRPCClient() *GRPCClient {
Expand All @@ -27,9 +25,7 @@ func NewGRPCClient() *GRPCClient {

// CheckHealth attempts to connect to the server and uses the reflection service to verify the server is up.
func (g *GRPCClient) CheckHealth(serverAddr string) error {
if strings.HasPrefix(serverAddr, "grpc://") {
serverAddr = strings.TrimPrefix(serverAddr, "grpc://")
}
serverAddr = strings.TrimPrefix(serverAddr, "grpc://")

conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/opinit_bots.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Valid options are [executor, challenger] eg. weave opinit-bots stop challenger`,
if err != nil {
return err
}
fmt.Println(fmt.Sprintf("Stopped the OPinit %s bot process.", botName))
fmt.Printf("Stopped the OPinit %s bot process.\n", botName)
return nil
},
}
Expand Down Expand Up @@ -298,7 +298,7 @@ Valid options are [executor, challenger] eg. weave opinit-bots reset challenger`
if err = execCmd.Run(); err != nil {
return fmt.Errorf("failed to reset-db: %v", err)
}
fmt.Println(fmt.Sprintf("Reset the OPinit %[1]s bot database successfully.", botName))
fmt.Printf("Reset the OPinit %s bot database successfully.\n", botName)
return nil
},
}
Expand Down
11 changes: 8 additions & 3 deletions cosmosutils/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@ func addNewKeyToHermes(appName, chainId, mnemonic string) (*KeyInfo, error) {
if err = io.WriteFile(tempMnemonicPath, mnemonic); err != nil {
return nil, fmt.Errorf("failed to write raw tx file: %v", err)
}
defer io.DeleteFile(tempMnemonicPath)

defer func() {
if err := io.DeleteFile(tempMnemonicPath); err != nil {
fmt.Printf("failed to delete temp mnemonic file: %v", err)
}
}()

cmd := exec.Command(appName, "keys", "add", "--chain", chainId, "--mnemonic-file", tempMnemonicPath)

Expand Down Expand Up @@ -370,11 +375,11 @@ func RecoverNewHermesKey(appName, chainId, mnemonic string) (*KeyInfo, error) {
}

func GenerateAndReplaceHermesKey(appName, chainId string) (*KeyInfo, error) {
DeleteWeaveKeyFromHermes(appName, chainId)
_ = DeleteWeaveKeyFromHermes(appName, chainId)
return GenerateAndAddNewHermesKey(appName, chainId)
}

func RecoverAndReplaceHermesKey(appName, chainId, mnemonic string) (*KeyInfo, error) {
DeleteWeaveKeyFromHermes(appName, chainId)
_ = DeleteWeaveKeyFromHermes(appName, chainId)
return RecoverNewHermesKey(appName, chainId, mnemonic)
}
2 changes: 1 addition & 1 deletion models/minitia/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ func (m *DownloadCelestiaBinaryLoading) Update(msg tea.Msg) (tea.Model, tea.Cmd)
state := weavecontext.PushPageAndGetState[LaunchState](m)

if state.downloadedNewCelestiaBinary {
state.weave.PushPreviousResponse(styles.RenderPreviousResponse(styles.NoSeparator, fmt.Sprintf("Celestia binary has been successfully downloaded."), []string{}, ""))
state.weave.PushPreviousResponse(styles.RenderPreviousResponse(styles.NoSeparator, "Celestia binary has been successfully downloaded.", []string{}, ""))
}
model := NewGenerateOrRecoverSystemKeysLoading(weavecontext.SetCurrentState(m.Ctx, state))
return model, model.Init()
Expand Down
6 changes: 5 additions & 1 deletion models/minitia/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ func (lsk *L1SystemKeys) FundAccountsWithGasStation(state *LaunchState) (*FundAc
if err = io.WriteFile(rawTxPath, rawTxContent); err != nil {
return nil, fmt.Errorf("failed to write raw tx file: %v", err)
}
defer io.DeleteFile(rawTxPath)
defer func() {
if err := io.DeleteFile(rawTxPath); err != nil {
fmt.Printf("failed to delete raw tx file: %v", err)
}
}()

signCmd := exec.Command(state.binaryPath, "tx", "sign", rawTxPath, "--from", common.WeaveGasStationKeyName, "--node", state.l1RPC,
"--chain-id", state.l1ChainId, "--keyring-backend", "test", "--output-document", rawTxPath)
Expand Down
4 changes: 2 additions & 2 deletions models/relayer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (m *KeysMnemonicDisplayInput) View() string {

if state.l2KeyMethod == string(L2GenerateKey) {
mnemonicText += styles.RenderMnemonic(
styles.RenderPrompt(fmt.Sprintf("Weave Relayer on L2"), []string{"L2"}, styles.Empty),
styles.RenderPrompt("Weave Relayer on L2", []string{"L2"}, styles.Empty),
state.l2RelayerAddress,
state.l2RelayerMnemonic,
)
Expand Down Expand Up @@ -780,7 +780,7 @@ func NewFundingAmountSelect(ctx context.Context) *FundingAmountSelect {
CannotBack: true,
},
BaseModel: weavecontext.BaseModel{Ctx: ctx, CannotBack: true},
question: fmt.Sprintf("Please select the filling amount option"),
question: "Please select the filling amount option",
}
}

Expand Down
22 changes: 11 additions & 11 deletions service/launchd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ func (j *Launchd) Create(binaryVersion, appHome string) error {
return j.reloadService()
}

func (j *Launchd) unloadService() error {
userHome, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get user home directory: %v", err)
}
unloadCmd := exec.Command("launchctl", "unload", filepath.Join(userHome, fmt.Sprintf("Library/LaunchAgents/%s.plist", j.GetServiceName())))
if err = unloadCmd.Run(); err != nil {
return fmt.Errorf("failed to unload service: %v", err)
}
return nil
}
// func (j *Launchd) unloadService() error {
// userHome, err := os.UserHomeDir()
// if err != nil {
// return fmt.Errorf("failed to get user home directory: %v", err)
// }
// unloadCmd := exec.Command("launchctl", "unload", filepath.Join(userHome, fmt.Sprintf("Library/LaunchAgents/%s.plist", j.GetServiceName())))
// if err = unloadCmd.Run(); err != nil {
// return fmt.Errorf("failed to unload service: %v", err)
// }
// return nil
// }

func (j *Launchd) reloadService() error {
userHome, err := os.UserHomeDir()
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import (
)

var (
pressEnter = InputStep{Msg: tea.KeyMsg{Type: tea.KeyEnter}}
pressSpace = InputStep{Msg: tea.KeyMsg{Type: tea.KeySpace}}
pressTab = InputStep{Msg: tea.KeyMsg{Type: tea.KeyTab}}
pressUp = InputStep{Msg: tea.KeyMsg{Type: tea.KeyUp}}
pressDown = InputStep{Msg: tea.KeyMsg{Type: tea.KeyDown}}
PressEnter = InputStep{Msg: tea.KeyMsg{Type: tea.KeyEnter}}
PressSpace = InputStep{Msg: tea.KeyMsg{Type: tea.KeySpace}}
PressTab = InputStep{Msg: tea.KeyMsg{Type: tea.KeyTab}}
PressUp = InputStep{Msg: tea.KeyMsg{Type: tea.KeyUp}}
PressDown = InputStep{Msg: tea.KeyMsg{Type: tea.KeyDown}}

waitFetching = WaitStep{Check: func() bool {
WaitFetching = WaitStep{Check: func() bool {
time.Sleep(5 * time.Second)
return true
}}
)

func typeText(text string) InputStep {
func TypeText(text string) InputStep {
return InputStep{Msg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(text)}}
}

// waitFor receives waitCondition as a parameter, which should return true if the wait should be over.
func waitFor(waitCondition func() bool) WaitStep {
func WaitFor(waitCondition func() bool) WaitStep {
return WaitStep{Check: waitCondition}
}
55 changes: 0 additions & 55 deletions tests/integration/gas_station_test.go

This file was deleted.

Loading

0 comments on commit fd65840

Please sign in to comment.