name: checks
on: [push]
jobs:
  checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version-file: .nvmrc
      - run: npm ci
      - run: npx playwright install --with-deps
      - run: npm run check:types
      - run: npm run check:lint
      - run: npm run check:format
      - run: npm test
      - run: npm run build
      - uses: actions/upload-artifact@v7
        with:
          path: dist/*

  build-website:
    if: github.ref == 'refs/heads/main'
    needs: checks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version-file: .nvmrc
      - run: npm install
      - run: npm run build:example
      - if: github.ref == 'refs/heads/main'
        uses: actions/upload-pages-artifact@v5
        with:
          path: example/dist/

  deploy-website:
    if: github.ref == 'refs/heads/main'
    needs: [checks, build-website]
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - id: deployment
        uses: actions/deploy-pages@v5
