version: 2

before:
  hooks:
    # `go mod tidy` fails on public CI runners because internal/diff/sandbox.go
    # (//go:build sandbox) imports the closed-source pkg/sandbox/. tidy evaluates
    # all build tags. Use `go mod download` which only fetches what go.mod requires.
    - go mod download
    - ./hack/make/completions
    - ./hack/make/manpages

release:
  prerelease: true
  make_latest: false
  name_template: "prerelease {{ .CommitDate }} ({{ .ShortCommit }})"

builds:
  - id: darwin_arm64
    main: ./cmd/ipsw
    binary: ipsw
    env:
      - CGO_ENABLED=1
    goos: [darwin]
    goarch: [arm64]
    tags: []
    mod_timestamp: "{{ .CommitTimestamp }}"
    flags: [-trimpath]
    ldflags:
      - -s -w
      - -X github.com/blacktop/ipsw/cmd/ipsw/cmd.AppVersion={{.Version}}
      - -X github.com/blacktop/ipsw/cmd/ipsw/cmd.AppBuildCommit={{.Commit}}

  - id: linux_build
    main: ./cmd/ipsw
    binary: ipsw
    env:
      - CGO_ENABLED=1
      - >-
        {{- if eq .Arch "amd64" }}CC=zig cc -target x86_64-linux-musl
        {{- else if eq .Arch "arm64" }}CC=zig cc -target aarch64-linux-musl
        {{- end }}
      - >-
        {{- if eq .Arch "amd64" }}CXX=zig cc -target x86_64-linux-musl
        {{- else if eq .Arch "arm64" }}CXX=zig cc -target aarch64-linux-musl
        {{- end }}
    goos: [linux]
    goarch: [amd64, arm64]
    goamd64: [v1]
    goarm64: [v8.0]
    mod_timestamp: "{{ .CommitTimestamp }}"
    flags: [-trimpath]
    ldflags:
      - -s -w
      - -X github.com/blacktop/ipsw/cmd/ipsw/cmd.AppVersion={{.Version}}
      - -X github.com/blacktop/ipsw/cmd/ipsw/cmd.AppBuildCommit={{.Commit}}

  - id: windows_build
    main: ./cmd/ipsw
    binary: ipsw
    env:
      - CGO_ENABLED=1
      - >-
        {{- if eq .Arch "amd64" }}CC=zig cc -target x86_64-windows-gnu
        {{- else if eq .Arch "arm64" }}CC=zig cc -target aarch64-windows-gnu
        {{- end }}
      - >-
        {{- if eq .Arch "amd64" }}CXX=zig cc -target x86_64-windows-gnu
        {{- else if eq .Arch "arm64" }}CXX=zig cc -target aarch64-windows-gnu
        {{- end }}
    goos: [windows]
    goarch: [amd64, arm64]
    goamd64: [v1]
    goarm64: [v8.0]
    mod_timestamp: "{{ .CommitTimestamp }}"
    flags: [-trimpath]
    ldflags:
      - -s -w
      - -X github.com/blacktop/ipsw/cmd/ipsw/cmd.AppVersion={{.Version}}
      - -X github.com/blacktop/ipsw/cmd/ipsw/cmd.AppBuildCommit={{.Commit}}

archives:
  - id: darwin_arm64_archive
    ids: [darwin_arm64]
    name_template: "{{ .ProjectName }}_{{ .Version }}_macOS_arm64"
    format_overrides:
      - goos: windows
        formats: [zip]
    files:
      - README.md
      - LICENSE
      - completions/*
      - manpages/*
    wrap_in_directory: true

  - id: linux_archive
    ids: [linux_build]
    name_template: >-
      {{- .ProjectName }}_{{ .Version }}_{{ .Os }}_
      {{- if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }}
    files:
      - README.md
      - LICENSE
      - completions/*
      - manpages/*
    wrap_in_directory: true

  - id: windows_archive
    ids: [windows_build]
    name_template: >-
      {{- .ProjectName }}_{{ .Version }}_{{ .Os }}_
      {{- if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }}
    format_overrides:
      - goos: windows
        formats: [zip]
    files:
      - README.md
      - LICENSE
      - completions/*
      - manpages/*
    wrap_in_directory: true

checksum:
  name_template: "checksums.prerelease.txt"
