Skip to content

Commit

Permalink
Merge branch 'main' into adam/feature/snapshot-service
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed May 16, 2024
2 parents 7f122c5 + 0e6a763 commit 6a85258
Show file tree
Hide file tree
Showing 421 changed files with 8,986 additions and 4,746 deletions.
2 changes: 1 addition & 1 deletion .github/actions/cleanup-stale/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ runs:
password: ${{ inputs.token }}

- name: Delete untagged images with no dependency
uses: Chizkiyahu/delete-untagged-ghcr-action@v3
uses: Chizkiyahu/delete-untagged-ghcr-action@v4
with:
repository: ${{ github.repository }}
repository_owner: ${{ github.repository_owner }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
matrix:
include:
# check support for oldest supported golang version
- name: go1.20
go-version: "~1.20"
- name: go1.22
go-version: "~1.22"
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version || '^1.20' }}
go-version: ${{ matrix.go-version || '^1.22' }}
check-latest: true

- run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checkFormat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true

- name: Check formatting
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true
cache: false

- run: go version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v5
with:
version: latest
args: --timeout=5m
2 changes: 1 addition & 1 deletion .github/workflows/measureMemory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ jobs:
- name: Resolve database
id: db
run: |
if [ "${{ github.event_name != 'workflow_dispatch' || inputs.cql }}" == "true" ]; then
if [ "${{ github.event_name == 'workflow_dispatch' && inputs.cql }}" == "true" ]; then
echo "name=cqldb" >> $GITHUB_OUTPUT
else
echo "name=mongodb" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staticAnalysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true
- run: go version

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

# login to ghcr.io so we can download device/bridge-device package
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run a test
run: |
make ${{ matrix.cmd }} TEST_CHECK_RACE=${{ matrix.checkRace }} \
Expand Down
106 changes: 70 additions & 36 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
run:
skip-dirs:
- dependency
- http-gateway/grpc-websocket-proxy
skip-dirs-use-default: false

linters-settings:
gocyclo:
min-complexity: 15
govet:
# check-shadowing: true
check-shadowing: false
exhaustive:
default-signifies-exhaustive: true
gocyclo:
min-complexity: 15
gomodguard:
blocked:
modules:
Expand All @@ -21,97 +12,129 @@ linters-settings:
gosec:
excludes:
- G402
govet:
enable:
- nilness
- shadow
stylecheck:
go: "1.20"
checks: ["all", "-ST1003"]

linters:
enable:
- asasalint # Check for pass []any as any in variadic func(...any)
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk # Checks for dangerous unicode character sequences
# - bodyclose # checks whether HTTP response body is closed successfully
# - contextcheck # check the function whether use a non-inherited context
- decorder # check declaration order and count of types, constants, variables and functions
# - depguard # Go linter that checks if package imports are in a list of acceptable packages
- bodyclose # Checks whether HTTP response body is closed successfully
# - copyloopvar # Detects places where loop variables are copied
- decorder # Check declaration order and count of types, constants, variables and functions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
# - dupl # Tool for code clone detection
- durationcheck # check for two durations multiplied together
- dupl # Tool for code clone detection
- dupword # A linter that checks for duplicate words in the source code (usually miswritten)
- durationcheck # Check for two durations multiplied together
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
# - exhaustive # check exhaustiveness of enum switch statements
- execinquery # Execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds.
- exportloopref # checks for pointers to enclosing loop variables
# - forbidigo # Forbids identifiers
# - forcetypeassert # finds forced type assertions
- gci # Gci control golang package import order and make it always deterministic.
# - gochecknoglobals # Checks that no globals are present in Go code
# - gochecknoinits # Checks that no init functions are present in Go code
# - gocognit # Computes and checks the cognitive complexity of functions
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid.
- gocognit # Computes and checks the cognitive complexity of functions
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # The most opinionated Go source code linter
# - gocyclo # Computes and checks the cyclomatic complexity of functions
- gocyclo # Computes and checks the cyclomatic complexity of functions
# - godox # Tool for detection of FIXME, TODO and other comment keywords
# - goerr113 # Golang linter to check the errors handling expressions
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
- goheader # Checks is file header matches to pattern
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
- gosec # Inspects source code for security problems
- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase
- gosimple # Linter for Go source code that specializes in simplifying a code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- grouper # An analyzer to analyze expression groups.
- grouper # An analyzer to analyze expression groups
- importas # Enforces consistent import aliases
- ineffassign # Detects when assignments to existing variables are not used
# - intrange # Intrange is a linter to find places where for loops could make use of an integer range
- loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
- mirror # Reports wrong mirror patterns of bytes/strings usage
- misspell # Finds commonly misspelled English words in comments
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
# - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
# - noctx # noctx finds sending http request without context.Context
- nolintlint # Reports ill-formed or insufficient nolint directives
# - paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative.
- prealloc # Finds slice declarations that could potentially be preallocated
- predeclared # find code that shadows one of Go's predeclared identifiers
- protogetter # Reports direct reads from proto message fields when getters should be used.
- revive # golint replacement, finds style mistakes
- reassign # Checks that package variables are not reassigned
- sloglint # Ensure consistent code style when using log/slog
- spancheck # Checks for mistakes with OpenTelemetry/Census spans
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- stylecheck # Stylecheck is a replacement for golint
# - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
# - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- testifylint # Checks usage of github.com/stretchr/testify.
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- unused # Checks Go code for unused constants, variables, functions and types
# - wastedassign # wastedassign finds wasted assignment statements
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
- wastedassign # wastedassign finds wasted assignment statements
- whitespace # Tool for detection of leading and trailing whitespace
disable:
- containedctx # containedctx is a linter that detects struct contained context.Context field
- contextcheck # check the function whether use a non-inherited context
- cyclop # checks function and package cyclomatic complexity
- depguard # Go linter that checks if package imports are in a list of acceptable packages
- exhaustive # Check exhaustiveness of enum switch statements
- exhaustivestruct # Checks if all struct's fields are initialized
- exhaustruct # Checks if all structure fields are initialized.
- forbidigo # Forbids identifiers
- funlen # Tool for detection of long functions
- gochecknoglobals # Checks that no globals are present in Go code
- gochecknoinits # Checks that no init functions are present in Go code
- godot # Check if comments end in a period
- gomnd # An analyzer to detect magic numbers.
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
- inamedparam # Reports interfaces with unnamed method parameters.
- interfacebloat # A linter that checks the number of methods inside an interface
- ireturn # Accept Interfaces, Return Concrete Types
- lll # Reports long lines
- maintidx # maintidx measures the maintainability index of each function.
- makezero # Finds slice declarations with non-zero initial length
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
- nestif # Reports deeply nested if statements
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
- prealloc # Finds slice declarations that could potentially be preallocated
- nonamedreturns # Reports all named returns
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- promlinter # Check Prometheus metrics naming via promlint
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
- tagalign # Check that struct tags are well aligned.
- tagliatelle # Checks the struct tags.
- testableexamples # linter checks if examples are testable (have an expected output)
- testpackage # linter that makes you use a separate _test package
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- varnamelen # checks that the length of a variable's name matches its scope
- wrapcheck # Checks that errors returned from external packages are wrapped
- wsl # Whitespace Linter - Forces you to use empty lines!

