Skip to content

Commit

Permalink
Adds Go Linter (#32)
Browse files Browse the repository at this point in the history
* Adds script to help install golangci-lint locally

* Adds lint command and fixes lint issues

* Add go lint ci job
  • Loading branch information
nitaliano authored Jul 8, 2024
1 parent 88124b9 commit a209230
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ jobs:
just test-contracts
id: test

go-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59

- name: Install dependencies
run: go mod download

- name: Run linter
run: just lint-go

go-tests:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ build-contracts:
build-go:
go build ./...

lint-go:
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./...

test-contracts:
forge test -vvv --root ./contracts

Expand Down
6 changes: 3 additions & 3 deletions anvil/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ func (a *Anvil) Start(ctx context.Context) error {

tempFile, err := os.CreateTemp("", "genesis-*.json")
if err != nil {
return fmt.Errorf("Error creating temporary genesis file: %v", err)
return fmt.Errorf("Error creating temporary genesis file: %w", err)
}
defer os.Remove(tempFile.Name())

_, err = tempFile.Write(a.cfg.Genesis)
if err != nil {
return fmt.Errorf("Error writing to genesis file: %v", err)
return fmt.Errorf("Error writing to genesis file: %w", err)
}

// Prep args
args := []string{
"--host", host,
"--chain-id", fmt.Sprintf("%d", a.cfg.ChainId),
"--port", fmt.Sprintf("%d", a.cfg.Port),
"--init", fmt.Sprintf("%s", tempFile.Name()),
"--init", tempFile.Name(),
}

a.cmd = exec.CommandContext(a.resourceCtx, "anvil", args...)
Expand Down
13 changes: 13 additions & 0 deletions scripts/local-dev-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ if ! command -v just > /dev/null 2>&1; then
else
echo "skipping just install, it already exists."
fi

##################
# Go Setup #
##################

echo "Checking go setup"

if ! command -v golangci-lint > /dev/null 2>&1; then
# binary will be $(go env GOPATH)/bin/golangci-lint
echo "Instaling golangci-lint"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
golangci-lint --version
fi
10 changes: 8 additions & 2 deletions supersim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ const (
func TestGenesisState(t *testing.T) {
logger := oplog.NewLogger(os.Stderr, oplog.DefaultCLIConfig())
supersim := NewSupersim(logger, &DefaultConfig)
supersim.Start(context.Background())
defer supersim.Stop(context.Background())
_ = supersim.Start(context.Background())

defer func() {
err := supersim.Stop(context.Background())
if err != nil {
t.Fatalf("Failed to stop supersim: %v", err)
}
}()

for _, l2ChainConfig := range DefaultConfig.l2Chains {
client, err := utils.WaitForAnvilClientToBeReady(fmt.Sprintf("http://127.0.0.1:%d", l2ChainConfig.Port), anvilClientTimeout)
Expand Down
3 changes: 2 additions & 1 deletion utils/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ func WaitForAnvilClientToBeReady(rpcUrl string, timeout time.Duration) (*rpc.Cli
case <-ctx.Done():
return nil, fmt.Errorf("timed out waiting for response from %s", rpcUrl)
case <-ticker.C:
_, err := http.Get(rpcUrl)
res, err := http.Get(rpcUrl)

if err != nil {
fmt.Printf("Error making request: %v\n", err)
continue
}
defer res.Body.Close()

client, err := rpc.Dial(rpcUrl)
if err != nil {
Expand Down

0 comments on commit a209230

Please sign in to comment.