# This is the configuration file for GoReleaser.
# It defines how your project should be built, packaged, and released.
# For more information, see: https://goreleaser.com/customization/
version: 2

git:
  ignore_tags:
    - nightly*
    - preview*

# The 'before' hook runs commands before the build process starts.
before:
  hooks:
    # Tidy up the go.mod file to ensure all dependencies are clean.
    - go mod tidy

# 'builds' defines the matrix of binaries to create.
# cgo is enabled for C-accelerated image processing and base64 wrapping (clib/).
# Cross-compilation uses zig cc for Linux/Windows and native clang for macOS.
# The release workflow runs on macos-latest (see .github/workflows/release.yml).
builds:
  - id: matcha
    main: .
    goos:
      - linux
      - darwin
      - windows
    goarch:
      - amd64
      - arm64
    flags:
      - -trimpath
    ldflags:
      - -s -w -buildid= -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
    env:
      - CGO_ENABLED=1
      - >-
        {{- if eq .Os "darwin" }}SDKROOT={{ .Env.SDK_PATH }}{{- end }}
      - >-
        {{- if eq .Os "darwin" }}MACOSX_DEPLOYMENT_TARGET=11.0{{- end }}
      - >-
        {{- if eq .Os "darwin" }}CGO_CFLAGS=-isysroot {{ .Env.SDK_PATH }} -mmacosx-version-min=11.0{{- end }}
      - >-
        {{- if eq .Os "darwin" }}CGO_LDFLAGS=-isysroot {{ .Env.SDK_PATH }}
        {{- else if eq .Os "linux" }}CGO_LDFLAGS=-L{{ .Env.PCSC_DIR }}/lib/{{ .Arch }}
        {{- end }}
      - >-
        {{- if eq .Os "darwin" }}
          {{- if eq .Arch "amd64"}}CC=clang -arch x86_64 -isysroot {{ .Env.SDK_PATH }}{{- end }}
          {{- if eq .Arch "arm64"}}CC=clang -arch arm64 -isysroot {{ .Env.SDK_PATH }}{{- end }}
        {{- else if eq .Os "linux" }}
          {{- if eq .Arch "amd64" }}CC=zig cc -target x86_64-linux-musl -lc{{- end }}
          {{- if eq .Arch "arm64"}}CC=zig cc -target aarch64-linux-musl -lc{{- end }}
        {{- else if eq .Os "windows" }}
          {{- if eq .Arch "amd64" }}CC=zig cc -target x86_64-windows-gnu -lc{{- end }}
          {{- if eq .Arch "arm64"}}CC=zig cc -target aarch64-windows-gnu -lc{{- end }}
        {{- end }}

# 'archives' defines how to package the built binaries.
# 'archives' defines how to package the built binaries.
archives:
  - # The archive configuration.
    # This will create .tar.gz files.
    formats: [tar.gz]

    # A template for the archive file names.
    # e.g., matcha_1.2.3_darwin_amd64.tar.gz
    name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
    # Files to include in the archive.
    format_overrides:
      - goos: windows
        formats: ["zip"]
    files:
      - LICENSE

      - README.md

# 'snapshot' configures how test releases are named when running on non-tagged commits.
snapshot:
  version_template: "{{ .Tag }}-next"

# 'checksum' creates a file with SHA256 checksums for all artifacts.
checksum:
  name_template: "checksums.txt"

# 'changelog' configures the automatic generation of release notes.
changelog:
  # Use 'github-native' to leverage GitHub's release notes API.
  # This automatically includes contributors and links to PRs/issues.
  # Categories are configured in .github/release.yml
  use: github-native

# 'release' configures the GitHub Release creation.
release:
  # If set to true, GoReleaser will automatically draft a new release.
  # Set to false to automatically publish the release.
  draft: false
  # If set to true, will mark the release as a pre-release.
  prerelease: auto
  # Add a footer to the release notes featuring full changelog.
  footer: |
    ---
    This version is also available on **[Snapcraft](https://snapcraft.io/matcha)**, **Homebrew**, **[Flatpak](https://matcha.email/matcha.flatpakref)**!

    View the [installation instructions](https://docs.matcha.email/installation) for more details.

# 'nix' configures the Nix flake publication.
# Generates a default.nix per release fetching prebuilt tarballs,
# pushes to floatpane/nix-matcha. Users install with:
#   nix profile install github:floatpane/nix-matcha
nix:
  - name: matcha
    repository:
      owner: floatpane
      name: nix-matcha
      branch: main
      token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
    commit_author:
      name: Floatpane Bot
      email: us@floatpane.com
    commit_msg_template: "matcha: bump to {{ .Tag }}"
    homepage: "https://matcha.email"
    description: "Beautiful and functional email client for the terminal"
    license: "mit"
    install: |
      mkdir -p $out/bin
      cp -vr ./matcha $out/bin/matcha

# 'brews' configures the Homebrew tap integration.
brews:
  - # The configuration for your Homebrew tap.
    # The name of your formula file will be 'matcha.rb'.
    name: matcha
    # The GitHub repository for your Homebrew tap.
    repository:
      owner: floatpane
      name: homebrew-matcha
      # The token to use for pushing to the tap repository.
      # It uses the secret you'll create in your repository settings.
      token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"

    # The commit author for the tap update.
    commit_author:
      name: Floatpane Bot
      email: us@floatpane.com

    # A description for your formula.
    description: "A beautiful and functional email client for your terminal."
    # The homepage URL for your formula.
    homepage: "https://matcha.email"

    # The dependencies for your formula.
    # Since it's a pre-compiled binary, there are no runtime dependencies.
    dependencies: []

    # The test block for your formula.
    # This command will be run by `brew test matcha`.
    test: |
      system "#{bin}/matcha --version"

    # The installation instructions for your formula.
    # This tells Homebrew to just install the binary.
    install: |
      bin.install "matcha"
# 'winget' configures the WinGet manifest generation and publication.
winget:
  - # Name of the package in WinGet.
    name: matcha
    # Unique package identifier used by WinGet.
    package_identifier: floatpane.matcha
    # WinGet publisher metadata.
    publisher: floatpane
    publisher_url: "https://matcha.email"
    publisher_support_url: "https://github.com/floatpane/matcha/issues"

    # Package metadata.
    short_description: "A beautiful and functional email client for your terminal."
    description: |
      A beautiful and functional email client for your terminal, built with Go and the charming Bubble Tea TUI library.
      Never leave your command line to check your inbox or send an email again!
    homepage: "https://matcha.email"
    license: MIT
    tags:
      - email
      - terminal
      - tui

    # Use release changelog as WinGet release notes.
    release_notes: "{{ .Changelog }}"

    # Commit to a feature branch in winget-pkgs and open a PR.
    repository:
      owner: floatpane
      name: winget-pkgs
      branch: "{{ .ProjectName }}-{{ .Version }}"
      token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
      pull_request:
        enabled: true
        base:
          owner: microsoft
          name: winget-pkgs
          branch: master

    # Commit author for manifest updates.
    commit_author:
      name: goreleaserbot
      email: bot@goreleaser.com

# Snapcraft is handled separately in the release workflow (requires Ubuntu).
# See .github/workflows/release.yml
