version: '3' includes: go: taskfile: ./Taskfile.go.yaml output: prefixed silent: true interval: 1s dotenv: - ./.env vars: NEWLINE_EXCLUDE: >- -not -path "./.git/*" -not -path "./.idea/*" -not -path "./vendor/*" -not -path "./tmp/*" -not -name "*.ico" -not -name "*.png" -not -name "*.svg" tasks: # ======= # HELPERS # ======= all: desc: generate + tidy + lint + test. cmds: - task: generate - task: go:tidy - task: go:lint - task: go:test generate: desc: all generators + cs. cmds: - task: sqlc - task: goverter - task: go:generate - task: cs cs: desc: go:cs + newline. cmds: - task: go:cs - task: newline # =============== # QUALITY CONTROL # =============== newline: desc: add newline at end file. cmds: - >- find . {{.NEWLINE_EXCLUDE}} -type f -exec grep -Iq . {} \; -and -print0 | xargs -0 -n 1 sh -c 'test -z "$(tail -c 1 "$0")" || (echo "" >> $0 && echo $0)' || exit 1 sources: &newline_sources - ./**/* - exclude: "*.ico" - exclude: "*.png" - exclude: "*.svg" newline:check: desc: check newline at end file. cmds: - find . {{.NEWLINE_EXCLUDE}} -type f -exec grep -Iq . {} \; -and -print0 | xargs -0 -n 1 sh -c 'test -z "$(tail -c 1 "$0")" || (echo "No new line at end of $0" && exit 1)' || exit 1 sources: *newline_sources # =========== # DEVELOPMENT # =========== dotenv:install: internal: true cmds: - mkdir -p bin - curl -o bin/env https://raw.githubusercontent.com/bashup/dotenv/master/dotenv - chmod +x bin/env status: - test -f bin/env dotenv: deps: [ dotenv:install ] desc: fill .env file. vars: UID: sh: id -u GID: sh: id -g GO_VER: sh: go mod edit -json | jq -r .Go GOIMPORTS_LOCAL: sh: go list -m | awk -F/ '{print $1}' ENV_DIST: sh: cat .env.dist|tr '\n' ' ' GOPATH: sh: go env GOPATH cmds: - bin/env set GROUP_ID={{.UID}} USER_ID={{.GID}} GO_VER={{.GO_VER}} GOPATH={{.GOPATH}} {{.ENV_DIST}} sources: - .env.dist - Taskfile.yaml generates: - .env goverter: desc: go run goverter deps: [ dotenv ] cmds: - go run github.com/jmattheis/goverter/cmd/goverter@{{.GOVERTER_VER}} gen ./... sources: - ./**/*.go sqlc: desc: go run sqlc. deps: [ dotenv ] cmds: - go run github.com/sqlc-dev/sqlc/cmd/sqlc@v{{.SQLC_VER}} generate sources: - sqlc.yaml - ./**/sql/**/* - ./**/db/**/* # ========= # OPERATION # ========= up: desc: up all services. cmds: - task: postgres:up - task: api:up down: desc: docker compose down. deps: [ dotenv ] cmds: - docker compose down -v --remove-orphans postgres:build: internal: true desc: docker compose build postgres. deps: [ dotenv ] cmds: - docker compose build postgres sources: - ./**/db/**/* - Dockerfile - docker-compose.yml postgres:up: desc: docker compose up postgres. deps: [ dotenv, postgres:build ] cmds: - docker compose up -d --force-recreate postgres postgres:push: desc: docker compose push postgres. deps: [ dotenv, postgres:build ] cmds: - docker compose push postgres api:build: internal: true desc: docker compose build api image. deps: [ dotenv ] cmds: - docker compose build api sources: - .env - Dockerfile - docker-compose.yml api:up: desc: docker compose up api. deps: [ dotenv, api:build ] cmds: - docker compose up -d --force-recreate api