Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add linters #402

Merged
merged 10 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
KNUU_TIMEOUT=60m # The timeout for the tests
# NOTE: this file should only contain generic environment variables as it is
# currently part of the git history.

KNUU_TIMEOUT=60m # The timeout for the tests
KNUU_BUILDER=docker # The builder to use for building images. docker or kubernetes
LOG_LEVEL=info # The debug level. debug, info, warn, error
LOG_LEVEL=info # The debug level. debug, info, warn, error
5 changes: 2 additions & 3 deletions .github/workflows/knuu_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: Knuu Testing

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
workflow_dispatch:

jobs:
test:

runs-on: ubuntu-latest

steps:
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Lint
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
merge_group:

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22.1
# This steps sets the GIT_DIFF environment variable to true
# if files defined in PATTERS changed
- uses: technote-space/get-diff-action@v6.1.2
with:
# This job will pass without running if go.mod, go.sum, and *.go
# wasn't modified.
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: golangci/golangci-lint-action@v6.0.1
with:
version: latest
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF

yamllint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: celestiaorg/.github/.github/actions/yamllint@v0.4.1

markdown-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: celestiaorg/.github/.github/actions/markdown-lint@v0.4.1

govulncheck:
runs-on: ubuntu-latest
name: Run govulncheck
steps:
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.22.1
go-package: ./...
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage.txt
.vscode/launch.json
*/**.html
*.idea
46 changes: 46 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
run:
timeout: 5m
modules-download-mode: readonly

linters:
disable:
# TODO: there are tons of errors for these, we need to handle in a separate PR
- errorlint
- errcheck
- gosec
enable:
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- typecheck
- unconvert
- unused

issues:
exclude-use-default: false
include:
- EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments
- EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments
exclude:
- SA1019 # TODO enable: SA 1019 staticcheck: this is being triggered by the refactor and all the deprecated code. We need to enable this once we make the breaking change official

linters-settings:
revive:
rules:
- name: package-comments
disabled: true
- name: duplicated-imports
severity: warning
- name: exported
disabled: true
# Leaving for reference if we can enable in the future.
# arguments:
# - disableStutteringCheck

goimports:
local-prefixes: github.com/celestiaorg
6 changes: 6 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default: true
MD010: false
MD013: false
MD041: false
MD024:
allow_different_nesting: true
9 changes: 9 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html
extends: default

rules:
# 120 chars should be enough, but don't fail if a line is longer
line-length:
max: 120
level: warning
53 changes: 27 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,49 @@ If you are new to Knuu, please go through the [README](./README.md) to familiari

- Have a suggestion you want to implement? Open an issue, then create a Pull Request with your implementation.

- Want to resolve an issue in the repo, make a request to be assigned, and be sure to tag the issue in your PR!.
- Want to resolve an issue in the repo, make a request to be assigned, and be sure to tag the issue in your PR!

## Contribution Workflow

To contribute to Knuu, follow these steps:

1. Fork the repository: Click on the 'Fork' button at the top right of this page. This will create a copy of the repository in your GitHub account.

2. Clone the forked repository to your local machine. Open your terminal and run:

```bash
git clone <forked-repository-url>
```
1. Clone the forked repository to your local machine. Open your terminal and run:

3. Create your working branch: In the project directory, create a new branch by running the following command in your terminal:
```bash
git clone <forked-repository-url>
```

```bash
git checkout -b working-branch
```
Be sure to name your branch according to the changes you are making.
For example: `add-missing-tests`.
1. Create your working branch: In the project directory, create a new branch by running the following command in your terminal:

4. Make your changes: Do not address multiple issues per PR.
For example, if you are adding a feature, it should not have bug fixes too. This is to enable the maintainers review your PR efficiently.
```bash
git checkout -b working-branch
```

5. Commit the changes to your branch: After making the desired changes to the repo, run the following commands to commit them:
Be sure to name your branch according to the changes you are making.
For example: `add-missing-tests`.

```bash
git add .
```
1. Make your changes: Do not address multiple issues per PR.
For example, if you are adding a feature, it should not have bug fixes too. This is to enable the maintainers review your PR efficiently.
MSevey marked this conversation as resolved.
Show resolved Hide resolved

```bash
git commit -m "add an appropriate commit message"
```
1. Commit the changes to your branch: After making the desired changes to the repo, run the following commands to commit them:

```bash
git push origin <working-branch>
```
```bash
git add .
```

To ensure that your contribution is working as expected, please run `knuu-example` with your fork and working branch.
```bash
git commit -m "add an appropriate commit message"
```

5. Create a Pull Request: Go to your forked repository on GitHub, and be sure that you are in the branch you pushed the changes to. Click on the 'Compare & pull request' button. This will open a new page where you can create your PR. Fill in the description field and click on 'Create pull request'.
```bash
git push origin <working-branch>
```

To ensure that your contribution is working as expected, please run `knuu-example` with your fork and working branch.

1. Create a Pull Request: Go to your forked repository on GitHub, and be sure that you are in the branch you pushed the changes to. Click on the 'Compare & pull request' button. This will open a new page where you can create your PR. Fill in the description field and click on 'Create pull request'.
MSevey marked this conversation as resolved.
Show resolved Hide resolved
Be sure to name your PR with a semantic prefix. For example, if it is a fix, it should be specified with the `fix:` prefix.

Congratulations! You have successfully made a Pull Request, and your changes will be reviewed by the maintainers.
File renamed without changes.
58 changes: 57 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,62 @@ pkgs := $(shell go list ./...)
run := .
count := 1

test:
## help: Show this help message
help: Makefile
@echo " Choose a command run in "$(PROJECTNAME)":"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
.PHONY: help

## clean: clean testcache
clean:
@echo "--> Clearing testcache"
@go clean --testcache
@rm coverage.txt
.PHONY: clean

## cover: generate to code coverage report.
cover:
@echo "--> Generating Code Coverage"
@go install github.com/ory/go-acc@latest
@go-acc -o coverage.txt $(pkgs)
.PHONY: cover

## deps: Install dependencies
deps:
@echo "--> Installing dependencies"
@go mod download
@go mod tidy
.PHONY: deps

## lint: Run linters golangci-lint and markdownlint.
lint: vet
@echo "--> Running markdownlint"
@markdownlint --config .markdownlint.yaml '**/*.md'
@echo "--> Running yamllint"
@yamllint --no-warnings . -c .yamllint.yml
@echo "--> Running actionlint"
@actionlint
@echo "--> Running govulncheck"
@govulncheck ./...
@echo "--> Running golangci-lint"
@golangci-lint run
.PHONY: lint