issues:
exclude-dirs:
- dependency
- http-gateway/grpc-websocket-proxy
exclude-files:
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
exclude-rules:
- path: _test.go
linters:
Expand All @@ -123,10 +146,6 @@ issues:
- gocognit
- gocyclo
- gosec
- path: tools/nats-server-config-reloader/pkg/natsreloader/natsreloader.go
text: "G404:"
linters:
- gosec
- path: pkg/time/delay.go
text: "G404:"
linters:
Expand All @@ -138,5 +157,20 @@ issues:
text: "SA1019:"
linters:
- staticcheck
- path: grpc-gateway/client/client.go
linters:
- dupword
- path: coap-gateway/service/session.go
linters:
- dupl
- path: grpc-gateway/client/subscription.go
linters:
- dupl
- path: resource-aggregate/events/resourceLinks.*.go|resource-aggregate/client/sync.*.go|resource-aggregate/service/grpcApi.go|resource-aggregate/events/resource.*.go
linters:
- dupl
# Fix found issues (if it's supported by the linter).
# fix: true

run:
go: "1.22"
11 changes: 7 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
"TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB": "1000",
"TEST_MEMORY_COAP_GATEWAY_RESOURCE_DATA_SIZE": "200",
"TEST_COAP_GATEWAY_LOG_LEVEL": "info",
"TEST_COAP_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_COAP_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_RESOURCE_AGGREGATE_LOG_LEVEL": "info",
"TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY": "false",
"TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY": "false",
"TEST_GRPC_GATEWAY_LOG_LEVEL": "info",
"TEST_GRPC_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_GRPC_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_IDENTITY_STORE_LOG_LEVEL": "info",
"TEST_IDENTITY_STORE_LOG_DUMP_BODY": "false",
"TEST_IDENTITY_STORE_LOG_DUMP_BODY": "false",
"TEST_DATABASE": "mongoDB",
"TEST_BRIDGE_DEVICE_CONFIG": "${workspaceFolder}/.tmp/bridge/config-test.yaml",
// "TEST_DEVICE_NAME": "bridged-device-0",
// "TEST_DEVICE_TYPE": "bridged",
// "GODEBUG": "scavtrace=1",
// "TEST_COAP_GATEWAY_UDP_ENABLED": "true",
// "GOMAXPROCS": 1,
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM ubuntu:22.04 AS hub-test
RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends build-essential ca-certificates curl git make patch sudo \
&& apt-get clean \
&& curl -sSL https://get.docker.com/ | sh
# apt: ca-certificates git make sudo
RUN git clone https://github.com/udhos/update-golang.git \
&& cd update-golang \
&& sudo RELEASE=1.20.13 ./update-golang.sh \
&& sudo RELEASE=1.22.3 ./update-golang.sh \
&& ln -s /usr/local/go/bin/go /usr/bin/go
WORKDIR $GOPATH/src/github.com/plgd-dev/hub
COPY go.mod go.sum ./
Expand All @@ -15,9 +16,12 @@ COPY . .
WORKDIR $GOPATH/src/github.com/plgd-dev/hub/tools/cert-tool
RUN go build -o /usr/bin/cert-tool

WORKDIR $GOPATH/src/github.com/plgd-dev/hub
WORKDIR /usr/local/go
# apt: patch
RUN ( cd /usr/local/go && patch -p1 < $GOPATH/src/github.com/plgd-dev/hub/tools/docker/patches/shrink_tls_conn.patch )
RUN ( patch -p1 < "$GOPATH/src/github.com/plgd-dev/hub/tools/docker/patches/shrink_tls_conn.patch" )


WORKDIR $GOPATH/src/github.com/plgd-dev/hub

# RUN go mod tidy

Expand Down
Loading

0 comments on commit 6a85258

Please sign in to comment.