150 lines
4.1 KiB
YAML
150 lines
4.1 KiB
YAML
# https://taskfile.dev
|
|||
|
|
version: "3"
|
||
|
|
|
||
|
|
vars:
|
||
|
|
APP: tele-recv
|
||
|
|
BIN_DIR: bin
|
||
|
|
CONFIG: telegram.yaml
|
||
|
|
GO_VERSION: "1.15"
|
||
|
|
LDFLAGS: '-s -w'
|
||
|
|
BUILD_DIR: "{{.BIN_DIR}}/{{.APP}}"
|
||
|
|
|
||
|
|
tasks:
|
||
|
|
default:
|
||
|
|
desc: Show available tasks
|
||
|
|
cmd: task --list-all
|
||
|
|
|
||
|
|
# ─── Build ────────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
build:
|
||
|
|
desc: Build the binary for the current platform
|
||
|
|
deps: [deps]
|
||
|
|
cmds:
|
||
|
|
- mkdir -p "{{.BIN_DIR}}"
|
||
|
|
- CGO_ENABLED=1 go build -ldflags="{{.LDFLAGS}}" -o "{{.BIN_DIR}}/{{.APP}}" .
|
||
|
|
sources:
|
||
|
|
- "**/*.go"
|
||
|
|
- go.mod
|
||
|
|
- go.sum
|
||
|
|
generates:
|
||
|
|
- "{{.BIN_DIR}}/{{.APP}}"
|
||
|
|
|
||
|
|
build-all:
|
||
|
|
desc: Cross-compile for linux/amd64 and windows/amd64
|
||
|
|
cmds:
|
||
|
|
- task: build-linux
|
||
|
|
- task: build-windows
|
||
|
|
|
||
|
|
build-linux:
|
||
|
|
desc: Build for linux/amd64 (requires CGO cross-compiler)
|
||
|
|
env:
|
||
|
|
GOOS: linux
|
||
|
|
GOARCH: amd64
|
||
|
|
CGO_ENABLED: "1"
|
||
|
|
CC: x86_64-linux-gnu-gcc
|
||
|
|
cmds:
|
||
|
|
- mkdir -p "{{.BIN_DIR}}"
|
||
|
|
- go build -ldflags="{{.LDFLAGS}}" -o "{{.BIN_DIR}}/{{.APP}}-linux" .
|
||
|
|
sources:
|
||
|
|
- "**/*.go"
|
||
|
|
- go.mod
|
||
|
|
- go.sum
|
||
|
|
generates:
|
||
|
|
- "{{.BIN_DIR}}/{{.APP}}-linux"
|
||
|
|
silent: false
|
||
|
|
|
||
|
|
build-windows:
|
||
|
|
desc: Build for windows/amd64 (requires MinGW cross-compiler)
|
||
|
|
env:
|
||
|
|
GOOS: windows
|
||
|
|
GOARCH: amd64
|
||
|
|
CGO_ENABLED: "1"
|
||
|
|
CC: x86_64-w64-mingw32-gcc
|
||
|
|
cmds:
|
||
|
|
- mkdir -p "{{.BIN_DIR}}"
|
||
|
|
- go build -ldflags="{{.LDFLAGS}}" -o "{{.BIN_DIR}}/{{.APP}}-win64.exe" .
|
||
|
|
sources:
|
||
|
|
- "**/*.go"
|
||
|
|
- go.mod
|
||
|
|
- go.sum
|
||
|
|
generates:
|
||
|
|
- "{{.BIN_DIR}}/{{.APP}}-win64.exe"
|
||
|
|
silent: false
|
||
|
|
|
||
|
|
# ─── Test ─────────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
test:
|
||
|
|
desc: Run all tests
|
||
|
|
cmds:
|
||
|
|
- go test ./...
|
||
|
|
|
||
|
|
test-race:
|
||
|
|
desc: Run tests with race detector
|
||
|
|
cmds:
|
||
|
|
- go test -race ./...
|
||
|
|
|
||
|
|
test-cover:
|
||
|
|
desc: Run tests with coverage report
|
||
|
|
cmds:
|
||
|
|
- go test -coverprofile=coverage.out ./...
|
||
|
|
- go tool cover -func=coverage.out
|
||
|
|
|
||
|
|
# ─── Run ──────────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
run:
|
||
|
|
desc: Run the service (start subcommand)
|
||
|
|
deps: [build]
|
||
|
|
cmds:
|
||
|
|
- "{{.BIN_DIR}}/{{.APP}} start"
|
||
|
|
|
||
|
|
run-test:
|
||
|
|
desc: Run the environment test (test subcommand)
|
||
|
|
deps: [build]
|
||
|
|
cmds:
|
||
|
|
- "{{.BIN_DIR}}/{{.APP}} test"
|
||
|
|
|
||
|
|
# ─── Development helpers ──────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
emu:
|
||
|
|
desc: Create a virtual serial port pair (ttyS0 ↔ ttyS1) with socat
|
||
|
|
cmds:
|
||
|
|
- socat PTY,link=ttyS0 PTY,link=ttyS1
|
||
|
|
silent: false
|
||
|
|
|
||
|
|
deps:
|
||
|
|
desc: Tidy and download Go module dependencies
|
||
|
|
cmds:
|
||
|
|
- go mod tidy
|
||
|
|
- go mod download
|
||
|
|
sources:
|
||
|
|
- go.mod
|
||
|
|
- go.sum
|
||
|
|
generates:
|
||
|
|
- go.sum
|
||
|
|
|
||
|
|
lint:
|
||
|
|
desc: Run go vet on all packages
|
||
|
|
cmds:
|
||
|
|
- go vet ./...
|
||
|
|
|
||
|
|
clean:
|
||
|
|
desc: Remove build artifacts, logs, and database
|
||
|
|
cmds:
|
||
|
|
- rm -rf "{{.BIN_DIR}}"
|
||
|
|
- rm -f telegram.db
|
||
|
|
- rm -rf ./logs/
|
||
|
|
silent: false
|
||
|
|
|
||
|
|
# ─── Distribution package ─────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
dist:
|
||
|
|
desc: Build all platforms and package into a tarball
|
||
|
|
cmds:
|
||
|
|
- task: build-all
|
||
|
|
- mkdir -p "{{.BUILD_DIR}}"
|
||
|
|
- cp "{{.BIN_DIR}}/{{.APP}}-linux" "{{.BUILD_DIR}}/"
|
||
|
|
- cp "{{.BIN_DIR}}/{{.APP}}-win64.exe" "{{.BUILD_DIR}}/"
|
||
|
|
- cp "{{.CONFIG}}" "{{.BUILD_DIR}}/"
|
||
|
|
- cd "{{.BIN_DIR}}" && tar czvf "{{.APP}}.tar.gz" "{{.APP}}/" && mv "{{.APP}}.tar.gz" .
|
||
|
|
- rm -rf "{{.BUILD_DIR}}"
|
||
|
|
silent: false
|