# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support documentation.
# This workflow will download a prebuilt Python version, install dependencies and run integration tests

name: Run Integration Tests

on:
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  integration_test:
    name: Build and Run Integration Tests on Python ${{ matrix.python-version }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version: ["3.11"]
        os: [ubuntu-latest]

    steps:
      - uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install Python dependencies (ubuntu)
        run: |
          pip3 install -r requirements.txt
          pip3 install -r requirements-dev.txt
          pip3 install --editable .

      - name: Execute Python integration tests
        # continue-on-error: true
        env:
          NATURAL_LANGUAGE_UNDERSTANDING_APIKEY: ${{ secrets.NLU_APIKEY }}
          NATURAL_LANGUAGE_UNDERSTANDING_URL: "https://api.us-south.natural-language-understanding.watson.cloud.ibm.com"
          SPEECH_TO_TEXT_APIKEY: ${{ secrets.STT_APIKEY }}
          SPEECH_TO_TEXT_URL: "https://api.us-south.speech-to-text.watson.cloud.ibm.com"
          TEXT_TO_SPEECH_APIKEY: ${{ secrets.TTS_APIKEY }}
          TEXT_TO_SPEECH_URL: "https://api.us-south.text-to-speech.watson.cloud.ibm.com"
          ASSISTANT_APIKEY: ${{ secrets.WA_APIKEY }}
          ASSISTANT_WORKSPACE_ID: ${{ secrets.WA_WORKSPACE_ID }}
          ASSISTANT_ASSISTANT_ID: ${{ secrets.WA_ASSISTANT_ID }}
          ASSISTANT_URL: "https://api.us-south.assistant.watson.cloud.ibm.com"
          DISCOVERY_V2_APIKEY: ${{ secrets.D2_APIKEY }}
          DISCOVERY_V2_PROJECT_ID: ${{ secrets.D2_PROJECT_ID }}
          DISCOVERY_V2_COLLECTION_ID: ${{ secrets.D2_COLLECTION_ID }}
          DISCOVERY_V2_URL: "https://api.us-south.discovery.watson.cloud.ibm.com"
        run: |
          pip3 install -U python-dotenv
          pytest test/integration/test_discovery_v2.py -rap
          pytest test/integration/test_natural_language_understanding_v1.py -rap
          pytest test/integration/test_speech_to_text_v1.py -rap
          pytest test/integration/test_text_to_speech_v1.py -rap

        # Do not notify on success.  We will leave the code here just in case we decide to switch gears
      - name: Notify slack on success
        if: false # success()
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
        uses: voxmedia/github-action-slack-notify-build@v1
        with:
          channel: watson-e2e-tests
          status: SUCCESS
          color: good

      - name: Notify slack on failure
        if: false # failure()
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
        uses: voxmedia/github-action-slack-notify-build@v1
        with:
          channel: watson-e2e-tests
          status: FAILED
          color: danger
