# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2

git:
  ignore_tags:
    - nightly
    - ".*-nightly.*"

before:
  hooks:
    - go mod tidy
    - go generate ./...
    - sh -c 'cd web/frontend && pnpm install && pnpm build:backend'
    - go install github.com/tc-hib/go-winres@latest
    - go-winres make --in web/backend/winres/winres.json --out web/backend/rsrc --product-version={{ .Version }} --file-version={{ .Version }}

builds:
  - id: picoclaw
    env:
      - CGO_ENABLED=0
    tags:
      - goolm
      - stdjson
    ldflags:
      - -s -w
      - -X github.com/sipeed/picoclaw/pkg/config.Version={{ .Version }}
      - -X github.com/sipeed/picoclaw/pkg/config.GitCommit={{ .ShortCommit }}
      - -X github.com/sipeed/picoclaw/pkg/config.BuildTime={{ .Date }}
      - -X github.com/sipeed/picoclaw/pkg/config.GoVersion={{ .Env.GOVERSION }}
    goos:
      - linux
      - windows
      - darwin
      - freebsd
      - netbsd
    goarch:
      - amd64
      - arm64
      - riscv64
      - loong64
      - arm
      - s390x
      - mipsle
    goarm:
      - "6"
      - "7"
    gomips:
      - softfloat
    main: ./cmd/picoclaw
    ignore:
      - goos: windows
        goarch: arm
      - goos: netbsd
        goarch: s390x
      - goos: netbsd
        goarch: mips64
      - goos: netbsd
        goarch: arm

  - id: picoclaw-launcher
    binary: picoclaw-launcher
    env:
      - CGO_ENABLED=0
    tags:
      - goolm
      - stdjson
    ldflags:
      - -s -w
    goos:
      - linux
      - windows
      - darwin
      - freebsd
      - netbsd
    goarch:
      - amd64
      - arm64
      - riscv64
      - loong64
      - arm
      - s390x
      - mipsle
    goarm:
      - "6"
      - "7"
    gomips:
      - softfloat
    main: ./web/backend
    ignore:
      - goos: windows
        goarch: arm
      - goos: netbsd
        goarch: s390x
      - goos: netbsd
        goarch: mips64
      - goos: netbsd
        goarch: arm

  - id: picoclaw-launcher-tui
    binary: picoclaw-launcher-tui
    env:
      - CGO_ENABLED=0
    tags:
      - goolm
      - stdjson
    ldflags:
      - -s -w
    goos:
      - linux
      - windows
      - darwin
      - freebsd
      - netbsd
    goarch:
      - amd64
      - arm64
      - riscv64
      - loong64
      - arm
      - s390x
      - mipsle
    goarm:
      - "6"
      - "7"
    gomips:
      - softfloat
    main: ./cmd/picoclaw-launcher-tui
    ignore:
      - goos: windows
        goarch: arm
      - goos: netbsd
        goarch: s390x
      - goos: netbsd
        goarch: mips64
      - goos: netbsd
        goarch: arm

dockers_v2:
  - id: picoclaw
    dockerfile: docker/Dockerfile.goreleaser
    extra_files:
      - docker/entrypoint.sh
    ids:
      - picoclaw
    images:
      - "ghcr.io/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw"
      - 'docker.io/{{ .Env.DOCKERHUB_IMAGE_NAME }}'
    tags:
      - '{{ if isEnvSet "NIGHTLY_BUILD" }}nightly{{ else }}{{ .Tag }}{{ end }}'
      - '{{ if isEnvSet "NIGHTLY_BUILD" }}nightly{{ else }}latest{{ end }}'
    platforms:
      - linux/amd64
      - linux/arm64
      - linux/riscv64

  - id: picoclaw-launcher
    dockerfile: docker/Dockerfile.goreleaser.launcher
    ids:
      - picoclaw
      - picoclaw-launcher
      - picoclaw-launcher-tui
    images:
      - "ghcr.io/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw"
      - 'docker.io/{{ .Env.DOCKERHUB_IMAGE_NAME }}'
    tags:
      - '{{ if isEnvSet "NIGHTLY_BUILD" }}nightly-launcher{{ else }}{{ .Tag }}-launcher{{ end }}'
      - '{{ if isEnvSet "NIGHTLY_BUILD" }}nightly-launcher{{ else }}launcher{{ end }}'
    platforms:
      - linux/amd64
      - linux/arm64
      - linux/riscv64

notarize:
  macos:
    - enabled: '{{ isEnvSet "MACOS_SIGN_P12" }}'
      ids:
        - picoclaw
        - picoclaw-launcher
        - picoclaw-launcher-tui
      sign:
        certificate: "{{.Env.MACOS_SIGN_P12}}"
        password: "{{.Env.MACOS_SIGN_PASSWORD}}"
      notarize:
        issuer_id: "{{.Env.MACOS_NOTARY_ISSUER_ID}}"
        key_id: "{{.Env.MACOS_NOTARY_KEY_ID}}"
        key: "{{.Env.MACOS_NOTARY_KEY}}"
        wait: true
        timeout: 20m

archives:
  - formats: [tar.gz]
    # this name template makes the OS and Arch compatible with the results of `uname`.
    name_template: >-
      {{ .ProjectName }}_
      {{- title .Os }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else if eq .Arch "386" }}i386
      {{- else }}{{ .Arch }}{{ end }}
      {{- if .Arm }}v{{ .Arm }}{{ end }}
    # use zip for windows archives
    format_overrides:
      - goos: windows
        formats: [zip]

nfpms:
  - id: picoclaw
    ids:
      - picoclaw
      - picoclaw-launcher
      - picoclaw-launcher-tui
    package_name: picoclaw
    file_name_template: >-
      {{ .PackageName }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else if eq .Arch "arm64" }}aarch64
      {{- else if eq .Arch "arm" }}armv{{ .Arm }}
      {{- else }}{{ .Arch }}{{ end }}
    vendor: picoclaw
    homepage: https://github.com/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw
    maintainer: picoclaw contributors
    description: picoclaw - a tool for managing and running tasks
    license: MIT
    formats:
      - rpm
      - deb
    bindir: /usr/bin
    contents:
      - src: web/picoclaw-launcher.desktop
        dst: /usr/share/applications/picoclaw-launcher.desktop
      - src: web/picoclaw-launcher.png
        dst: /usr/share/icons/hicolor/512x512/apps/picoclaw-launcher.png

changelog:
  sort: asc
  filters:
    exclude:
      - "^docs:"
      - "^test:"

# upx:
#    - enabled: true
#      compress: best
#      lzma: true

release:
  disable: '{{ isEnvSet "NIGHTLY_BUILD" }}'
  footer: >-

    ---

    Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
