Skip to content

Commit

Permalink
refactor: rewrite (#11)
Browse files Browse the repository at this point in the history
* re-org packages and use cli v3

* drop yal

* rework config loading and paths

* remove aliases

* cleanup error handlers

* minor cleanups

* ignore non-existant directories

* bump version

* drop terminal color dependencies

* remove unused files

* update go version in workflow
  • Loading branch information
hay-kot authored Dec 13, 2024
1 parent 3ec5b3f commit df1da99
Show file tree
Hide file tree
Showing 22 changed files with 526 additions and 436 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/partial-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Go Build/Test

on:
workflow_call:

jobs:
Go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.23

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
args: --timeout=6m

- name: Build
run: go build ./...

- name: Test
run: go test ./... -race
14 changes: 14 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pr

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
backend-tests:
name: "Go Build/Test"
uses: ./.github/workflows/partial-tests.yml
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and Publish

permissions:
contents: write

on:
push:
tags:
- "*"

jobs:
backend-tests:
name: "Go Build/Test"
uses: ./.github/workflows/partial-tests.yml

goreleaser:
name: "Release"
needs:
- backend-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version: ">=1.23"
cache: true
- uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72 changes: 72 additions & 0 deletions .golanci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
run:
timeout: 5m
linters-settings:
goconst:
min-len: 5
min-occurrences: 5
exhaustive:
default-signifies-exhaustive: true
revive:
ignore-generated-header: false
severity: warning
confidence: 3
depguard:
rules:
main:
deny:
- pkg: io/util
desc: |
Deprecated: As of Go 1.16, the same functionality is now provided by
package io or package os, and those implementations should be
preferred in new code. See the specific function documentation for
details.
- pkg: github.com/pkg/errors
desc: Should be replaced by standard lib errors package
gocritic:
enabled-checks:
- ruleguard
testifylint:
enable-all: true
tagalign:
order:
- json
- schema
- yaml
- yml
- toml
- validate
linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- errcheck
- errorlint
- exhaustive
- exportloopref
- gochecknoinits
- goconst
- gocritic
- gocyclo
- goprintffuncname
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- staticcheck
- stylecheck
- tagalign
- testifylint
- typecheck
- typecheck
- unconvert
- unused
- whitespace
- zerologlint
issues:
exclude-use-default: false
fix: true
25 changes: 18 additions & 7 deletions .goreleaser.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ builds:
- linux
- windows
- darwin

archives:
- format: zip
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"
snapshot:
Expand All @@ -28,3 +35,7 @@ changelog:
exclude:
- "^docs:"
- "^test:"
# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024-12-10, Hayden Kotelman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 49 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3"

env:
LOG_LEVEL: "debug"

tasks:
run:
desc: Runs the main application and supports passing CLI args
cmds:
- go run *.go {{ .CLI_ARGS }}
silent: false

build:
desc: Builds the backend binary
cmds:
- goreleaser build --snapshot --rm-dist

test:
desc: Runs all go tests using gotestsum - supports passing gotestsum args
cmds:
- gotestsum {{ .CLI_ARGS }} ./...

test:watch:
desc: Runs all go tests using gotestsum in watch mode
cmds:
- gotestsum --watch -- -v ./...

coverage:
desc: Runs all go tests with -race flag and generates a coverage report
cmds:
- go test -race -coverprofile=coverage.out -covermode=atomic ./... -v -cover
silent: true

tidy:
desc: Runs go mod tidy on the backend
cmds:
- go mod tidy

lint:
desc: Runs golangci-lint
cmds:
- golangci-lint run ./...

pr:
desc: Runs all go test and lint related tasks for PRs
cmds:
- task: tidy
- task: lint
- task: test
39 changes: 18 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
module github.com/hay-kot/gofind

go 1.19
go 1.23

require (
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.2
github.com/charmbracelet/lipgloss v0.7.1
github.com/hay-kot/yal v0.0.2
github.com/jwalton/go-supportscolor v1.1.0
github.com/muesli/termenv v0.15.1
github.com/sahilm/fuzzy v0.1.0
github.com/urfave/cli/v2 v2.25.1
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/lipgloss v1.0.0
github.com/rs/zerolog v1.33.0
github.com/sahilm/fuzzy v0.1.1
github.com/urfave/cli/v3 v3.0.0-beta1
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/charmbracelet/x/ansi v0.6.0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
)
Loading

0 comments on commit df1da99

Please sign in to comment.