# TODO(toby): Combine this workflow with the deploy workflow so that these
#   end-to-end tests can block prod deploy if they fail.
#   Do this after this workflow has run successfully in parallel to reduce
#   risk of breaking deploys.
name: End-to-End Tests

on:
  push:
    branches:
      - main

# Runner itself is not run directly as part of our stack. Instead, it is a
# dependency of web-preview. This means we must do a little back-and-forth to
# run end-to-end tests against the latest changes to runner.
# 1. Trigger a deploy of web-preview to testing1. This action executes on the
#    web-preview repository. Wait for this to complete successfully.
# 2. Run the end-to-end tests against testing1. At this point, the latest
#    changes to runner should be present on that environment.
jobs:
  deploy-web-preview:
    name: Deploy web-preview to testing1.adalo.com

    runs-on: ubuntu-latest

    steps:
      - name: Send dispatch to invoke Web Preview testing deployment
        uses: AdaloHQ/dispatch-and-wait@master
        with:
          owner: AdaloHQ
          repo: web-preview
          token: ${{secrets.GH_ACTIONS_TOKEN}}
          event_type: deploy-testing
          client_payload: '{"sha": "${{ github.sha }}"}'
          wait_time: 10
          max_time: 900

  e2e-tests:
    needs: deploy-web-preview
    uses: AdaloHQ/e2e-tests/.github/workflows/e2e-tests-reusable.yml@main
    secrets: inherit