## fmt: Run fixes for linters.
fmt:
@echo "--> Formatting markdownlint"
@markdownlint --config .markdownlint.yaml '**/*.md' -f
@echo "--> Formatting go"
@golangci-lint run --fix
.PHONY: fmt

## vet: Run go vet
vet:
@echo "--> Running go vet"
@go vet $(pkgs)
.PHONY: vet

## test: Run the testsuite
test: vet
KNUU_TIMEOUT=120m go test -v $(pkgs) -run $(run) -count=$(count) -timeout 120m
.PHONY: test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ In the folder `e2e`, you will find some examples of how to use the [knuu](https:

## Write Tests

You can find the relevant documentation in the `pkg/knuu` package at: https://pkg.go.dev/github.com/celestiaorg/knuu
You can find the relevant documentation in the `pkg/knuu` package at: <https://pkg.go.dev/github.com/celestiaorg/knuu>

## Run

Expand Down Expand Up @@ -256,7 +256,7 @@ See [SECURITY.md](SECURITY.md) for security and disclosure information.

## Licensing

Knuu is licensed under the [Apache License 2.0](LICENSE).
Knuu is licensed under the [Apache License 2.0](./LICENSE).

<!---
## Contact
Expand Down
22 changes: 11 additions & 11 deletions docs/architecture/adr-001-redesign-knuu-async-approach.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ Node Configuration:
Playbook setup:

- **After reaching height 10**:
- Adjust the bandwidth of **15%** of Validators to **10Mbps**.
- Introduce a 50ms latency to **30%** of Light DA Nodes.
- Add a 20ms jitter to **25%** of Full DA Nodes.
- Adjust the bandwidth of **15%** of Validators to **10Mbps**.
- Introduce a 50ms latency to **30%** of Light DA Nodes.
- Add a 20ms jitter to **25%** of Full DA Nodes.

- **Test Duration**:
- Keep the test running until height **10,000**
- or **30 minutes**, ensuring comprehensive evaluation.
- Keep the test running until height **10,000**
- or **30 minutes**, ensuring comprehensive evaluation.

- **Metrics collection**
- Configured traffic shape on each node
- Error logs of each node
- Time to complete the sync of DA nodes
- Number of missing blocks to sign
- Number of missing blocks to propose
- ...
- Configured traffic shape on each node
- Error logs of each node
- Time to complete the sync of DA nodes
- Number of missing blocks to sign
- Number of missing blocks to propose
- ...

Each worker node receives this playbook and based on that decides what to do.
The entire playbook could be written in a golang code just like what Testground does.
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/file_test_image_cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFileCached(t *testing.T) {
// adding the folder after the Commit, it will help us to use a cached image.
err = instance.AddFile("resources/html/index.html", "/usr/share/nginx/html/index.html", "0:0")
if err != nil {
t.Fatalf("Error adding file to '%v': %v", instanceName, err)
t.Errorf("Error adding file to '%v': %v", instanceName, err)
}
}(i, instance)
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/basic/files_to_volumes_cm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestNoVolumesNoFiles(t *testing.T) {
t.Fatalf("Error creating executor: %v", err)
}

instanceName := fmt.Sprintf("web-1")
instanceName := "web-1"
instance, err := knuu.NewInstance(instanceName)
if err != nil {
t.Fatalf("Error creating instance '%v': %v", instanceName, err)
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestOneVolumeNoFiles(t *testing.T) {
t.Fatalf("Error creating executor: %v", err)
}

instanceName := fmt.Sprintf("web-1")
instanceName := "web-1"
instance, err := knuu.NewInstance(instanceName)
if err != nil {
t.Fatalf("Error creating instance '%v': %v", instanceName, err)
Expand Down
3 changes: 2 additions & 1 deletion e2e/basic/folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package basic
import (
"testing"

"github.com/celestiaorg/knuu/pkg/knuu"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/knuu/pkg/knuu"
)

func TestFolder(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/folder_test_image_cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestFolderCached(t *testing.T) {
// adding the folder after the Commit, it will help us to use a cached image.
err := instance.AddFolder("resources/html", "/usr/share/nginx/html", "0:0")
if err != nil {
t.Fatalf("Error adding file to '%v': %v", instanceName, err)
t.Errorf("Error adding file to '%v': %v", instanceName, err)
}
}(i, instance)
}
Expand Down
Loading
Loading