Skip to content

Commit

Permalink
chore: use github-action for golangci-lint workflow (#538)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Nov 8, 2023
1 parent 3acd492 commit a97d336
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 63 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Lint checks
on:
push:
branches:
- 'main'
- '[0-9]+.[1-9][0-9]*.x'
pull_request:
branches:
- 'main'
- '[0-9]+.[1-9][0-9]*.x'
paths:
- "**.go"
- "**/go.mod"
- "**/go.sum"
- ".golangi.yml"
- ".github/workflows/golangci-lint.yml"
- "!docs/**"
env:
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION: "v1.55.2"
GO_VERSION: "~1.20"
jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-22.04
strategy:
fail-fast: false
steps:
- name: Check out code
uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
working-directory: ./
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: --config ./.golangci.yml -v
29 changes: 3 additions & 26 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,9 @@ permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.DEFAULT_GO_VERSION }}
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Environment
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Module cache
uses: actions/cache@v3
env:
cache-name: go-mod-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
- name: Run linter
run: make lint

unit-test:
name: Unit Tests
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Install Go
uses: actions/setup-go@v4
Expand Down Expand Up @@ -78,7 +55,7 @@ jobs:
docker-local:
permissions:
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -117,7 +94,7 @@ jobs:
path: ${{ github.workspace }}/open-feature-operator-local.tar

e2e-test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: docker-local
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
pull-requests: write
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
name: Validate PR title
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
permissions:
contents: write # for google-github-actions/release-please-action to create release commit
pull-requests: write # for google-github-actions/release-please-action to create release PR
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

