name: Coot CI Homebrew macOS

on:
  push:

jobs:

  build-coot-for-macos:

    runs-on: macos-latest

    steps:

    - name: Which brew?
      run:  which brew

    - name: Setup homebrew
      id:   setup-homebrew
      uses: Homebrew/actions/setup-homebrew@master

    - name: turn on brew analytics
      run:  brew analytics on

    - name: brew update
      run:  |
        brew update
        brew upgrade

    # I don't think that glfw is needed now (it is in the coot.rb file though)
    - name: Install Coot dependencies in Homebrew
      run:  >
         brew install boost boost-python3 brewsci/bio/clipper4coot
         brewsci/bio/raster3d brewsci/bio/ssm brewsci/bio/gemmi
         dwarfutils gsl rdkit pygobject3 gtk4 glm automake glfw
         py3cairo pygobject3

    - name: Get coot.rb file
      # try this modified version for now:
      # run:  wget https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/files/coot.rb
      # back to Yoshitaka Moriwaki version
      # run:  wget https://raw.githubusercontent.com/YoshitakaMo/homebrew-bio/coot/Formula/coot.rb
      # use the version on github:
      run: wget https://raw.githubusercontent.com/brewsci/homebrew-bio/refs/heads/develop/Formula/coot.rb

    - name: Compile Homebrew coot HEAD
      # don't stall waiting for user input to resolve the failed patch
      run:  NONINTERACTIVE=1 brew install ./coot.rb --HEAD || true > $HOME/brew.log >&2

    - name: Upload brew log
      uses: actions/upload-artifact@v4
      with:
        name: brew-log-package
        path: /Users/runner/Library/Logs/Homebrew/coot
        retention-days: 3

    - name: ls the executable in /opt/homebrew/bin
      run: ls -lt /opt/homebrew/bin

    # 20240911 this has stopped working.
    # - name: ls the install bin
    #   run: ls -lt /opt/homebrew/Cellar/coot/HEAD*/bin

    # the homebrew build is still broken
    # - name: Does it run?
    #   run: /opt/homebrew/bin/coot --no-graphics < /dev/null

