name: 'Build Unsigned Mac Binaries'

on:
  workflow_dispatch:
  workflow_call:
    inputs:
      ref:
        description: 'The branch, tag, or SHA to build from.'
        required: true
        type: 'string'

permissions:
  contents: 'read'

defaults:
  run:
    shell: 'bash'

jobs:
  build-mac:
    name: 'Build Unsigned (${{ matrix.arch }})'
    runs-on: 'macos-latest'
    strategy:
      fail-fast: false
      matrix:
        arch: ['x64', 'arm64']

    steps:
      - name: 'Checkout'
        uses: 'actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5' # ratchet:actions/checkout@v4
        with:
          ref: '${{ inputs.ref || github.ref }}'
          persist-credentials: false

      - name: 'Set up Node.js'
        uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' # ratchet:actions/setup-node@v4
        with:
          node-version-file: '.nvmrc'
          architecture: '${{ matrix.arch }}'
          cache: 'npm'

      - name: 'Install dependencies'
        run: 'npm ci'

      - name: 'Build Binary'
        env:
          SKIP_SIGNING: 'true'
        run: 'npm run build:binary'

      - name: 'Verify Output Exists'
        run: |
          if [ -f "dist/darwin-${{ matrix.arch }}/gemini" ]; then
            echo "Binary found at dist/darwin-${{ matrix.arch }}/gemini"
          else
            echo "Error: Binary not found in dist/darwin-${{ matrix.arch }}/"
            ls -R dist/
            exit 1
          fi

      - name: 'Upload Artifact'
        uses: 'actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02' # ratchet:actions/upload-artifact@v4
        with:
          name: 'gemini-darwin-${{ matrix.arch }}-unsigned'
          path: 'dist/darwin-${{ matrix.arch }}/gemini'
          retention-days: 14
