name: E2E API Tests

# Controls when the action will run. Triggers the workflow on push or pull request
on:
  workflow_call:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  e2e_api:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    timeout-minutes: 80

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    - name: Setup kernel for react native, increase watchers
      run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
    
    - uses: actions/setup-node@v2
      with:
        node-version: '20.13.1'

    - uses: pnpm/action-setup@v2
      name: Install pnpm
      id: pnpm-install
      env:
        CI: false
      with:
        version: 8.9.0
        run_install: false

    - name: Get pnpm store directory
      id: pnpm-cache
      shell: bash
      run: |
        echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

    - uses: actions/cache@v3
      name: Setup pnpm cache
      with:
        path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
        key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
        restore-keys: |
          ${{ runner.os }}-pnpm-store-

    - name: Install dependencies
      run: pnpm install
      env:
        CI: false

    # Runs a set of commands using the runners shell
    - name: Run a test
      run: |
        pnpm test:api
