Skip to content

Commit

Permalink
ci: improved testing job and added linting job (#25)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AlexNabokikh committed Feb 28, 2023
1 parent 6613e8d commit 45a69df
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 17 deletions.
70 changes: 70 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -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"
39 changes: 29 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'
120 changes: 120 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -20,20 +20,28 @@

### Homebrew

To install tfsort using Homebrew, run the following command:
To install `tfsort` using Homebrew, run the following command:

1. Add the tap:

```bash
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).
Expand Down
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
2 changes: 2 additions & 0 deletions tsort/tsort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 45a69df

Please sign in to comment.