name: Ansible Integration Test Runner

on:
  schedule:
    # * is a special character in YAML so you have to quote this string
    - cron:  '0 1 * * *'

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up Python 3.7
      uses: actions/setup-python@v1
      with:
        python-version: 3.7
    - name: Install ansible and collection dependencies
      run: |
        python -m pip install --upgrade pip
        pip install ansible
        pip install -r requirements.txt
    - name: Build and install collection
      run: |
        ansible-galaxy collection build .
        ansible-galaxy collection install *.gz
    - name: Add service account file
      env:
        SERVICE_ACCOUNT_FILE: ${{ secrets.SERVICE_ACCOUNT_FILE }}
      run: |
        echo "$SERVICE_ACCOUNT_FILE" > /tmp/service_account.json
    - name: Add test template
      env:
        TEST_SETTINGS_TEMPLATE: ${{ secrets.TEST_SETTINGS_TEMPLATE }}
      run: |
        pushd ~/.ansible/collections/ansible_collections/google/cloud
        echo "$TEST_SETTINGS_TEMPLATE" > tests/integration/cloud-config-gcp.ini
    - name: Run the tests
      run: |
        pushd ~/.ansible/collections/ansible_collections/google/cloud
        ansible-test integration -v --allow-unsupported --continue-on-error $(find tests/integration/targets -name "gcp*" -type d -printf "%P ")
