name: "Test @notesnook/core"

on:
  workflow_dispatch:
  push:
    branches:
      - "master"
    paths:
      - "packages/core/**"
      # re-run workflow if workflow file changes
      - ".github/workflows/core.tests.yml"
  pull_request:
    types:
      - "ready_for_review"
      - "opened"
      - "synchronize"
      - "reopened"

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Setup Node
        uses: ./.github/actions/setup-node-with-cache

      - name: Prepare environment
        run: |
          npm ci --ignore-scripts --prefer-offline --no-audit
          npm run bootstrap -- --scope=core
      - name: Add environment variables
        run: |
          echo "USER_EMAIL=${{ secrets.USER_EMAIL }}" >> $GITHUB_ENV
          echo "USER_PASSWORD=${{ secrets.USER_PASSWORD }}" >> $GITHUB_ENV
          echo "USER_TOTP_SECRET=${{ secrets.USER_TOTP_SECRET }}" >> $GITHUB_ENV
          echo "USER_HASHED_PASSWORD=${{ secrets.USER_HASHED_PASSWORD }}" >> $GITHUB_ENV
          echo "NX_CLOUD_ACCESS_TOKEN=${{ secrets.NX_CLOUD_ACCESS_TOKEN }}" >> $GITHUB_ENV

      - name: Run all @notesnook/core tests
        run: npx nx test:e2e @notesnook/core
