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

Add linter CI pipeline #3

Merged
merged 2 commits into from
Sep 17, 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
2 changes: 1 addition & 1 deletion .github/workflows/govuln.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- run: |
set -euo pipefail

go install golang.org/x/vuln/cmd/govulncheck@latest && govulncheck ./...
make vulncheck
60 changes: 60 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/expected_netboxmock_calls_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/netbox_testdata_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 0 additions & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ func GetOperatorConfig() *OperatorConfig {
func GetProtocol() string {
if GetOperatorConfig().HttpsEnable {
return "https"
} else {
return "http"
}
return "http"
}

func GetBaseUrl() string {
Expand Down
6 changes: 0 additions & 6 deletions tools/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
13 changes: 0 additions & 13 deletions tools/license_header.txt

This file was deleted.