name: 🔨 Build Test

on:
  pull_request:
    paths:
      - "**.go"
      - "**.mod"
  workflow_dispatch:
    inputs:
      short:
        description: "Use -short flag for tests"
        required: false
        type: boolean
        default: false

jobs:
  lint:
    name: Lint Test
    if: "${{ !endsWith(github.actor, '[bot]') }}"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: projectdiscovery/actions/setup/go@v1
      - uses: projectdiscovery/actions/golangci-lint/v2@v1

  build:
    name: Test Builds
    needs: [lint]
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macOS-latest]
    steps:
      - uses: actions/checkout@v6
      - uses: projectdiscovery/actions/setup/go@v1
      - run: go build ./...

      - name: Run tests
        env:
          BEVIGIL_API_KEY: ${{secrets.BEVIGIL_API_KEY}}
          BINARYEDGE_API_KEY: ${{secrets.BINARYEDGE_API_KEY}}
          BUFFEROVER_API_KEY: ${{secrets.BUFFEROVER_API_KEY}}
          C99_API_KEY: ${{secrets.C99_API_KEY}}
          CENSYS_API_KEY: ${{secrets.CENSYS_API_KEY}}
          CERTSPOTTER_API_KEY: ${{secrets.CERTSPOTTER_API_KEY}}
          CHAOS_API_KEY: ${{secrets.CHAOS_API_KEY}}
          CHINAZ_API_KEY: ${{secrets.CHINAZ_API_KEY}}
          DNSDB_API_KEY: ${{secrets.DNSDB_API_KEY}}
          DNSREPO_API_KEY: ${{secrets.DNSREPO_API_KEY}}
          FOFA_API_KEY: ${{secrets.FOFA_API_KEY}}
          FULLHUNT_API_KEY: ${{secrets.FULLHUNT_API_KEY}}
          GITHUB_API_KEY: ${{secrets.GITHUB_API_KEY}}
          INTELX_API_KEY: ${{secrets.INTELX_API_KEY}}
          LEAKIX_API_KEY: ${{secrets.LEAKIX_API_KEY}}
          QUAKE_API_KEY: ${{secrets.QUAKE_API_KEY}}
          ROBTEX_API_KEY: ${{secrets.ROBTEX_API_KEY}}
          SECURITYTRAILS_API_KEY: ${{secrets.SECURITYTRAILS_API_KEY}}
          SHODAN_API_KEY: ${{secrets.SHODAN_API_KEY}}
          THREATBOOK_API_KEY: ${{secrets.THREATBOOK_API_KEY}}
          URLSCAN_API_KEY: ${{secrets.URLSCAN_API_KEY}}
          VIRUSTOTAL_API_KEY: ${{secrets.VIRUSTOTAL_API_KEY}}
          WHOISXMLAPI_API_KEY: ${{secrets.WHOISXMLAPI_API_KEY}}
          ZOOMEYEAPI_API_KEY: ${{secrets.ZOOMEYEAPI_API_KEY}}
        uses: nick-fields/retry@v3
        with:
          timeout_seconds: 360
          max_attempts: 3
          command: go test ./... -v ${{ github.event.inputs.short == 'true' && '-short' || '' }}

      - name: Race Condition Tests
        run: go build -race ./...

      - name: Run Example
        run: go run .
        working-directory: examples
