name: 'CIPD install'
description: 'Installs the specified CIPD package'
inputs:
  cipd-root-prefix-path:
    description: 'Path to prepend to installation directory'
    default: ''
  dependency:
    description: 'Name of dependency to install'
  deps-file:
    description: 'Location of DEPS file that defines the dependency'
  installation-dir:
    description: 'Location to install dependency'
  target-platform:
    description: 'Target platform, should be linux, win, macos'
  package:
    description: 'Package to install'
runs:
  using: "composite"
  steps:
    - name: Delete wrong ${{ inputs.dependency }}
      shell: bash
      run : |
        rm -rf ${{ inputs.cipd-root-prefix-path }}${{ inputs.installation-dir }}
    - name: Create ensure file for ${{ inputs.dependency }}
      shell: bash
      run: |
        echo '${{ inputs.package }}' `e d gclient getdep --deps-file=${{ inputs.deps-file }} -r '${{ inputs.installation-dir }}:${{ inputs.package }}'` > ${{ inputs.dependency }}_ensure_file
        cat ${{ inputs.dependency }}_ensure_file
    - name: CIPD installation of ${{ inputs.dependency }} (macOS)
      if: ${{ inputs.target-platform == 'macos' }}
      shell: bash
      run: |
        echo "ensuring ${{ inputs.dependency }} on macOS"
        e d cipd ensure --root ${{ inputs.cipd-root-prefix-path }}${{ inputs.installation-dir }} -ensure-file ${{ inputs.dependency }}_ensure_file
    - name: CIPD installation of ${{ inputs.dependency }} (Windows)
      if: ${{ inputs.target-platform == 'win' }}
      shell: powershell
      run: |
        echo "ensuring ${{ inputs.dependency }} on Windows"
        e d cipd ensure --root ${{ inputs.cipd-root-prefix-path }}${{ inputs.installation-dir }} -ensure-file ${{ inputs.dependency }}_ensure_file