# Release-please creates a PR that tracks all changes
steps:
Expand All @@ -38,7 +38,7 @@ jobs:
permissions:
packages: write # to push the container image
needs: release-please
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
if: ${{ needs.release-please.outputs.release_created }}
steps:
- name: Checkout
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
permissions:
contents: write # for softprops/action-gh-release to create GitHub release
needs: release-please
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
if: ${{ needs.release-please.outputs.release_created }}
steps:
- name: Checkout
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
needs: release-please
permissions:
contents: write
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
if: ${{ needs.release-please.outputs.release_created }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-crd-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defaults:
jobs:
check-helm-docs:
name: Check crd documentation values
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
34 changes: 34 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
run:
timeout: 5m
go: '1.20'
linters:
enable:
- gofmt # Gofmt checks whether code was gofmt-ed. By default, this tool runs with -s option to check for code simplification
- gci # Gci controls golang package import order and makes it always deterministic.
- errorlint # errorlint can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- containedctx # containedctx is a linter that detects struct contained context.Context field
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
- noctx # noctx finds sending http request without context.Context
- gocyclo # measure cyclomatic complexity
- gocognit # measure cognitive complexity
- funlen # limit function length
- dupl # Detect code duplication

issues:
exclude-rules:
- linters:
- containedctx
- gocyclo
- gocognit
- funlen
path: _test\.go

linters-settings:
gocyclo:
min-complexity: 10
gocognit:
min-complexity: 20
funlen:
lines: 120
statements: 120
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ e2e-test-validate-local:
.PHONY: lint
lint:
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
${GOPATH}/bin/golangci-lint run --deadline=3m --timeout=3m ./... # Run linters
${GOPATH}/bin/golangci-lint run --deadline=3m --timeout=3m --config=./.golangci.yml -v ./... # Run linters

.PHONY: generate-crdocs
generate-crdocs: kustomize crdocs
Expand Down
2 changes: 2 additions & 0 deletions apis/core/v1alpha1/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ type FlagSourceConfigurationList struct {
Items []FlagSourceConfiguration `json:"items"`
}

//nolint:gocyclo
func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
fsc := &FlagSourceConfigurationSpec{
MetricsPort: DefaultMetricPort,
Expand Down Expand Up @@ -278,6 +279,7 @@ func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
return fsc, nil
}

//nolint:gocyclo
func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) {
if new == nil {
return
Expand Down
4 changes: 2 additions & 2 deletions apis/core/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1beta1 contains API Schema definitions for the core v1beta1 API group
//+kubebuilder:object:generate=true
//+groupName=core.openfeature.dev
// +kubebuilder:object:generate=true
// +groupName=core.openfeature.dev
package v1beta1

import (
Expand Down
4 changes: 2 additions & 2 deletions controllers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package common
import (
"context"
"fmt"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"

"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
appsV1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down
5 changes: 4 additions & 1 deletion controllers/common/flagd-injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/go-logr/logr"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/controllers/common/constant"
Expand All @@ -16,7 +18,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"
)

const (
Expand Down Expand Up @@ -45,6 +46,7 @@ type FlagdContainerInjector struct {
FlagDResourceRequirements corev1.ResourceRequirements
}

//nolint:gocyclo
func (fi *FlagdContainerInjector) InjectFlagd(
ctx context.Context,
objectMeta *metav1.ObjectMeta,
Expand Down Expand Up @@ -179,6 +181,7 @@ func (fi *FlagdContainerInjector) handleSidecarSources(ctx context.Context, obje
return nil
}

//nolint:gocyclo
func (fi *FlagdContainerInjector) buildSources(ctx context.Context, objectMeta *metav1.ObjectMeta, flagSourceConfig *v1alpha1.FlagSourceConfigurationSpec, podSpec *corev1.PodSpec, sidecar *corev1.Container) ([]types.SourceConfig, error) {
var sourceCfgCollection []types.SourceConfig

Expand Down
7 changes: 5 additions & 2 deletions controllers/common/flagd-injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package common
import (
"context"
"errors"
"reflect"
"testing"

"github.com/go-logr/logr/testr"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/controllers/common/constant"
Expand All @@ -17,10 +20,8 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes/scheme"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"testing"
)

func TestFlagdContainerInjector_InjectDefaultSyncProvider(t *testing.T) {
Expand Down Expand Up @@ -999,6 +1000,7 @@ func Test_getSecurityContext(t *testing.T) {
}
}

//nolint:dupl
func TestFlagdContainerInjector_EnableClusterRoleBinding_AddDefaultServiceAccountName(t *testing.T) {

namespace, fakeClient := initEnableClusterroleBindingTestEnv()
Expand Down Expand Up @@ -1042,6 +1044,7 @@ func TestFlagdContainerInjector_EnableClusterRoleBinding_AddDefaultServiceAccoun
require.Equal(t, namespace, updatedCrb.Subjects[0].Namespace)
}

//nolint:dupl
func TestFlagdContainerInjector_EnableClusterRoleBinding_ServiceAccountName(t *testing.T) {

namespace, fakeClient := initEnableClusterroleBindingTestEnv()
Expand Down
3 changes: 2 additions & 1 deletion controllers/common/flagd-proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package common

import (
"context"
"testing"

"github.com/go-logr/logr/testr"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/apps/v1"
v12 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"testing"
)

func TestNewFlagdProxyConfiguration(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion controllers/common/mock/flagd-injector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions controllers/core/featureflagconfiguration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ import (
"context"

"github.com/go-logr/logr"
corev1alpha1 "github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/controllers/common"
"github.com/open-feature/open-feature-operator/pkg/utils"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"

corev1alpha1 "github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

// FeatureFlagConfigurationReconciler reconciles a FeatureFlagConfiguration object
Expand Down Expand Up @@ -61,6 +59,7 @@ type FeatureFlagConfigurationReconciler struct {

const CrdName = "FeatureFlagConfiguration"

//nolint:gocognit,gocyclo
func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Log.Info("Reconciling" + CrdName)

Expand Down
7 changes: 4 additions & 3 deletions controllers/core/flagsourceconfiguration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"strings"
"time"

"github.com/go-logr/logr"
corev1alpha1 "github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/controllers/common"
appsV1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -30,9 +32,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/go-logr/logr"
corev1alpha1 "github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
)

// FlagSourceConfigurationReconciler reconciles a FlagSourceConfiguration object
Expand All @@ -55,6 +54,8 @@ type FlagSourceConfigurationReconciler struct {

// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/reconcile
//
//nolint:gocyclo
func (r *FlagSourceConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Log.Info("Searching for FlagSourceConfiguration")

Expand Down
Loading

0 comments on commit a97d336

Please sign in to comment.