name: Expensive e2e tests
on:
  push:
    branches:
      - main
  # allows manual run on github actions
  workflow_dispatch:
  schedule:
    - cron: "0 6 * * 1-5"

jobs:
  end-to-end-tests:
    name: Expensive e2e tests
    strategy:
      matrix:
        grafana_version:
          - 10.3.0
          - 11.2.0
          - latest
      fail-fast: false
      # Run one version at a time to avoid the issue when SMS notification are bundled together for multiple versions
      # running at the same time (the affected test is in grafana-plugin/e2e-tests/alerts/sms.test.ts)
      max-parallel: 1
    uses: ./.github/workflows/e2e-tests.yml
    with:
      grafana_version: ${{ matrix.grafana_version }}
      run-expensive-tests: true
      browsers: "chromium"
    secrets: inherit

  post-status-to-slack:
    runs-on: ubuntu-latest
    needs: end-to-end-tests
    if: failure()
    steps:
      # Useful references
      # https://stackoverflow.com/questions/59073850/github-actions-get-url-of-test-build
      # https://github.com/orgs/community/discussions/26822#discussioncomment-3305794
      #
      - uses: slackapi/slack-github-action@v1.24.0
        with:
          channel-id: gops-irm-dev
          # yamllint disable rule:line-length
          payload: |
            {
              "blocks": [
                {
                  "type": "section",
                  "text": {
                    "type": "mrkdwn",
                    "text": "Daily e2e tests build result: ${{ needs.end-to-end-tests.result == 'success' && ':check:' || ':alert:' }}\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
                  }
                }
              ]
            }
          # yamllint enable rule:line-length
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_DAILY_E2E_TESTS_BOT_TOKEN }}
