From 4616ac7aa55921d748ff1dd0b82978b532d67b83 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 31 Jan 2026 02:33:41 +0000 Subject: [PATCH] replace makefile with taskfile add CI config + action --- .github/workflows/golang-ci.yml | 29 +++++++++++++++++ .golangci.yml | 54 +++++++++++++++++++++++++++++++ Taskfile.yml | 57 +++++++++++++++++++++++++++++++++ makefile | 40 ----------------------- 4 files changed, 140 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/golang-ci.yml create mode 100644 .golangci.yml create mode 100644 Taskfile.yml delete mode 100644 makefile diff --git a/.github/workflows/golang-ci.yml b/.github/workflows/golang-ci.yml new file mode 100644 index 0000000..a6aa5e6 --- /dev/null +++ b/.github/workflows/golang-ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + branches: ['main'] + paths: + - '**.go' + pull_request: + branches: ['main'] + paths: + - '**.go' +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + timeout-minutes: 3 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.24' + - name: Install golangci-lint + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - name: Run golangci-lint + run: golangci-lint run ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..55de51c --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,54 @@ +run: + # timeout for analysis, e.g. 30s, 3m, default is 1m + timeout: 3m + # exclude test files + tests: true + +linters: + # Set to true runs only fast linters. + # Good option for 'lint on save', pre-commit hook or CI. + fast: true + + disable-all: true + + enable: + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - gofmt + - gofumpt + - misspell + - unparam + - gosec + - asciicheck + - errname + - gci + - godot + - goimports + - revive + +linters-settings: + gofmt: + rewrite-rules: + - pattern: 'interface{}' + replacement: 'any' + - pattern: 'a[b:len(a)]' + replacement: 'a[b:]' + + misspell: + locale: UK + + errcheck: + check-type-assertions: true + +issues: + max-same-issues: 0 + max-issues-per-linter: 0 + exclude-use-default: false + exclude: + # gosec: Duplicated errcheck checks + - G104 + # gosec: integer overflow conversion int -> uint32 + - G115 diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..3bfb992 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,57 @@ +version: '3' + +vars: + PROGRAM: xair-cli + SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}' + BIN_DIR: bin + VERSION: + sh: 'git describe --tags $(git rev-list --tags --max-count=1)' + + WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe' + LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64' + +tasks: + default: + desc: Build the xair-cli project + cmds: + - task: build + + build: + desc: Build the xair-cli project + deps: [vet] + cmds: + - task: build-windows + - task: build-linux + + vet: + desc: Vet the code + deps: [fmt] + cmds: + - go vet ./... + + fmt: + desc: Fmt the code + cmds: + - go fmt ./... + + build-windows: + desc: Build the xair-cli project for Windows + cmds: + - GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" + internal: true + + build-linux: + desc: Build the xair-cli project for Linux + cmds: + - GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" + internal: true + + test: + desc: Run tests + cmds: + - go test ./... + + clean: + desc: Clean the build artifacts + cmds: + - '{{.SHELL}} rm -r {{.BIN_DIR}}' diff --git a/makefile b/makefile deleted file mode 100644 index 2ea3353..0000000 --- a/makefile +++ /dev/null @@ -1,40 +0,0 @@ -program = xair-cli - -GO = @go -BIN_DIR := bin - -WINDOWS=$(BIN_DIR)/$(program)_windows_amd64.exe -LINUX=$(BIN_DIR)/$(program)_linux_amd64 -VERSION=$(shell git describe --tags --always --long --dirty) - -.DEFAULT_GOAL := build - -.PHONY: fmt vet build windows linux test clean -fmt: - $(GO) fmt ./... - -vet: fmt - $(GO) vet ./... - -build: vet windows linux | $(BIN_DIR) - @echo version: $(VERSION) - -windows: $(WINDOWS) - -linux: $(LINUX) - - -$(WINDOWS): - env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" . - -$(LINUX): - env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" . - -test: - $(GO) test ./... - -$(BIN_DIR): - @mkdir -p $@ - -clean: - @rm -rv $(BIN_DIR) \ No newline at end of file