From 6119d00158543480f3c09a51326b5ae9a398ceb5 Mon Sep 17 00:00:00 2001 From: TheEdgeOfRage Date: Tue, 22 Jul 2025 16:31:47 +0200 Subject: [PATCH] Add CI to github pushes --- .github/workflows/ci.yaml | 28 +++++++++++++++++ .github/workflows/release.yml | 8 +++-- .gitignore | 1 + .golangci.yml | 58 +++++++++++++++++++++++++---------- Makefile | 19 ++++++++++++ config/config.go | 6 ++-- parser/record.go | 5 +-- 7 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..b9e0222 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,28 @@ +name: Run CI + +on: + push: + branches: + - "*" + +jobs: + lint_test: + name: Linting and tests + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + + - name: Run linting + run: "make lint" + + - name: Run tests + run: "make test" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ded93a5..70cb664 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,10 +3,11 @@ name: Release on: push: tags: - - "*" + - "v*" jobs: build_release: + name: Build logfmt binaries runs-on: ubuntu-latest strategy: matrix: @@ -30,7 +31,7 @@ jobs: GOARCH: ${{ matrix.goarch }} run: | go build -ldflags="-s -w" -o logfmt-${{ matrix.goos }}-${{ matrix.goarch }}-${{ github.ref_name }} - + - name: Compress with UPX (Linux only) if: matrix.goos == 'linux' uses: crazy-max/ghaction-upx@v3 @@ -47,6 +48,7 @@ jobs: retention-days: 1 create_release: + name: Create GitHub release from tag version runs-on: ubuntu-latest needs: build_release permissions: @@ -68,4 +70,4 @@ jobs: name: "Release ${{ github.ref_name }}" body: | Automated release for tag ${{ github.ref_name }}. - files: release-artifacts/*/* \ No newline at end of file + files: release-artifacts/*/* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/.golangci.yml b/.golangci.yml index 5cb0a2b..3880a3e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,22 +1,46 @@ --- +version: "2" linters: enable: - - goimports - - stylecheck + - forbidigo - lll + - prealloc + - predeclared + - staticcheck - errcheck - -run: - go: '1.22' - timeout: 30s - -issues: - exclude-rules: - - linters: - - lll - source: "// nolint:lll" - - linters: - - unused - - deadcode - - varcheck - source: "// nolint:unused" + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - lll + source: // nolint:lll + - linters: + - staticcheck + source: // nolint:stylecheck + - linters: + - deadcode + - revive + - unused + - varcheck + source: // nolint:unused + - linters: + - staticcheck + text: 'SA1019:' + source: // ignore:deprecated +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + settings: + gci: + sections: + - standard + - default + - localmodule diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9437633 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: setup lint test + +setup: bin/golangci-lint + go mod download + +bin: + mkdir bin + +bin/golangci-lint: bin + GOBIN=$(PWD)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.0 + +lint: bin/golangci-lint + bin/golangci-lint fmt + go vet ./... + go mod tidy + bin/golangci-lint -c .golangci.yml run ./... + +test: + go test -timeout=10s -race -cover ./... diff --git a/config/config.go b/config/config.go index 60995d0..3aa6fa3 100644 --- a/config/config.go +++ b/config/config.go @@ -44,9 +44,9 @@ type rawConfig struct { NoColor bool `long:"no-color" short:"n" description:"Disable color output"` ForceColor bool `long:"force-color" short:"c" description:"Force color output, even when outputting to a pipe"` NoTime bool `long:"no-time" short:"t" description:"Disable time output"` - KeepEmpty bool `long:"keep-empty" short:"k" description:"Keep lines with no field present selected by output or with all excluded"` - Raw bool `long:"raw" short:"r" description:"Output only selected fields values (comma separated) lcut like"` - All bool `long:"all" short:"A" description:"Output all field after the output fields effectivly making it ordered"` + KeepEmpty bool `long:"keep-empty" short:"k" description:"Keep lines with no field present selected by output or with all excluded"` // nolint:lll + Raw bool `long:"raw" short:"r" description:"Output only selected fields values (comma separated) lcut like"` // nolint:lll + All bool `long:"all" short:"A" description:"Output all field after the output fields effectivly making it ordered"` // nolint:lll } func Parse() (*Config, error) { diff --git a/parser/record.go b/parser/record.go index 0f5d73a..500dba5 100644 --- a/parser/record.go +++ b/parser/record.go @@ -7,9 +7,10 @@ import ( "strings" "time" - "github.com/TheEdgeOfRage/logfmt/config" "github.com/fatih/color" "github.com/go-logfmt/logfmt" + + "github.com/TheEdgeOfRage/logfmt/config" ) var ( @@ -155,7 +156,7 @@ func (r *Record) String(cfg *config.Config) string { outFields := r.fieldOrder if len(cfg.OutputFields) > 0 { if cfg.All { - var reorderedFields []string = cfg.OutputFields + reorderedFields := cfg.OutputFields for _, key := range r.fieldOrder { if !slices.Contains(reorderedFields, key) {