# .goreleaser.yml
version: 2
project_name: CBZOptimizer

# Configures the release process on GitHub
# https://goreleaser.com/customization/release/
release:
  github:
    owner: belphemur
    name: CBZOptimizer
  include_meta: true
  # draft: false # Default is false
  # prerelease: auto # Default is auto
  # mode: replace # Default is append

# Configures the binary archive generation
# https://goreleaser.com/customization/archive/
archives:
  - ids:
      - cbzoptimizer
    formats: ["tar.zst"]
    format_overrides:
      - # Which GOOS to override the format for.
        goos: windows
        formats: ["zip"] # Plural form, multiple formats. Since: v2.6

# Configures the changelog generation
# https://goreleaser.com/customization/changelog/
changelog:
  use: github
  format: "{{.SHA}}: {{.Message}} (@{{.AuthorUsername}})"
  sort: asc
  filters:
    exclude:
      - "^docs:"
      - "^test:"
      - "^chore:"
  groups:
    - title: Features
      regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
      order: 0
    - title: "Bug fixes"
      regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
      order: 1
    - title: "Performance"
      regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$'
      order: 2

# Hooks to run before the build process starts
# https://goreleaser.com/customization/hooks/
before:
  hooks:
    - go mod tidy
    - go generate ./...

# Configures the Go build process
# https://goreleaser.com/customization/build/
builds:
  - id: cbzoptimizer
    main: cmd/cbzoptimizer/main.go
    goos:
      - linux
      - darwin
      - windows
    goarch:
      - amd64
      - arm64
    ignore:
      - goos: windows
        goarch: arm64
    # ensures mod timestamp to be the commit timestamp
    mod_timestamp: "{{ .CommitTimestamp }}"
    flags:
      # trims path
      - -trimpath
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }}
    env:
      - CGO_ENABLED=0
  - id: encoder-setup
    main: cmd/encoder-setup/main.go
    binary: encoder-setup
    goos:
      - linux
    goarch:
      - amd64
      - arm64
    # ensures mod timestamp to be the commit timestamp
    mod_timestamp: "{{ .CommitTimestamp }}"
    flags:
      # trims path
      - -trimpath
    tags:
      - encoder_setup
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }}
    env:
      - CGO_ENABLED=0

# Configures the checksum file generation
# https://goreleaser.com/customization/checksum/
checksum:
  name_template: "checksums.txt"

# Change the digests filename for attestation
# https://goreleaser.com/customization/docker_digest/
docker_digest:
  name_template: "digests.txt"

# Creates a source code archive (tar.gz and zip)
# https://goreleaser.com/customization/source/
source:
  enabled: true

# Configures Go Modules settings
# https://goreleaser.com/customization/gomod/
gomod:
  proxy: true

# Creates SBOMs (Software Bill of Materials)
# https://goreleaser.com/customization/sbom/
sboms:
  - id: archive # Default ID for archive SBOMs
    artifacts: archive # Generate SBOMs for binary archives using Syft
  - id: source # Unique ID for source SBOM
    artifacts: source # Generate SBOM for the source code archive

# Creates Docker images and pushes them to registries using Docker v2 API
# https://goreleaser.com/customization/docker/
dockers_v2:
  - id: cbzoptimizer-image
    ids:
      - cbzoptimizer
      - encoder-setup
    platforms:
      - linux/amd64
      - linux/arm64
    images:
      - "ghcr.io/belphemur/cbzoptimizer"
    tags:
      - "{{ .Version }}"
      - latest
    annotations:
      "org.opencontainers.image.description": "CBZOptimizer is a Go-based tool designed to optimize CBZ (Comic Book Zip) and CBR (Comic Book RAR) files by converting images to a specified format and quality. This tool is useful for reducing the size of comic book archives while maintaining acceptable image quality."
      "org.opencontainers.image.created": "{{.Date}}"
      "org.opencontainers.image.name": "{{.ProjectName}}"
      "org.opencontainers.image.revision": "{{.FullCommit}}"
      "org.opencontainers.image.version": "{{.Version}}"
      "org.opencontainers.image.source": "{{.GitURL}}"
    labels:
      "org.opencontainers.image.created": "{{.Date}}"
      "org.opencontainers.image.name": "{{.ProjectName}}"
      "org.opencontainers.image.revision": "{{.FullCommit}}"
      "org.opencontainers.image.version": "{{.Version}}"
      "org.opencontainers.image.source": "{{.GitURL}}"
      "org.opencontainers.image.description": "CBZOptimizer is a Go-based tool designed to optimize CBZ (Comic Book Zip) and CBR (Comic Book RAR) files by converting images to a specified format and quality. This tool is useful for reducing the size of comic book archives while maintaining acceptable image quality."
