name: Weblets Cypress Tests

on:
  workflow_dispatch:
  schedule:
    - cron: "0 6 * * *"

jobs:
  cypress-run:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: "yarn"
      - name: Yarn deps
        run: |
          yarn
          lerna run build --no-private
          cd packages/weblets
          yarn deps
      - name: Generate SSH Key
        run: |
          ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519
      - name: Write the cypress.env.json file
        run: |
          echo '${{ secrets.TFCHAIN_MNEMONICS }}' > packages/weblets/cypress.env.json
      - name: Cypress run
        uses: cypress-io/github-action@v5.7.1
        env:
          NODE_OPTIONS: "--max-old-space-size=8192 --openssl-legacy-provider"
        with:
          browser: chrome
          start: yarn workspace @threefold/weblets serve:app
          wait-on: "http://localhost:8080/"
          wait-on-timeout: 500
          project: ./packages/weblets
