version: 2

project_name: tart

before:
  hooks:
    - .ci/set-version.sh
    - sh .ci/build-release.sh arm64
    - sh .ci/build-release.sh x86_64

builds:
  - id: tart
    builder: prebuilt
    goamd64: [v1]
    goos:
      - darwin
    goarch:
      - arm64
      - amd64
    binary: tart.app/Contents/MacOS/tart
    prebuilt:
      path: '.build/prebuilt/{{- if eq .Arch "arm64" }}arm64{{- else }}x86_64{{ end }}/tart'

universal_binaries:
  - name_template: tart.app/Contents/MacOS/tart
    replace: true
    hooks:
      post:
        - mkdir -p dist/tart_darwin_all/tart.app/Contents/Resources
        - cp Resources/embedded.provisionprofile dist/tart_darwin_all/tart.app/Contents/
        - cp Resources/Info.plist dist/tart_darwin_all/tart.app/Contents/
        - cp "Resources/actool/UPW Tart.icns" "Resources/actool/Assets.car" dist/tart_darwin_all/tart.app/Contents/Resources/
        - cmd: .ci/sign-release.sh
          output: true

archives:
  - name_template: "{{ .ProjectName }}"
    files:
      - src: dist/tart_darwin_all/tart.app/Contents/Info.plist
        dst: tart.app/Contents/Info.plist
      - src: dist/tart_darwin_all/tart.app/Contents/embedded.provisionprofile
        dst: tart.app/Contents/embedded.provisionprofile
      - src: dist/tart_darwin_all/tart.app/Contents/Resources/UPW Tart.icns
        dst: tart.app/Contents/Resources/UPW Tart.icns
      - src: dist/tart_darwin_all/tart.app/Contents/Resources/Assets.car
        dst: tart.app/Contents/Resources/Assets.car
      - src: dist/tart_darwin_all/tart.app/Contents/_CodeSignature/CodeResources
        dst: tart.app/Contents/_CodeSignature/CodeResources
      - LICENSE

release:
  prerelease: auto

brews:
  - name: tart
    directory: Formula
    repository:
      owner: openai
      name: homebrew-tools
      token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
      branch: "tart-{{ .Version }}"
      pull_request:
        enabled: true
    caveats: |
      Tart has been installed. You might want to reduce the default DHCP lease time
      from 86,400 to 600 seconds to avoid DHCP shortage when running lots of VMs daily:

        sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.InternetSharing.default.plist bootpd -dict DHCPLeaseTimeSecs -int 600

      See https://tart.run/faq/#changing-the-default-dhcp-lease-time for more details.
    homepage: https://github.com/openai/tart
    license: FSL-1.1-ALv2
    description: Run macOS and Linux VMs on Apple Hardware
    skip_upload: auto
    dependencies:
      - "openai/tools/softnet"
    install: |
      libexec.install Dir["*"]
      bin.write_exec_script "#{libexec}/tart.app/Contents/MacOS/tart"
    custom_block: |
      on_macos do
        depends_on :macos => :ventura
      end
      def post_install
        generate_completions_from_executable(libexec/"tart.app/Contents/MacOS/tart", "--generate-completion-script")
      end
