Files
softplayer-backend/Taskfile.yml
2026-05-22 11:23:04 +02:00

220 lines
5.9 KiB
YAML

# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
LOCALBIN:
sh: echo "$(pwd)/bin"
MIGRATE: "{{.LOCALBIN}}/migrate"
GOFUMPT: "{{.LOCALBIN}}/gofumpt"
GOLANGCI_LINT: "{{.LOCALBIN}}/golangci-lint"
# Tool versions
GOLANGCI_LINT_VERSION: v2.8.0
tasks:
build:
desc: Build go code
cmd: go build -o ./build/softplayer
silent: true
unit:
desc: Run unit tests
env:
SOFTPLAYER_DB_CONNECTION_STRING: postgres://softplayer:qwertyu9@localhost:30432/softplayer?sslmode=disable
SOFTPLAYER_REDIS_HOST: localhost:30379
cmd: go test ./...
deps:
- run-migrations-dev
silent: true
fmt:
desc: Run gofumt fmt against code.
deps:
- gofumt
cmd: '"{{.GOFUMPT}}" -l -w .'
vet:
desc: Run go vet against code.
cmd: go vet ./...
lint:
desc: Run golangci-lint linter
deps:
- golangci-lint
cmd: '"{{.GOLANGCI_LINT}}" run'
lint-fix:
desc: Run golangci-lint linter and perform fixes
deps:
- golangci-lint
cmd: '"{{.GOLANGCI_LINT}}" run --fix'
lint-config:
desc: Verify golangci-lint linter configuration
deps:
- golangci-lint
cmd: '"{{.GOLANGCI_LINT}}" config verify'
run-migrations-dev:
desc: Execute database migrations
env:
SOFTPLAYER_DB_CONNECTION_STRING: postgres://softplayer:qwertyu9@localhost:30432/softplayer?sslmode=disable
cmd: go run main.go migrate --migrations-path=file://migrations
force-migration:
desc: Force migrate to a desired version
vars:
SOFTPLAYER_DB_CONNECTION_STRING: postgres://softplayer:qwertyu9@localhost:30432/softplayer?sslmode=disable
cmd: "{{ .MIGRATE }} -path=./migrations -database={{ .SOFTPLAYER_DB_CONNECTION_STRING }} force {{ .CLI_ARGS }}"
deps:
- migrate
down-migrations:
desc: Roll back all migrations
vars:
SOFTPLAYER_DB_CONNECTION_STRING: postgres://softplayer:qwertyu9@localhost:30432/softplayer?sslmode=disable
cmd: "{{ .MIGRATE }} -path=./migrations -database={{ .SOFTPLAYER_DB_CONNECTION_STRING }} down -all"
deps:
- migrate
drop-migrations:
desc: Drop migrations
vars:
SOFTPLAYER_DB_CONNECTION_STRING: postgres://softplayer:qwertyu9@localhost:30432/softplayer?sslmode=disable
cmd: "{{ .MIGRATE }} -path=./migrations -database={{ .SOFTPLAYER_DB_CONNECTION_STRING }} drop"
deps:
- migrate
run-server-dev:
desc: Run the local dev server
deps:
- run-migrations-dev
env:
SOFTPLAYER_DB_CONNECTION_STRING: postgres://softplayer:qwertyu9@localhost:30432/softplayer?sslmode=disable
SOFTPLAYER_REDIS_HOST: localhost:30379
cmd: go run main.go server --dev-mode --reflection
psql:
desc: Connect to the dev database
env:
PGDATABASE: softplayer
PGUSER: softplayer
PGPORT: "30432"
PGHOST: localhost
PGPASSWORD: qwertyu9
cmd: psql
deploy-local-env:
desc: Run a kind cluster and deploy deps
deps:
- kind-cluster
- helmfile-deploy
kind-cluster:
desc: Run a kind cluster
cmd: kind create cluster --config ./kind-config.yaml
kind-cluster-remove:
desc: Remove the kind cluster
cmd: kind delete cluster
helmfile-deploy:
desc: Deploy the helmfile for the local dev
cmd: helmfile apply
get-proto-from-branch:
desc: Get the latest version of generated protobuf code from the branch
silent: true
vars:
WORKDIR:
sh: mktemp -d
cmds:
- git clone git@gitea.badhouseplants.net:softplayer/softplayer-go-proto.git '{{ .WORKDIR }}'
- git -C '{{ .WORKDIR }}' checkout '{{ .CLI_ARGS | default "main" }}'
- go get gitea.badhouseplants.net/softplayer/softplayer-go-proto@$(git -C '{{ .WORKDIR }}' rev-parse HEAD)
- rm -rf '{{ .WORKDIR }}'
- go mod tidy
add-migration:
desc: Add a new database migration
silent: true
cmd: "{{.MIGRATE}} create -dir migrations -ext sql {{.CLI_ARGS}}"
deps:
- migrate
# Install required tools
localbin:
desc: Create local bin directory
silent: true
cmds:
- mkdir -p "{{.LOCALBIN}}"
migrate:
desc: Download migrate if necessary
silent: true
deps:
- localbin
cmds:
- task: go-install-tool
vars:
TARGET: "{{.MIGRATE}}"
PACKAGE: github.com/golang-migrate/migrate/v4/cmd/migrate
VERSION: latest
TAGS: "postgres"
go-install-tool:
internal: true
silent: true
cmd: |-
set -e
TARGET="{{.TARGET}}"
PACKAGE="{{.PACKAGE}}@{{.VERSION}}"
VERSIONED="${TARGET}-{{.VERSION}}"
if [ -f "$VERSIONED" ] && [ "$(readlink -- "$TARGET" 2>/dev/null)" = "$VERSIONED" ]; then
echo "$PACKAGE already installed"
exit 0
fi
echo "Downloading $PACKAGE"
rm -f "$TARGET"
TAGS="{{.TAGS}}"
if [ -n "$TAGS" ]; then
echo "Using build tags: $TAGS"
GOBIN="{{.LOCALBIN}}" go install -tags "$TAGS" "$PACKAGE"
else
GOBIN="{{.LOCALBIN}}" go install "$PACKAGE"
fi
mv "{{.LOCALBIN}}/$(basename "$TARGET")" "$VERSIONED"
ln -sf "$(realpath "$VERSIONED")" "$TARGET"
gofumt:
desc: Download latest gofumt
silent: true
deps:
- localbin
cmds:
- task: go-install-tool
vars:
TARGET: "{{.GOFUMPT}}"
PACKAGE: mvdan.cc/gofumpt
VERSION: "latest"
golangci-lint:
desc: Install golangci-lint (with optional custom build)
silent: true
deps:
- localbin
cmds:
- task: go-install-tool
vars:
TARGET: "{{.GOLANGCI_LINT}}"
PACKAGE: github.com/golangci/golangci-lint/v2/cmd/golangci-lint
VERSION: "{{.GOLANGCI_LINT_VERSION}}"
- |
if [ -f .custom-gcl.yml ]; then
echo "Building custom golangci-lint with plugins..."
"{{.GOLANGCI_LINT}}" custom --destination "{{.LOCALBIN}}" --name golangci-lint-custom
mv -f "{{.LOCALBIN}}/golangci-lint-custom" "{{.GOLANGCI_LINT}}"
fi