name: pod try GoogleMaps

on:
  schedule:
    - cron: '0 */2 * * *'

jobs:
  check_pod_try:
    # The type of runner that the job will run on
    runs-on: macos-latest

    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - name: Checkout maps-sdk-for-ios-samples
      uses: actions/checkout@v2

    # Install CocoaPods v 1.6.1. Need to use this version since there are issues with running `pod try` on later versions
    - name: Install CocoaPods 1.6.1
      run: | 
        sudo gem install cocoapods -v 1.6.1

    # Copy pod try results to current copy
    - name: Copy pod try GoogleMaps changes into current copy
      run: |
        POD_TRY_DIR="$(pod _1.6.1_ try GoogleMaps | tail -1 | awk '{print $2}' | echo "/$(cut -d\/ -f2-11)")"
        echo "Copying contents of '$POD_TRY_DIR' into '$GITHUB_WORKSPACE/GoogleMaps'"
        cp -R $POD_TRY_DIR/* $GITHUB_WORKSPACE/GoogleMaps/.
        echo "Checking diff"
        git diff $GITHUB_WORKSPACE
      
    # Commit changes
#    - name: PR Changes
#      uses: peter-evans/create-pull-request@v2

name: pod try GoogleMaps

on:
  schedule:
    - cron: '0 */2 * * *'

jobs:
  check_pod_try:
    # The type of runner that the job will run on
    runs-on: macos-latest

    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - name: Checkout maps-sdk-for-ios-samples
      uses: actions/checkout@v2

    # Install CocoaPods v 1.6.1. Need to use this version since there are issues with running `pod try` on later versions
    - name: Install CocoaPods 1.6.1
      run: | 
        sudo gem install cocoapods -v 1.6.1

    # Copy pod try results to current copy
    - name: Copy pod try GoogleMaps changes into current copy
      run: |
        POD_TRY_DIR="$(pod _1.6.1_ try GoogleMaps | tail -1 | awk '{print $2}' | echo "/$(cut -d\/ -f2-11)")"
        echo "Copying contents of '$POD_TRY_DIR' into '$GITHUB_WORKSPACE/GoogleMaps'"
        cp -R $POD_TRY_DIR/* $GITHUB_WORKSPACE/GoogleMaps/.
        echo "Checking diff"
        git diff $GITHUB_WORKSPACE
      
    # Commit changes
    - name: PR Changes
      uses: peter-evans/create-pull-request@v2
      with: 
        token: ${{ secrets.ACTION_GITHUB_TOKEN }}
        commit-message: 'chore: Update GoogleMaps samples from CocoaPods'
        committer: googlemaps-bot <googlemaps-bot@google.com>
        author: googlemaps-bot <googlemaps-bot@google.com>
        title: 'chore: Update GoogleMaps samples from CocoaPods'
        body: |
          Pulling in changes from `pod try GoogleMaps` into this repo.

Create a PR for pod try GoogleMaps changes
build: Create a PR for pod try GoogleMaps changes