From 0351646909040eb194d743510f5d08d005d87830 Mon Sep 17 00:00:00 2001 From: James Kong Date: Wed, 20 Nov 2024 23:06:53 +0800 Subject: [PATCH] chore: add taskfiles to simplify development (#103) --- .tool-versions | 1 + Makefile | 4 ---- README.md | 37 ++++++++++++++++++++++++++++++++++ Taskfile.yml | 13 ++++++++++++ taskfiles/install/Taskfile.yml | 11 ++++++++++ taskfiles/install/asdf.yml | 14 +++++++++++++ taskfiles/lint/Taskfile.yml | 15 ++++++++++++++ taskfiles/test/Taskfile.yml | 18 +++++++++++++++++ 8 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 Taskfile.yml create mode 100644 taskfiles/install/Taskfile.yml create mode 100644 taskfiles/install/asdf.yml create mode 100644 taskfiles/lint/Taskfile.yml create mode 100644 taskfiles/test/Taskfile.yml diff --git a/.tool-versions b/.tool-versions index 854be15..db5afda 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,3 @@ golang 1.22.9 golangci-lint 1.62.0 +task 3.40.0 \ No newline at end of file diff --git a/Makefile b/Makefile index 087ed13..584545f 100644 --- a/Makefile +++ b/Makefile @@ -45,10 +45,6 @@ build: clean @echo "\n\t$(C_GREEN)# Build binary $(BINARY)$(C_END)" go build -trimpath -ldflags $(LDFLAGS) -o $(BIN_FOLDER)/$(BINARY) main.go -.PHONY: lint -lint: - $(SCRIPTS_F)/golangci_html_report.sh - .PHONY: release release: @echo "\n\t$(C_GREEN)# Creating release $(VERSION) $(C_END)" diff --git a/README.md b/README.md index f387e87..7c9a4c4 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,40 @@ Development
+ +## Development + +### Getting Started + +Install the developments tools and dependencies to get started. + +#### Install `asdf` + +[asdf](https://asdf-vm.com/) is a tool version manager. All dependencies used for local development of this repo are +managed through `asdf`. To install `asdf`: + +1. [Install asdf](https://asdf-vm.com/guide/getting-started.html) +2. Follow the instructions to ensure `asdf` is shimmed into your terminal or development environment + +#### Install `task` + +[task](https://github.com/go-task/task) is an alternative to `make` and is used to provide commands for everyday +development tasks. To install `task`: + +1. Add the asdf task plugin: `asdf plugin add task` +2. Install `task` with `asdf install task` +3. Run `task -l` to see available commands + +### Installing Dependencies + +Now that you have `asdf` and `task` installed, you can install the dependencies for this repo: + +```bash +task install:tools +``` + +### Linting + +```shell +task lint +``` \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..01b3a39 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,13 @@ +# https://taskfile.dev + +version: "3" + +includes: + install: + taskfile: ./taskfiles/install/Taskfile.yml + + lint: + taskfile: ./taskfiles/lint/Taskfile.yml + + test: + taskfile: ./taskfiles/test/Taskfile.yml diff --git a/taskfiles/install/Taskfile.yml b/taskfiles/install/Taskfile.yml new file mode 100644 index 0000000..626fce6 --- /dev/null +++ b/taskfiles/install/Taskfile.yml @@ -0,0 +1,11 @@ +version: '3' + +includes: + asdf: + taskfile: ./asdf.yml + +tasks: + tools: + desc: Installs development tools + cmds: + - task: asdf:install diff --git a/taskfiles/install/asdf.yml b/taskfiles/install/asdf.yml new file mode 100644 index 0000000..0b21d03 --- /dev/null +++ b/taskfiles/install/asdf.yml @@ -0,0 +1,14 @@ +version: '3' + +tasks: + install: + internal: true + desc: Installs the tools defined in asdf + dir: '{{.USER_WORKING_DIR}}' + cmds: + # Add all the plugins defined in .tool-versions by reading the first column for the plugin + # name and adding it to asdf + - awk '{print $1}' .tool-versions | xargs -I _ asdf plugin add _ + + # Install all the tools defined in .tool-versions + - asdf install \ No newline at end of file diff --git a/taskfiles/lint/Taskfile.yml b/taskfiles/lint/Taskfile.yml new file mode 100644 index 0000000..8bed5de --- /dev/null +++ b/taskfiles/lint/Taskfile.yml @@ -0,0 +1,15 @@ +version: '3' + +tasks: + default: + desc: "Run Go lint checks" + cmds: + - golangci-lint run + fix: + desc: "Fix Go lint issues" + cmds: + - | + echo "Fixing Go lint issues..." + gofmt -s -w . + goimports -w . + golangci-lint run --fix diff --git a/taskfiles/test/Taskfile.yml b/taskfiles/test/Taskfile.yml new file mode 100644 index 0000000..31f68a1 --- /dev/null +++ b/taskfiles/test/Taskfile.yml @@ -0,0 +1,18 @@ +version: '3' + +tasks: + default: + desc: "Run the entire test suite" + cmds: + - go test {{.CLI_ARGS}} ./... + + coverage: + desc: "Run the entire test suite with coverage" + cmds: + - go test -coverprofile=coverage.out -covermode count ./... + - go tool cover -html=coverage.out + + race: + desc: "Run the entire test suite with race detection" + cmds: + - go test -race ./... \ No newline at end of file