- name: Download Kiln macOS disk image
  get_url:
    url: "https://github.com/Kiln-AI/Kiln/releases/download/{{ courseware_kiln_release_tag }}/Kiln.MacOS.AppleSilicon.M-Processor.dmg"
    dest: "{{ courseware_downloads_dir }}/Kiln.MacOS.AppleSilicon.M-Processor.dmg"
    mode: "0644"

- name: Install Kiln.app into project state
  shell: |
    set -euo pipefail
    mount_point=$(mktemp -d /tmp/kiln.XXXXXX)
    hdiutil attach "{{ courseware_downloads_dir }}/Kiln.MacOS.AppleSilicon.M-Processor.dmg" -mountpoint "$mount_point" -nobrowse -quiet
    app_path=$(find "$mount_point" -maxdepth 1 -name '*.app' | head -n 1)
    rm -rf "{{ courseware_apps_dir }}/Kiln.app"
    cp -R "$app_path" "{{ courseware_apps_dir }}/Kiln.app"
    hdiutil detach "$mount_point" -quiet
    rmdir "$mount_point"
  args:
    executable: /bin/bash
    creates: "{{ courseware_apps_dir }}/Kiln.app"
