name: Purge jsDelivr cache

on:
  push:
    branches: [main]
    paths:
      - "blocklist.txt"
      - "dist/**"
      - "README.md"

permissions:
  contents: read

jobs:
  purge:
    runs-on: ubuntu-latest
    steps:
      - name: Purge published files
        shell: bash
        run: |
          files=(
            blocklist.txt
            dist/adblock.txt
            dist/domains.txt
            dist/hosts.txt
            dist/dnsmasq.conf
            dist/unbound.conf
            dist/blocklist.rpz
            dist/blocklist.json
            dist/blocklist.csv
            README.md
          )
          for file in "${files[@]}"; do
            url="https://purge.jsdelivr.net/gh/hapara-fail/blocklist@main/${file}"
            echo "Purging ${url}"
            curl --fail --show-error --silent --output /dev/null "$url"
          done
