name: npx

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]
  schedule:
    - cron: '0 0 * * *' # every day at 00:00 UTC
  workflow_dispatch: # allow manual triggering

jobs:
  npx:
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/master'
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 24.x
      - run: npm ci
      - run: npm run build
      - uses: cypress-io/github-action@v7
        with:
          build: npm install --global scrabble-solver@latest
          start: scrabble-solver
          wait-on: 'http://localhost:3333'
        env:
          CYPRESS_BASE_URL: http://localhost:3333
      - uses: actions/upload-artifact@v7
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
          if-no-files-found: ignore
