archives:
  - id: coder-linux
    builds: [coder-linux]
    format: tar.gz

  - id: coder-darwin
    builds: [coder-darwin]
    format: zip

  - id: coder-windows
    builds: [coder-windows]
    format: zip

before:
  hooks:
    - go mod tidy
    - rm -f site/out/bin/coder*

builds:
  - id: coder-slim
    dir: cmd/coder
    ldflags: ["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
    env: [CGO_ENABLED=0]
    goos: [darwin, linux, windows]
    goarch: [amd64, arm, arm64]
    goarm: ["7"]
    # Only build arm 7 for Linux
    ignore:
      - goos: windows
        goarm: "7"
      - goos: darwin
        goarm: "7"
    hooks:
      # The "trimprefix" appends ".exe" on Windows.
      post: |
        cp {{.Path}} site/out/bin/coder-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ trimprefix .Name "coder" }}

  - id: coder-linux
    dir: cmd/coder
    flags: [-tags=embed]
    ldflags: ["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
    env: [CGO_ENABLED=0]
    goos: [linux]
    goarch: [amd64, arm, arm64]
    goarm: ["7"]

  - id: coder-windows
    dir: cmd/coder
    flags: [-tags=embed]
    ldflags: ["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
    env: [CGO_ENABLED=0]
    goos: [windows]
    goarch: [amd64, arm64]

  - id: coder-darwin
    dir: cmd/coder
    flags: [-tags=embed]
    ldflags: ["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
    env: [CGO_ENABLED=0]
    goos: [darwin]
    goarch: [amd64, arm64]
    hooks:
      # This signs the binary that will be located inside the zip.
      # MacOS requires the binary to be signed for notarization.
      #
      # If it doesn't successfully sign, the zip sign step will error.
      post: |
        sh -c 'codesign -s {{.Env.AC_APPLICATION_IDENTITY}} -f -v --timestamp --options runtime {{.Path}} || true'

env:
  # Apple identity for signing!
  - AC_APPLICATION_IDENTITY=BDB050EB749EDD6A80C6F119BF1382ECA119CCCC

nfpms:
  - id: packages
    vendor: Coder
    homepage: https://coder.com
    maintainer: Coder <support@coder.com>
    description: |
      Provision development environments with infrastructure with code
    formats:
      - apk
      - deb
      - rpm
    suggests:
      - postgresql
    builds:
      - coder-linux
    bindir: /usr/bin
    contents:
      - src: coder.env
        dst: /etc/coder.d/coder.env
        type: "config|noreplace"
      - src: coder.service
        dst: /usr/lib/systemd/system/coder.service

# Image templates are empty on snapshots to avoid lengthy builds for development.
dockers:
  - image_templates: ["{{ if not .IsSnapshot }}ghcr.io/coder/coder:{{ .Tag }}-amd64{{ end }}"]
    id: coder-linux
    dockerfile: Dockerfile
    use: buildx
    build_flag_templates:
      - --platform=linux/amd64
      - --label=org.opencontainers.image.title=Coder
      - --label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform.
      - --label=org.opencontainers.image.url=https://github.com/coder/coder
      - --label=org.opencontainers.image.source=https://github.com/coder/coder
      - --label=org.opencontainers.image.version={{ .Version }}
      - --label=org.opencontainers.image.revision={{ .FullCommit }}
      - --label=org.opencontainers.image.licenses=AGPL-3.0
  - image_templates: ["{{ if not .IsSnapshot }}ghcr.io/coder/coder:{{ .Tag }}-arm64{{ end }}"]
    goarch: arm64
    dockerfile: Dockerfile
    use: buildx
    build_flag_templates:
      - --platform=linux/arm64/v8
      - --label=org.opencontainers.image.title=coder
      - --label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform.
      - --label=org.opencontainers.image.url=https://github.com/coder/coder
      - --label=org.opencontainers.image.source=https://github.com/coder/coder
      - --label=org.opencontainers.image.version={{ .Tag }}
      - --label=org.opencontainers.image.revision={{ .FullCommit }}
      - --label=org.opencontainers.image.licenses=AGPL-3.0
  - image_templates: ["{{ if not .IsSnapshot }}ghcr.io/coder/coder:{{ .Tag }}-armv7{{ end }}"]
    goarch: arm
    goarm: "7"
    dockerfile: Dockerfile
    use: buildx
    build_flag_templates:
      - --platform=linux/arm/v7
      - --label=org.opencontainers.image.title=Coder
      - --label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform.
      - --label=org.opencontainers.image.url=https://github.com/coder/coder
      - --label=org.opencontainers.image.source=https://github.com/coder/coder
      - --label=org.opencontainers.image.version={{ .Tag }}
      - --label=org.opencontainers.image.revision={{ .FullCommit }}
      - --label=org.opencontainers.image.licenses=AGPL-3.0
docker_manifests:
  - name_template: ghcr.io/coder/coder:{{ .Tag }}
    image_templates:
      - ghcr.io/coder/coder:{{ .Tag }}-amd64
      - ghcr.io/coder/coder:{{ .Tag }}-arm64
      - ghcr.io/coder/coder:{{ .Tag }}-armv7

release:
  ids: [coder-linux, coder-darwin, coder-windows, packages]
  footer: |
    ## Container Image
    - `docker pull ghcr.io/coder/coder:{{ .Tag }}`

signs:
  - ids: [coder-darwin]
    artifacts: archive
    cmd: ./scripts/sign_macos.sh
    args: ["${artifact}"]
    output: true

snapshot:
  name_template: "{{ .Version }}-devel+{{ .ShortCommit }}"
