name: 'Prepare for Deployment'
description: 'Setup all required dependencies and secrets for the given release channel'

inputs:
  channel:
    description: 'Release Channel'
    required: true

  # Secret Keys
  appstore-connect-key:
    description: 'App Store Connect API Key'
    required: false
    default: ''
  ghcr-actor:
    description: 'GitHub Container Registry Actor'
    required: false
    default: ''
  ghcr-token:
    description: 'GitHub Container Registry Token'
    required: false
    default: ''
  google-play-key:
    description: 'Google Play Store API Key'
    required: false
    default: ''

runs:
  using: composite
  steps:
    - name: Checkout Repository
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Prepare Folders
      shell: bash
      run: |
        mkdir -p output
        mkdir -p keys

    - name: Install Ruby
      if: ${{ inputs.channel == 'play-store' || inputs.channel == 'app-store' }}
      uses: ruby/setup-ruby@v1
      with:
        bundler-cache: true
    
    - name: Install XCode
      if: ${{ inputs.channel == 'app-store' }}
      uses: maxim-lobanov/setup-xcode@v1
      with:
        xcode-version: latest-stable

    - name: Set up Docker Buildx
      if: ${{ inputs.channel == 'docker' }}
      uses: docker/setup-buildx-action@v1

    - name: Setup GitHub Package Registry
      if: ${{ inputs.channel == 'docker' }}
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ inputs.ghcr-actor }}
        password: ${{ inputs.ghcr-token }}

    - name: Setup Secret Keys
      shell: bash
      run: |
        echo ${{ inputs.appstore-connect-key }} | base64 --decode > keys/appstore.p8
        echo ${{ inputs.google-play-key }} | base64 --decode > keys/googleplay.json

    - name: Setup Android Platform
      if: ${{ inputs.channel == 'play-store' }}
      shell: bash
      run: |
        cd android && bundle install

    - name: Setup iOS Platform
      if: ${{ inputs.channel == 'app-store' }}
      shell: bash
      run: |
        cd ios && bundle install
      
    - name: Setup macOS Platform
      if: ${{ inputs.channel == 'app-store' }}
      shell: bash
      run: |
        cd macos && bundle install
