diff --git a/.github/workflows/govuln.yaml b/.github/workflows/govuln.yaml index 942058be..28d078fd 100644 --- a/.github/workflows/govuln.yaml +++ b/.github/workflows/govuln.yaml @@ -19,4 +19,4 @@ jobs: - run: | set -euo pipefail - go install golang.org/x/vuln/cmd/govulncheck@latest && govulncheck ./... + make vulncheck diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..09fac7ca --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,60 @@ +--- +name: Static analysis +on: + push: + branches: + - main + tags: + - v* + pull_request: +permissions: read-all +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 + with: + go-version: 1.22.6 + - name: golangci-lint + uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0 + with: + version: v1.60.3 + args: --config tools/.golangci.yaml + - run: | + set -euo pipefail + + make vet + - run: | + set -euo pipefail + + make lint + - run: | + set -euo pipefail + + make fmt + + DIFF=$(git status --porcelain) + + if [ -n "$DIFF" ]; then + echo "These files were modified:" + echo + echo "$DIFF" + echo + exit 1 + fi + - run: | + set -euo pipefail + + DIFF=$(git status --porcelain) + + make generate manifests + + if [ -n "$DIFF" ]; then + echo "These files were modified:" + echo + echo "$DIFF" + echo + echo "Please run make generate manifests and commit the changes." + exit 1 + fi diff --git a/Makefile b/Makefile index 28284aa9..cf20441f 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ GO_PACKAGE_NAME_GOLANGCI_LINT := golangci-lint install-$(GO_PACKAGE_NAME_GOLANGCI_LINT): @if [ ! -x "$(GOBIN)/$(GO_PACKAGE_NAME_GOLANGCI_LINT)" ]; then \ echo "Installing $(GO_PACKAGE_NAME_GOLANGCI_LINT)..." ; \ - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.57.2 ; \ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.60.3 ; \ else \ echo "$(GO_PACKAGE_NAME_GOLANGCI_LINT) is installed" ; \ fi diff --git a/internal/controller/expected_netboxmock_calls_test.go b/internal/controller/expected_netboxmock_calls_test.go index 9d67d8c8..e4b51acf 100644 --- a/internal/controller/expected_netboxmock_calls_test.go +++ b/internal/controller/expected_netboxmock_calls_test.go @@ -1,5 +1,5 @@ /* -Copyright 2024. +Copyright 2024 Swisscom (Schweiz) AG. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/internal/controller/netbox_testdata_test.go b/internal/controller/netbox_testdata_test.go index 22308da1..83a11704 100644 --- a/internal/controller/netbox_testdata_test.go +++ b/internal/controller/netbox_testdata_test.go @@ -1,5 +1,5 @@ /* -Copyright 2024. +Copyright 2024 Swisscom (Schweiz) AG. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index 82b7db04..8d66a362 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -60,7 +60,6 @@ var ipamMockIpAddressClaim *mock_interfaces.MockIpamInterface var tenancyMock *mock_interfaces.MockTenancyInterface var ctx context.Context var cancel context.CancelFunc -var netboxClient *api.NetboxClient func TestControllers(t *testing.T) { RegisterFailHandler(Fail) diff --git a/pkg/config/config.go b/pkg/config/config.go index 475c9823..52f954f7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -96,9 +96,8 @@ func GetOperatorConfig() *OperatorConfig { func GetProtocol() string { if GetOperatorConfig().HttpsEnable { return "https" - } else { - return "http" } + return "http" } func GetBaseUrl() string { diff --git a/tools/.golangci.yaml b/tools/.golangci.yaml index e12fa1c9..d45230ae 100644 --- a/tools/.golangci.yaml +++ b/tools/.golangci.yaml @@ -5,9 +5,6 @@ issues: max-same-issues: 0 exclude-files: - ^zz_generated.* - - test/ - - pkg/leaselocker/ - - internal/controller/suite_test.go linters: disable-all: true enable: @@ -85,6 +82,3 @@ linters-settings: - name: error-strings severity: error disabled: false - # https://golangci-lint.run/usage/linters/#goheader - goheader: - template-path: ./tools/license_header.txt diff --git a/tools/license_header.txt b/tools/license_header.txt deleted file mode 100644 index c0471535..00000000 --- a/tools/license_header.txt +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2024 Swisscom (Schweiz) AG. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License.