name: Setup for Apple
description: Sets up caches for builds and CocoaPods, and runs `pod install`
inputs:
  project-directory:
    description: The path to the root of the project directory
    required: true
    type: string
  working-directory:
    description: The directory where commands are run
    required: true
    type: string

runs:
  using: composite
  steps:
    - name: Generate cache key
      id: cache-key-generator
      run: |
        if [[ -f ${{ inputs.working-directory }}/${{ inputs.project-directory }}/Podfile.lock ]]; then
          echo "cache-key=$(basename ${{ inputs.working-directory }})-$(node scripts/shasum.mjs ${{ inputs.working-directory }}/${{ inputs.project-directory }}/Podfile.lock)" >> $GITHUB_OUTPUT
        else
          echo 'cache-key=false' >> $GITHUB_OUTPUT
        fi
      shell: bash
    - name: Cache /.ccache
      if: ${{ steps.cache-key-generator.outputs.cache-key != 'false' }}
      uses: actions/cache@v3
      with:
        path: .ccache
        key: ccache-${{ runner.os }}-${{ steps.cache-key-generator.outputs.cache-key }}
        restore-keys: ccache-${{ runner.os }}-${{ inputs.project-directory }}-
    - name: Cache ${{ inputs.working-directory }}/${{ inputs.project-directory }}/Pods
      if: ${{ steps.cache-key-generator.outputs.cache-key != 'false' }}
      uses: actions/cache@v3
      with:
        path: ${{ inputs.working-directory }}/${{ inputs.project-directory }}/Pods
        key: pods-${{ runner.os }}-${{ steps.cache-key-generator.outputs.cache-key }}
    - name: Install Pods
      run: |
        pod install --project-directory=${{ inputs.project-directory }}
      shell: bash
      working-directory: ${{ inputs.working-directory }}
