mirror of
https://github.com/aykhans/sarin.git
synced 2026-01-13 20:11:21 +00:00
92 lines
2.3 KiB
YAML
92 lines
2.3 KiB
YAML
# https://taskfile.dev
|
|
version: "3"
|
|
|
|
vars:
|
|
BIN_DIR: ./bin
|
|
GOLANGCI_LINT_VERSION: v2.7.2
|
|
GOLANGCI: "{{.BIN_DIR}}/golangci-lint-{{.GOLANGCI_LINT_VERSION}}"
|
|
|
|
tasks:
|
|
ftl:
|
|
desc: Run fmt, tidy, and lint.
|
|
cmds:
|
|
- task: fmt
|
|
- task: tidy
|
|
- task: lint
|
|
|
|
fmt:
|
|
desc: Run linters
|
|
deps:
|
|
- install-golangci-lint
|
|
cmds:
|
|
- "{{.GOLANGCI}} fmt"
|
|
|
|
tidy:
|
|
desc: Run go mod tidy.
|
|
cmds:
|
|
- go mod tidy {{.CLI_ARGS}}
|
|
|
|
lint:
|
|
desc: Run linters
|
|
deps:
|
|
- install-golangci-lint
|
|
cmds:
|
|
- "{{.GOLANGCI}} run"
|
|
|
|
test:
|
|
desc: Run Go tests.
|
|
cmds:
|
|
- go test ./... {{.CLI_ARGS}}
|
|
|
|
create-bin-dir:
|
|
desc: Create bin directory.
|
|
cmds:
|
|
- mkdir -p {{.BIN_DIR}}
|
|
|
|
build:
|
|
desc: Build the application.
|
|
deps:
|
|
- create-bin-dir
|
|
vars:
|
|
OUTPUT: '{{.OUTPUT | default (printf "%s/sarin" .BIN_DIR)}}'
|
|
cmds:
|
|
- rm -f {{.OUTPUT}}
|
|
- >-
|
|
CGO_ENABLED=0 GOEXPERIMENT=greenteagc go build
|
|
-ldflags "-X 'go.aykhans.me/sarin/internal/version.Version=$(git describe --tags --always)'
|
|
-X 'go.aykhans.me/sarin/internal/version.GitCommit=$(git rev-parse HEAD)'
|
|
-X 'go.aykhans.me/sarin/internal/version.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)'
|
|
-X 'go.aykhans.me/sarin/internal/version.GoVersion=$(go version)'
|
|
-s -w"
|
|
-o {{.OUTPUT}} ./cmd/cli/main.go
|
|
|
|
install-golangci-lint:
|
|
desc: Install golangci-lint
|
|
deps:
|
|
- create-bin-dir
|
|
status:
|
|
- test -f {{.GOLANGCI}}
|
|
cmds:
|
|
- rm -f {{.GOLANGCI}}
|
|
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b {{.BIN_DIR}} {{.GOLANGCI_LINT_VERSION}}
|
|
- mv {{.BIN_DIR}}/golangci-lint {{.GOLANGCI}}
|
|
|
|
docker-build:
|
|
desc: Build the Docker image.
|
|
vars:
|
|
IMAGE_NAME: '{{.IMAGE_NAME | default "sarin"}}'
|
|
TAG: '{{.TAG | default "latest"}}'
|
|
GO_VERSION: '{{.GO_VERSION | default ""}}'
|
|
VERSION:
|
|
sh: git describe --tags --always
|
|
GIT_COMMIT:
|
|
sh: git rev-parse HEAD
|
|
cmds:
|
|
- >-
|
|
docker build
|
|
{{if .GO_VERSION}}--build-arg GO_VERSION={{.GO_VERSION}}{{end}}
|
|
--build-arg VERSION={{.VERSION}}
|
|
--build-arg GIT_COMMIT={{.GIT_COMMIT}}
|
|
-t {{.IMAGE_NAME}}:{{.TAG}}
|
|
.
|