diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1e68185..5bedff1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -47,6 +47,34 @@ jobs: name: unit-test path: /tmp/unit/ + linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # ratchet:actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Install Dependencies + run: | + sudo apt update + sudo apt install -y clang + sudo apt install -y libbpf-dev + sudo apt install -y libseccomp-dev + + - name: Build coverage-instrumented binary + run: | + make build-static-libbpfgo + make build-bpf + + - name: Golangci-lint + uses: golangci/golangci-lint-action@v6.1.0 + with: + # TODO: find a way to pass this the same way we pass it to go test + args: internal/analyzer internal/archiver internal/elfreader internal/embeddable internal/executor internal/metadata internal/privileged internal/seccomputils internal/writer + integration-test: runs-on: ubuntu-latest @@ -76,7 +104,7 @@ jobs: mkdir -p /tmp/integration # we have to run integration tests one-by-one # otherwhise they will run in parallel. - # since harpoon apply network forwards, these could + # since harpoon apply network forwards, these could # interact with each other and make the test fail. go test \ -exec sudo \ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..1632031 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,164 @@ +--- +# golangci-lint configuration file made by @ccoVeille +# Source: https://github.com/ccoVeille/golangci-lint-config-examples/ +# Author: @ccoVeille +# License: MIT +# +issues: + # Maximum issues count per one linter. + # Set to 0 to disable the limit (Default: 50) + max-issues-per-linter: 0 + # Maximum count of issues with the same text. + # Set to 0 to disable the limit (Default: 3) + max-same-issues: 0 + +run: + # Exit code when at least one issue was found (Default: 1) + # Using 0 allow to report all issues, without blocking the CI + issues-exit-code: 0 + +linters: + # some linters are enabled by default + # https://golangci-lint.run/usage/linters/ + # + # enable some extra linters + enable: + # Errcheck is a program for checking for unchecked errors in Go code. + - errcheck + + # Linter for Go source code that specializes in simplifying code. + - gosimple + + # Vet examines Go source code and reports suspicious constructs. + - govet + + # Detects when assignments to existing variables are not used. + - ineffassign + + # It's a set of rules from staticcheck. See https://staticcheck.io/ + - staticcheck + + # Fast, configurable, extensible, flexible, and beautiful linter for Go. + # Drop-in replacement of golint. + - revive + + # check imports order and makes it always deterministic. + - gci + + # make sure to use t.Helper() when needed + - thelper + + # mirror suggests rewrites to avoid unnecessary []byte/string conversion + - mirror + + # detect the possibility to use variables/constants from the Go standard library. + - usestdlibvars + + # Detects common programming mistakes. + - errorlint + + # Finds commonly misspelled English words. + - misspell + + # Checks for duplicate words in the source code. + - dupword + + # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced + - errorlint + +linters-settings: + gci: # define the section orders for imports + sections: + # Standard section: captures all standard packages. + - standard + # Default section: catchall that is not standard or custom + - default + # linters that related to local tool, so they should be separated + - localmodule + + revive: + rules: + # these are the default revive rules + # you can remove the whole "rules" node if you want + # BUT + # ! /!\ they all need to be present when you want to add more rules than the default ones + # otherwise, you won't have the default rules, but only the ones you define in the "rules" node + + # Blank import should be only in a main or test package, or have a comment justifying it. + - name: blank-imports + + # context.Context() should be the first parameter of a function when provided as argument. + - name: context-as-argument + arguments: + - allowTypesBefore: "*testing.T" + + # Basic types should not be used as a key in `context.WithValue` + - name: context-keys-type + + # Importing with `.` makes the programs much harder to understand + - name: dot-imports + + # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-block + + # for better readability, variables of type `error` must be named with the prefix `err`. + - name: error-naming + + # for better readability, the errors should be last in the list of returned values by a function. + - name: error-return + + # for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: error-strings + + # report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible + - name: errorf + + # incrementing an integer variable by 1 is recommended to be done using the `++` operator + - name: increment-decrement + + # highlights redundant else-blocks that can be eliminated from the code + - name: indent-error-flow + + # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: range + + # receiver names in a method should reflect the struct name (p for Person, for example) + - name: receiver-naming + + # redefining built in names (true, false, append, make) can lead to bugs very difficult to detect. + - name: redefines-builtin-id + + # redundant else-blocks that can be eliminated from the code. + - name: superfluous-else + + # prevent confusing name for variables when using `time` package + - name: time-naming + + # warns when an exported function or method returns a value of an un-exported type. + - name: unexported-return + + # spots and proposes to remove unreachable code. also helps to spot errors + - name: unreachable-code + + # Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug. + - name: unused-parameter + + # report when a variable declaration can be simplified + - name: var-declaration + + # warns when initialism, variable or package naming conventions are not followed. + - name: var-naming + + - name: comment-spacings + + - name: unhandled-error + + dupword: + # Keywords used to ignore detection. + # Default: [] + ignore: + # - "blah" # this will accept "blah blah …" as a valid duplicate word + + misspell: + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US