name: 'BrowserStack Test'

on: [push, pull_request]

jobs:
  e2e-test:
    runs-on: ubuntu-latest

    steps:
      - name: 'BrowserStack Env Setup'
        uses: 'browserstack/github-actions/setup-env@master'
        with:
          username: ${{ secrets.BROWSERSTACK_USERNAME }}
          access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
          build-name: BUILD_INFO
          project-name: REPO_NAME
      - name: 'BrowserStackLocal Setup'
        uses: 'browserstack/github-actions/setup-local@master'
        with:
          local-testing: start
          local-identifier: random
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16.x'
      - run: npm ci
      - run: npx http-server -p 8099 &
      - run: npm run test:e2e
      - name: 'BrowserStackLocal Stop'
        uses: 'browserstack/github-actions/setup-local@master'
        with:
          local-testing: stop

name: 'BrowserStack Test'

on:
  workflow_run:
    workflows: ['CI']
    branches: [main]
    types:
      - completed

jobs:
  e2e-test:
    runs-on: ubuntu-latest

    steps:
      - name: 'BrowserStack Env Setup'
        uses: 'browserstack/github-actions/setup-env@master'
        with:
          username: ${{ secrets.BROWSERSTACK_USERNAME }}
          access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
          build-name: BUILD_INFO
          project-name: REPO_NAME
      - name: 'BrowserStackLocal Setup'
        uses: 'browserstack/github-actions/setup-local@master'
        with:
          local-testing: start
          local-identifier: random
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16.x'
      - run: npm ci
      - run: npx http-server -p 8099 &
      - run: npm run test:e2e
      - name: 'BrowserStackLocal Stop'
        uses: 'browserstack/github-actions/setup-local@master'
        with:
          local-testing: stop

Make E2E test workflow depend on CI workflow
Make E2E test workflow depend on CI workflow
