# SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
#
# SPDX-License-Identifier: CC0-1.0

version: "3"

vars:
  VERSION:
    sh: git describe --tags --always 2>/dev/null || echo "v0.0.0"
  GOOS:
    sh: go env GOOS
  GOARCH:
    sh: go env GOARCH

env:
  CGO_ENABLED: 0

tasks:
  default:
    desc: Run all checks
    cmds:
      - task: fmt
      - task: lint:fix
      - task: staticcheck
      - task: test
      - task: vuln
      - task: reuse

  fmt:
    cmds:
      - go install mvdan.cc/gofumpt@latest
      - gofumpt -l -w .

  lint:
    cmds:
      - golangci-lint run

  lint:fix:
    cmds:
      - golangci-lint run --fix

  staticcheck:
    cmds:
      - go install honnef.co/go/tools/cmd/staticcheck@latest
      - staticcheck ./...

  test:
    cmds:
      - go test -v ./...

  vuln:
    cmds:
      - go install golang.org/x/vuln/cmd/govulncheck@latest
      - govulncheck ./...

  reuse:
    desc: Lint licenses and copyright headers
    cmds:
      - reuse lint

  build:
    cmds:
      - go build -o lune -ldflags "-s -w -X main.version={{.VERSION}}"
    generates:
      - lune

  install:
    cmds:
      - go install -ldflags "-s -w -X main.version={{.VERSION}}"

  run:
    cmds:
      - go run -ldflags "-s -w -X main.version={{.VERSION}}" . {{.CLI_ARGS}}

  pack:
    desc: Pack lune with UPX
    cmds:
      - upx --best -qo lune.min lune
      - mv lune.min lune
    sources:
      - lune

  clean:
    desc: Remove build artifacts
    cmds:
      - rm -rf lune dist/

  clean-all:
    desc: Remove build artifacts and config.toml
    cmds:
      - rm -rf lune config.toml

  release:
    desc: Interactive release workflow (tag, build, pack, upload)
    cmds:
      - ./release.fish
