From 1f5224b74be5b2e24f1e2263f5800d739211ab7f Mon Sep 17 00:00:00 2001 From: blotus Date: Fri, 26 Aug 2022 13:31:49 +0200 Subject: [PATCH] switch to go 1.19 (#1709) --- .github/workflows/bats-hub.yml | 8 ++--- .github/workflows/bats-mysql.yml | 8 ++--- .github/workflows/bats-postgres.yml | 8 ++--- .github/workflows/bats-sqlite-coverage.yml | 8 ++--- .github/workflows/ci-windows-build-msi.yml | 4 +-- .../workflows/ci_golangci-lint-windows.yml | 31 ------------------- .github/workflows/ci_golangci-lint.yml | 9 ++++-- .github/workflows/go-tests-windows.yml | 4 +-- .github/workflows/go-tests.yml | 4 +-- .github/workflows/release_publish-package.yml | 8 ++--- Dockerfile | 2 +- Dockerfile.debian | 2 +- azure-pipelines.yml | 4 +-- go.mod | 2 +- pkg/acquisition/acquisition_test.go | 10 +++--- .../modules/journalctl/journalctl_test.go | 5 ++- pkg/csplugin/broker_win_test.go | 2 +- 17 files changed, 46 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/ci_golangci-lint-windows.yml diff --git a/.github/workflows/bats-hub.yml b/.github/workflows/bats-hub.yml index cd5507d6d..79e1afc5e 100644 --- a/.github/workflows/bats-hub.yml +++ b/.github/workflows/bats-hub.yml @@ -23,10 +23,10 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.17" + - name: "Set up Go 1.19" uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: "Clone CrowdSec" @@ -39,8 +39,8 @@ jobs: run: | sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential daemonize jq netcat-openbsd go install github.com/mikefarah/yq/v4@latest - go install github.com/cloudflare/cfssl/cmd/cfssl@latest - go install github.com/cloudflare/cfssl/cmd/cfssljson@latest + go install github.com/cloudflare/cfssl/cmd/cfssl@master + go install github.com/cloudflare/cfssl/cmd/cfssljson@master sudo cp -u ~/go/bin/yq /usr/local/bin/ sudo cp -u ~/go/bin/cfssl /usr/local/bin sudo cp -u ~/go/bin/cfssljson /usr/local/bin diff --git a/.github/workflows/bats-mysql.yml b/.github/workflows/bats-mysql.yml index 5172b1c93..90e393919 100644 --- a/.github/workflows/bats-mysql.yml +++ b/.github/workflows/bats-mysql.yml @@ -34,10 +34,10 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.17" + - name: "Set up Go 1.19" uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: "Check out CrowdSec repository" @@ -50,8 +50,8 @@ jobs: run: | sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential daemonize jq netcat-openbsd go install github.com/mikefarah/yq/v4@latest - go install github.com/cloudflare/cfssl/cmd/cfssl@latest - go install github.com/cloudflare/cfssl/cmd/cfssljson@latest + go install github.com/cloudflare/cfssl/cmd/cfssl@master + go install github.com/cloudflare/cfssl/cmd/cfssljson@master sudo cp -u ~/go/bin/yq ~/go/bin/cfssl ~/go/bin/cfssljson /usr/local/bin/ - name: "Build crowdsec and fixture" diff --git a/.github/workflows/bats-postgres.yml b/.github/workflows/bats-postgres.yml index a7fa6e0ee..93282594c 100644 --- a/.github/workflows/bats-postgres.yml +++ b/.github/workflows/bats-postgres.yml @@ -35,10 +35,10 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.17" + - name: "Set up Go 1.19" uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: "Check out CrowdSec repository" @@ -51,8 +51,8 @@ jobs: run: | sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential daemonize jq netcat-openbsd go install github.com/mikefarah/yq/v4@latest - go install github.com/cloudflare/cfssl/cmd/cfssl@latest - go install github.com/cloudflare/cfssl/cmd/cfssljson@latest + go install github.com/cloudflare/cfssl/cmd/cfssl@master + go install github.com/cloudflare/cfssl/cmd/cfssljson@master sudo cp -u ~/go/bin/yq ~/go/bin/cfssl ~/go/bin/cfssljson /usr/local/bin/ - name: "Build crowdsec and fixture (DB_BACKEND: pgx)" diff --git a/.github/workflows/bats-sqlite-coverage.yml b/.github/workflows/bats-sqlite-coverage.yml index c2217f25b..af8271cce 100644 --- a/.github/workflows/bats-sqlite-coverage.yml +++ b/.github/workflows/bats-sqlite-coverage.yml @@ -21,10 +21,10 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.17" + - name: "Set up Go 1.19" uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: "Check out CrowdSec repository" @@ -37,8 +37,8 @@ jobs: run: | sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential daemonize jq netcat-openbsd go install github.com/mikefarah/yq/v4@latest - go install github.com/cloudflare/cfssl/cmd/cfssl@latest - go install github.com/cloudflare/cfssl/cmd/cfssljson@latest + go install github.com/cloudflare/cfssl/cmd/cfssl@master + go install github.com/cloudflare/cfssl/cmd/cfssljson@master sudo cp -u ~/go/bin/yq ~/go/bin/cfssl ~/go/bin/cfssljson /usr/local/bin/ go install github.com/wadey/gocovmerge@latest sudo cp -u ~/go/bin/gocovmerge /usr/local/bin/ diff --git a/.github/workflows/ci-windows-build-msi.yml b/.github/workflows/ci-windows-build-msi.yml index 913662724..cdb93ecf8 100644 --- a/.github/workflows/ci-windows-build-msi.yml +++ b/.github/workflows/ci-windows-build-msi.yml @@ -14,10 +14,10 @@ jobs: name: Build runs-on: windows-2019 steps: - - name: Set up Go 1.17 + - name: Set up Go 1.19 uses: actions/setup-go@v1 with: - go-version: 1.17 + go-version: 1.19 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 diff --git a/.github/workflows/ci_golangci-lint-windows.yml b/.github/workflows/ci_golangci-lint-windows.yml deleted file mode 100644 index 2dccbf44b..000000000 --- a/.github/workflows/ci_golangci-lint-windows.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: golangci-lint (windows) - -on: - push: - tags: - - v* - branches: - - master - paths-ignore: - - 'docs/**' - - 'mkdocs.yml' - - 'README.md' - pull_request: - paths-ignore: - - 'docs/**' - - 'mkdocs.yml' - - 'README.md' -jobs: - golangci: - name: lint - runs-on: windows-2022 - steps: - - uses: actions/checkout@v3 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.48 - # Optional: golangci-lint command line arguments. - args: --issues-exit-code=0 --timeout 10m - only-new-issues: true diff --git a/.github/workflows/ci_golangci-lint.yml b/.github/workflows/ci_golangci-lint.yml index 32e9791e3..97585a3d9 100644 --- a/.github/workflows/ci_golangci-lint.yml +++ b/.github/workflows/ci_golangci-lint.yml @@ -1,4 +1,4 @@ -name: golangci-lint (linux) +name: golangci-lint on: push: @@ -17,8 +17,11 @@ on: - 'README.md' jobs: golangci: + strategy: + matrix: + os: [ubuntu-latest, windows-2022] name: lint - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: golangci-lint @@ -27,7 +30,7 @@ jobs: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: v1.48 # Optional: golangci-lint command line arguments. - args: --issues-exit-code=1 --timeout 5m + args: --issues-exit-code=1 --timeout 10m # Optional: show only new issues if it's a pull request. The default value is `false`. only-new-issues: false # Optional: if set to true then the all caching functionality will be complete disabled, diff --git a/.github/workflows/go-tests-windows.yml b/.github/workflows/go-tests-windows.yml index d62e3f44d..618b79e80 100644 --- a/.github/workflows/go-tests-windows.yml +++ b/.github/workflows/go-tests-windows.yml @@ -21,10 +21,10 @@ jobs: steps: - - name: "Set up Go 1.17" + - name: "Set up Go 1.19" uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: Check out CrowdSec repository diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 425251e01..cdfc3af01 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -58,10 +58,10 @@ jobs: steps: - - name: "Set up Go 1.17" + - name: "Set up Go 1.19" uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: Check out CrowdSec repository diff --git a/.github/workflows/release_publish-package.yml b/.github/workflows/release_publish-package.yml index 5c5452672..2a3bb42cd 100644 --- a/.github/workflows/release_publish-package.yml +++ b/.github/workflows/release_publish-package.yml @@ -10,10 +10,10 @@ jobs: name: Build and upload binary package runs-on: ubuntu-latest steps: - - name: Set up Go 1.17 + - name: Set up Go 1.19 uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.19 id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 @@ -29,10 +29,10 @@ jobs: name: Build and upload binary package runs-on: ubuntu-latest steps: - - name: Set up Go 1.17 + - name: Set up Go 1.19 uses: actions/setup-go@v1 with: - go-version: 1.17 + go-version: 1.19 id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 diff --git a/Dockerfile b/Dockerfile index 2342c4580..900529a42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG GOVERSION=1.17 +ARG GOVERSION=1.19 FROM golang:${GOVERSION}-alpine AS build diff --git a/Dockerfile.debian b/Dockerfile.debian index 544d20ac6..cd962c914 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -1,4 +1,4 @@ -ARG GOVERSION=1.17 +ARG GOVERSION=1.19 FROM golang:${GOVERSION}-bullseye AS build diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 63f335f0e..d863a009c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,9 +25,9 @@ stages: custom: 'tool' arguments: 'install --global SignClient --version 1.3.155' - task: GoTool@0 - displayName: "Install Go 1.17" + displayName: "Install Go 1.19" inputs: - version: '1.17.9' + version: '1.19' - pwsh: | choco install -y jq diff --git a/go.mod b/go.mod index 15f57aa4a..6ce66ac5f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/crowdsecurity/crowdsec -go 1.17 +go 1.19 require ( entgo.io/ent v0.10.1 diff --git a/pkg/acquisition/acquisition_test.go b/pkg/acquisition/acquisition_test.go index d18995fc4..7344fcb82 100644 --- a/pkg/acquisition/acquisition_test.go +++ b/pkg/acquisition/acquisition_test.go @@ -52,7 +52,7 @@ func (f *MockSource) ConfigureByDSN(string, map[string]string, *log.Entry) error return fmt.Errorf("not supported") } -//copy the mocksource, but this one can't run +// copy the mocksource, but this one can't run type MockSourceCantRun struct { MockSource } @@ -60,7 +60,7 @@ type MockSourceCantRun struct { func (f *MockSourceCantRun) CanRun() error { return fmt.Errorf("can't run bro") } func (f *MockSourceCantRun) GetName() string { return "mock_cant_run" } -//appendMockSource is only used to add mock source for tests +// appendMockSource is only used to add mock source for tests func appendMockSource() { if GetDataSourceIface("mock") == nil { mock := struct { @@ -445,7 +445,6 @@ READLOOP: } } -// type MockTailError struct { MockTail } @@ -493,11 +492,10 @@ READLOOP: } } -//nolint: structcheck,unused type MockSourceByDSN struct { configuration.DataSourceCommonCfg `yaml:",inline"` - Toto string `yaml:"toto"` - logger *log.Entry + Toto string `yaml:"toto"` + logger *log.Entry //nolint: unused } func (f *MockSourceByDSN) Configure(cfg []byte, logger *log.Entry) error { return nil } diff --git a/pkg/acquisition/modules/journalctl/journalctl_test.go b/pkg/acquisition/modules/journalctl/journalctl_test.go index a73aad9ab..5511a01e3 100644 --- a/pkg/acquisition/modules/journalctl/journalctl_test.go +++ b/pkg/acquisition/modules/journalctl/journalctl_test.go @@ -3,6 +3,7 @@ package journalctlacquisition import ( "os" "os/exec" + "path/filepath" "runtime" "testing" "time" @@ -279,7 +280,9 @@ journalctl_filter: func TestMain(m *testing.M) { if os.Getenv("USE_SYSTEM_JOURNALCTL") == "" { - os.Setenv("PATH", "./test_files"+":"+os.Getenv("PATH")) + currentDir, _ := os.Getwd() + fullPath := filepath.Join(currentDir, "test_files") + os.Setenv("PATH", fullPath+":"+os.Getenv("PATH")) } os.Exit(m.Run()) } diff --git a/pkg/csplugin/broker_win_test.go b/pkg/csplugin/broker_win_test.go index 395daaffd..46899c67d 100644 --- a/pkg/csplugin/broker_win_test.go +++ b/pkg/csplugin/broker_win_test.go @@ -20,7 +20,7 @@ import ( ) /* -Due to the complexity of file permission modification with go on windows, we only test the basic behaviour the broker, +Due to the complexity of file permission modification with go on windows, we only test the basic behavior the broker, not if it will actually reject plugins with invalid permissions */