name: Build

on:
  push:
    branches:
      - development
    tags-ignore:
      - '**'
  pull_request:
    branches:
      - development
  # Allow manual dispatch in GH
  workflow_dispatch:

permissions:
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup node
        uses: actions/setup-node@v4
        with:
          node-version-file: .nvmrc
      - name: Install NPM dependencies
        run: npm ci
      - name: Build
        run: npm run build
      - name: Test
        run: npm test
      - name: Lint
        run: npm run lint
      # Create recursivelly the destiantion dir with
      # "--parrents where no error if existing, make parent directories as needed."
      - run: mkdir -p ./build/${{ github.head_ref || github.ref_name }}
      - name: Deploy to GitHub Pages
        if: github.event.pull_request.head.repo.fork == false && github.actor != 'dependabot[bot]'
        uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./build
          # in stremio, we use `feat/features-name` or `fix/this-bug`
          # so we need a recursive creation of the destination dir
          destination_dir: ${{ github.head_ref || github.ref_name }}
          allow_empty_commit: true
