name: check
on:
  workflow_dispatch:
  pull_request:
    types: [opened, synchronize, reopened, edited]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 2
      - uses: tj-actions/changed-files@v12.2
        id: files
        with:
          files: 'streams'
      - uses: actions/setup-node@v2
        if: ${{ !env.ACT && steps.files.outputs.any_changed == 'true' }}
        with:
          node-version: '14'
          cache: 'npm'
      - name: download data from api
        if: steps.files.outputs.any_changed == 'true'
        run: |
          mkdir -p scripts/data
          curl -L -o scripts/data/blocklist.json https://iptv-org.github.io/api/blocklist.json
          curl -L -o scripts/data/channels.json https://iptv-org.github.io/api/channels.json
      - name: validate
        if: steps.files.outputs.any_changed == 'true'
        run: |
          npm install
          npm run playlist:lint -- ${{ steps.files.outputs.all_changed_files }}
          npm run playlist:validate -- ${{ steps.files.outputs.all_changed_files }}