From 45a69dfc991c4ec075ffbb6f29e45738fc755735 Mon Sep 17 00:00:00 2001 From: Alexander Nabokikh <42908293+AlexNabokikh@users.noreply.github.com> Date: Tue, 28 Feb 2023 20:18:54 +0100 Subject: [PATCH] ci: improved testing job and added linting job (#25) * fix: addressed cuddled decalarations * docs: re-arranged readme badges * chore: added golangci config file * ci: improving pipeline * ci: expanded strategy matrix * ci: run coverage only on master branch * ci: bumped go version * ci: revert to 1.19 * chore: added codeclimate config * chore: disabled golint as it is depricated --- .codeclimate.yml | 70 +++++++++++++++++++++++ .github/workflows/ci.yml | 39 +++++++++---- .golangci.yaml | 120 +++++++++++++++++++++++++++++++++++++++ README.md | 16 ++++-- cmd/root.go | 8 ++- tsort/tsort.go | 2 + 6 files changed, 238 insertions(+), 17 deletions(-) create mode 100644 .codeclimate.yml create mode 100644 .golangci.yaml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..5022048 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,70 @@ +--- +version: "2" + +checks: + argument-count: + config: + threshold: 4 + complex-logic: + config: + threshold: 4 + file-lines: + config: + threshold: 500 + method-complexity: + enabled: false + config: + threshold: 20 + method-count: + enabled: false + config: + threshold: 20 + method-lines: + enabled: false + config: + threshold: 50 + nested-control-flow: + config: + threshold: 4 + return-statements: + config: + threshold: 10 + similar-code: + config: + threshold: # language-specific defaults. an override will affect all languages. + identical-code: + config: + threshold: # language-specific defaults. an override will affect all languages. + +plugins: + gofmt: + enabled: true + govet: + enabled: true + markdownlint: + enabled: true + shellcheck: + enabled: true + fixme: + enabled: true + config: + strings: + - FIXME + - BUG + - HACK + +exclude_patterns: + - "config/" + - "db/" + - "dist/" + - "features/" + - "**/node_modules/" + - "script/" + - "**/spec/" + - "**/test/" + - "**/tests/" + - "Tests/" + - "**/vendor/" + - "**/*_test.go" + - "**/*.d.ts" + - "examples" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2848413..9d89355 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,40 +1,60 @@ -name: ci +name: CI on: push: branches: - - "*" + - master + pull_request: jobs: - test: + golangci-lint: + name: golangci-lint runs-on: ubuntu-latest - steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Go uses: actions/setup-go@v3 with: go-version: 1.19 + - name: Lint + uses: golangci/golangci-lint-action@v3 + tests: + name: Tests + needs: golangci-lint + strategy: + matrix: + go: + - 1.19 + os: + - ubuntu-latest + - macos-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 - name: Install dependencies run: go mod download - - name: Go Test run: make test coverage: + name: Coverage + needs: tests runs-on: ubuntu-latest - needs: test + if: github.ref == 'refs/heads/master' steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Go uses: actions/setup-go@v3 with: go-version: 1.19 - - name: Code Climate Coverage Action uses: paambaati/codeclimate-action@v3.2.0 env: @@ -43,4 +63,3 @@ jobs: coverageCommand: make coverage prefix: ${{ github.event.repository.name }} coverageLocations: "${{github.workspace}}/c.out:gocov" - if: github.ref == 'refs/heads/master' diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..6e3ff8b --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,120 @@ +run: + concurrency: 4 # number of concurrent linters + deadline: 1m # timeout for analysis + issues-exit-code: 1 # exit code when issues were found + tests: true + skip-dirs: + - vendor$ + +output: + format: colored-line-number + print-issued-lines: true + print-linter-name: true + uniq-by-line: true + sort-results: true + +linters-settings: + errcheck: + check-type-assertions: false # Check type assertions + check-blank: false # Check assignments on blank identifiers + + govet: + check-shadowing: true # Check for shadowed variables + + gofmt: + simplify: true + + gosec: + exclude-generated: false # Exclude files that were generated by the protocol buffer compiler + severity: medium + confidence: medium + excludes: + - G306 # Poor file permissions used when writing to a new file + + misspell: + locale: US + + stylecheck: + go: "1.19" + checks: + ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"] + # https://staticcheck.io/docs/options#dot_import_whitelist + dot-import-whitelist: + - fmt + # https://staticcheck.io/docs/options#initialisms + initialisms: + [ + "ACL", + "API", + "ASCII", + "CPU", + "CSS", + "DNS", + "EOF", + "GUID", + "HTML", + "HTTP", + "HTTPS", + "ID", + "IP", + "JSON", + "QPS", + "RAM", + "RPC", + "SLA", + "SMTP", + "SQL", + "SSH", + "TCP", + "TLS", + "TTL", + "UDP", + "UI", + "GID", + "UID", + "UUID", + "URI", + "URL", + "UTF8", + "VM", + "XML", + "XMPP", + "XSRF", + "XSS", + ] + # https://staticcheck.io/docs/options#http_status_code_whitelist + http-status-code-whitelist: ["200", "400", "404", "500"] + + unused: + # Select the Go version to target. The default is '1.13'. + go: "1.19" + + whitespace: + multi-if: true # Enforces newlines (or comments) after every multi-line if statement + multi-func: true # Enforces newlines (or comments) after every multi-line function signature + +linters: + enable-all: true + disable: + - deadcode + - exhaustivestruct + - exhaustruct + - forbidigo + - gochecknoinits + - goerr113 + - golint + - gomnd + - ifshort + - interfacer + - maligned + - nosnakecase + - paralleltest + - rowserrcheck + - scopelint + - sqlclosecheck + - structcheck + - tparallel + - varcheck + - varnamelen + - wastedassign + - wrapcheck diff --git a/README.md b/README.md index 81b8157..a9451ff 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # tfsort +[![badge-gh-ci](https://github.com/AlexNabokikh/tfsort/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexNabokikh/tfsort/actions/workflows/ci.yml/badge.svg) +[![badge-gh-release](https://github.com/AlexNabokikh/tfsort/actions/workflows/release.yml/badge.svg)](https://github.com/AlexNabokikh/tfsort/actions/workflows/release.yml/badge.svg) [![go-report-card](https://goreportcard.com/badge/github.com/AlexNabokikh/tfsort)](https://goreportcard.com/report/github.com/AlexNabokikh/tfsort) [![maintainability](https://api.codeclimate.com/v1/badges/7d6a9fee7a8775dea0d8/maintainability)](https://codeclimate.com/github/AlexNabokikh/tfsort/maintainability) [![test-coverage](https://api.codeclimate.com/v1/badges/7d6a9fee7a8775dea0d8/test_coverage)](https://codeclimate.com/github/AlexNabokikh/tfsort/test_coverage) -[![badge-gh-release](https://github.com/AlexNabokikh/tfsort/actions/workflows/release.yml/badge.svg)](https://github.com/AlexNabokikh/tfsort/actions/workflows/release.yml/badge.svg) -[![badge-gh-ci](https://github.com/AlexNabokikh/tfsort/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexNabokikh/tfsort/actions/workflows/ci.yml/badge.svg) ![Logo](files/logo.png) @@ -20,7 +20,7 @@ ### Homebrew -To install tfsort using Homebrew, run the following command: +To install `tfsort` using Homebrew, run the following command: 1. Add the tap: @@ -28,12 +28,20 @@ To install tfsort using Homebrew, run the following command: brew tap alexnabokikh/tfsort ``` -2. Install tfsort: +2. Install `tfsort`: ```bash brew install tfsort ``` +### Chocolatey (Windows) + +To install `tfsort` using Chocolatey, run the following command: + +```bash +choco install tfsort +``` + ### Binary release To install `tfsort`, you can download the latest binary release from the [releases page](https://github.com/AlexNabokikh/tfsort/releases). diff --git a/cmd/root.go b/cmd/root.go index 73398d1..66688e3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,9 +9,11 @@ import ( // Execute is the entry point for the CLI. func Execute() { - var filePath string - var outputPath string - var dryRun bool + var ( + filePath string + outputPath string + dryRun bool + ) rootCmd := &cobra.Command{ Use: "tfsort [file]", diff --git a/tsort/tsort.go b/tsort/tsort.go index 8f49726..c73b116 100644 --- a/tsort/tsort.go +++ b/tsort/tsort.go @@ -74,6 +74,7 @@ func (i *Ingestor) Parse(path string, outputPath string, dry bool) error { return nameI < nameJ }) + output := strings.Join(matches, "\n\n") + "\n" switch { @@ -101,6 +102,7 @@ func ValidateFilePath(path string) error { } info, err := os.Stat(path) + switch { case os.IsNotExist(err): return errors.New("file does not exist")