name: "Clone everything"
description: "Checks out the repo, and initializes submodules. Must check out repo first."

inputs:
  access-token:
    description: "Private pods access token"
    required: false

runs:
  using: "composite"

  steps:
    - id: checkout_repo
      name: Checkout Repo
      uses: actions/checkout@v6
      with:
        # Check out submodules through GitHub instead of from scratch later.
        # THIS STEP WILL FAIL if the current Pods commit is only available in Private.
        # However, we can continue and the build will still pass.
        submodules: recursive
      continue-on-error: ${{ inputs.access-token != '' }}

    - id: private_pods_ref
      name: Compute Private Pods Ref
      if: ${{ steps.checkout_repo.outcome == 'failure' }}
      shell: bash
      run: echo "ref=$(git ls-tree --object-only HEAD Pods)" >> "$GITHUB_OUTPUT"

    # Checkout private pods repo iff we have an access token to read private repos
    - name: Checkout Private Pods
      uses: actions/checkout@v6
      if: ${{ steps.checkout_repo.outcome == 'failure' }}
      with:
        repository: signalapp/Signal-Pods-Private
        token: ${{ inputs.access-token }}
        path: Pods
        ref: ${{ steps.private_pods_ref.outputs.ref }}

    - id: message_backup_tests_ref
      name: Compute Signal-Message-Backup-Tests Ref
      if: ${{ steps.checkout_repo.outcome == 'failure' }}
      shell: bash
      run: echo "ref=$(git ls-tree --object-only HEAD SignalServiceKit/tests/MessageBackup/Signal-Message-Backup-Tests)" >> "$GITHUB_OUTPUT"

    - name: Checkout Signal-Message-Backup-Tests
      uses: actions/checkout@v6
      if: ${{ steps.checkout_repo.outcome == 'failure' }}
      with:
        repository: signalapp/Signal-Message-Backup-Tests
        path: SignalServiceKit/tests/MessageBackup/Signal-Message-Backup-Tests
        ref: ${{ steps.message_backup_tests_ref.outputs.ref }}

    - name: Fetch RingRTC
      shell: bash
      run: make fetch-ringrtc
