name: Trigger Cloud Regression E2E Tests
on:
  push:
    branches: [master]
    paths:
      - 'CMakeLists.txt'
      - '**.c'
      - '**.cc'
      - '**.cpp'
      - '**.h'
      - 'mqtt_websockets/**'
      - 'aclk/aclk-schemas/**'
jobs:
  trigger_cloud_regression_tests:
    runs-on: ubuntu-latest
    if: github.repository == 'netdata/netdata'
    steps:
      - name: Evaluate workflow dispatch parameters
        env:
          PR_REPO_NAME: ${{ github.event.pull_request.head.repo.full_name }}
          PR_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
          PR_COMMIT_HASH: ${{ github.event.pull_request.head.sha }}
        id: output-workflow-dispatch-params
        run: |
          if [ ${{ github.event_name }} == 'pull_request_target' ]; then
            NETDATA_CUSTOM_REPO="$PR_REPO_NAME"
            NETDATA_CUSTOM_BRANCH="$PR_BRANCH_NAME"
            NETDATA_CUSTOM_PR_NUMBER="${{ github.event.number }}"
            NETDATA_CUSTOM_COMMIT_HASH="$PR_COMMIT_HASH"
          elif [ ${{ github.event_name }} == 'push' ]; then
            NETDATA_CUSTOM_REPO="netdata/netdata"
            NETDATA_CUSTOM_BRANCH="master"
            NETDATA_CUSTOM_PR_NUMBER=""
            NETDATA_CUSTOM_COMMIT_HASH="${{ github.sha }}"
          fi
          echo "netdata_repo=${NETDATA_CUSTOM_REPO}" >> $GITHUB_OUTPUT
          echo "netdata_branch=${NETDATA_CUSTOM_BRANCH}" >> $GITHUB_OUTPUT
          echo "netdata_pr_number=${NETDATA_CUSTOM_PR_NUMBER}" >> $GITHUB_OUTPUT
          echo "netdata_commit_hash=${NETDATA_CUSTOM_COMMIT_HASH}" >> $GITHUB_OUTPUT

      - name: Trigger Full Cloud Regression
        uses: aurelien-baudet/workflow-dispatch@v2
        with:
          repo: netdata/test-automation
          ref: refs/heads/master
          workflow: regression.yml
          token: ${{ secrets.NETDATABOT_GITHUB_TOKEN  }}
          inputs: '{ "netdata_branch": "${{ steps.output-workflow-dispatch-params.outputs.netdata_branch }}",
               "netdata_repo": "${{ steps.output-workflow-dispatch-params.outputs.netdata_repo }}",
               "netdata_pr_number": "${{ steps.output-workflow-dispatch-params.outputs.netdata_pr_number }}",
               "netdata_branch_commit_hash": "${{ steps.output-workflow-dispatch-params.outputs.netdata_commit_hash }}",
               "custom_netdata_image": "true"
               }'
          wait-for-completion: false

      - name: Trigger Agent Parent/Child with Cloud Integration tests
        uses: aurelien-baudet/workflow-dispatch@v2
        with:
          repo: netdata/test-automation
          ref: refs/heads/master
          workflow: agent_smoke_tests.yml
          token: ${{ secrets.NETDATABOT_GITHUB_TOKEN  }}
          inputs: '{ "netdata_branch": "${{ steps.output-workflow-dispatch-params.outputs.netdata_branch }}",
               "netdata_repo": "${{ steps.output-workflow-dispatch-params.outputs.netdata_repo }}",
               "netdata_pr_number": "${{ steps.output-workflow-dispatch-params.outputs.netdata_pr_number }}",
               "netdata_branch_commit_hash": "${{ steps.output-workflow-dispatch-params.outputs.netdata_commit_hash }}",
               "custom_netdata_image": "true"
               }'
          wait-for-completion: true
