Skip to content

Commit

Permalink
CLOUDP-236398: Adding golangci and code-health action
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaangiolillo committed Mar 7, 2024
1 parent e1e42ca commit 8f033c8
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .github/actionlint-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "actionlint",
"pattern": [
{
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}
68 changes: 68 additions & 0 deletions .github/workflows/code-health-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: 'Code Health Tools'

# Set of validations run on each pull request and merged commits to master.
on:
push:
branches:
- main
paths:
- 'tools/**'
paths-ignore: # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-excluding-paths
- '*.md'
pull_request: {}
workflow_dispatch: {}

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout CLI
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
path: tools/cli
- name: Install Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'tools/cli/go.mod'
- name: Build CLI
run: |
pushd tools/cli
make build
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
sparse-checkout: |
.github
tools
- name: Install Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'tools/cli/go.mod'
cache: false # see https://github.com/golangci/golangci-lint-action/issues/807
- name: golangci-lint
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804
with:
version: v1.56.2
working-directory: tools/cli
- name: Download actionlint
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
sparse-checkout: |
.github
- name: Download actionlint
id: get_actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
shell: bash
- name: Check workflow files
run: |
echo "::add-matcher::.github/actionlint-matcher.json"
${{ steps.get_actionlint.outputs.executable }} -color
shell: bash


135 changes: 135 additions & 0 deletions tools/cli/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
check-shadowing: true
enable:
- fieldalignment

revive:
# see https://github.com/mgechev/revive#available-rules for details.
ignore-generated-header: true
severity: warning
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: errorf
- name: exported
- name: indent-error-flow
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: struct-tag
# Too many unusued parameters, skipping this check for now
#- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
maligned:
suggest-new: true
misspell:
locale: US
ignore-words:
- cancelled
lll:
# Default is 120. '\t' is counted as 1 character.
# set our project to 500, as we are adding open api field description in the schema.
# also, for anyone using vscode, use the following configs:
# "rewrap.wrappingColumn": 500 ... requires the rewrap plugin
# "editor.rulers": [500]
line-length: 500
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 7
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [case, return]
funlen:
lines: 360
statements: 120
linters:
disable-all: true
enable:
- dogsled
- errcheck
- funlen
- gocritic
- gofmt
- goimports
- revive
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- nolintlint
- rowserrcheck
- exportloopref
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- whitespace
- thelper
- testifylint
- exhaustive
- makezero
- noctx
- tenv

# don't enable:
# - deadcode
# - varcheck
# - structcheck
# - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
# - gocyclo # we already have funlen lint
# - dupl # we have a lot of duplicate test cases
# - gochecknoinits # we need the init function for the provider
# - gochecknoglobals # we need some global variables
# - unparam # Forces to create global variables when one variable is repeated in different functions
# - goerr113 # It does not allow you to return an error, you need to save the error in a variable to do it
# - goconst
# - gocognit
issues:
exclude:
- declaration of ".*" shadows declaration at line .*
exclude-rules:
- linters:
- staticcheck
text: "SA1019:" # d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK
- linters:
- gocritic
text: "^hugeParam: req is heavy"

run:
timeout: 10m
tests: true
build-tags:
- integration
modules-download-mode: readonly
15 changes: 14 additions & 1 deletion tools/cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html

GOLANGCI_VERSION=v1.56.2
SOURCE_FILES?=./cmd
BINARY_NAME=openapicli
VERSION=v0.0.1
Expand All @@ -20,8 +21,13 @@ deps: ## Download go module dependencies
go mod download
go mod tidy

.PHONY: devtools
devtools: ## Install dev tools
@echo "==> Installing dev tools..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)

.PHONY: setup
setup: deps ## Set up dev env
setup: deps devtools ## Set up dev env

.PHONY: fmt
fmt: ### Format all go files with goimports and gofmt
Expand All @@ -39,6 +45,13 @@ build-debug:
@echo "==> Building openapicli binary for debugging"
go build -gcflags="$(DEBUG_FLAGS)" -ldflags "$(LINKER_FLAGS)" -o $(DESTINATION) $(SOURCE_FILES)

.PHONY: lint
lint: ## Run linter
golangci-lint run

.PHONY: fix-lint
fix-lint: ## Fix linting errors
golangci-lint run --fix

.PHONY: list
list: ## List all make targets
Expand Down
12 changes: 1 addition & 11 deletions tools/cli/internal/cli/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,14 @@ import (
)

type Opts struct {
Base *load.SpecInfo
outputPath string
Base *load.SpecInfo
}

func (o *Opts) Run(args []string) error {
// To add in follow up PR: CLOUDP-225849
return nil
}

func (o *Opts) removeExternalReferences(paths []string, federated *load.SpecInfo) ([]byte, error) {
// To add in follow up PR: CLOUDP-225849
return nil, nil

}
func (o *Opts) saveFile(data []byte) error {
return nil
}

func (o *Opts) PreRunE(args []string) error {
// To Add in follow up PR: CLOUDP-225849
return nil
Expand Down

0 comments on commit 8f033c8

Please sign in to comment.