name: Validation

on:
    pull_request:

    push:
        branches: [main]
        paths:
            - "domains/*"
            - "tests/*"
            - "util/*"
            - ".github/workflows/validation.yml"
            - "dnsconfig.js"

    workflow_dispatch:

concurrency:
    group: ${{ github.ref }}-validation
    cancel-in-progress: true

jobs:
    dns:
        name: DNS
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4

            - name: Check
              uses: is-a-dev/dnscontrol-action@main
              with:
                  args: check

    tests:
        name: Tests
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4

            - uses: actions/checkout@v4
              with:
                  repository: is-a-dev/register
                  path: register-${{ github.run_id }}

            - run: npm install

            - name: Get all modified domain JSON files
              if: github.event_name == 'pull_request'
              id: changed-files
              uses: tj-actions/changed-files@v45
              with:
                  files: domains/*.json

            - name: Run tests
              run: npx ava tests/*.test.js
              env:
                  EVENT: ${{ github.event_name }}
                  RUN_ID: ${{ github.run_id }}
                  PR_AUTHOR: ${{ github.event.pull_request.user.login }}
                  MODIFIED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
