name: Auto rebuild anti-AD list

on:
  push:
    branches: [ adlist-maker ]
    paths:
      - '**.php'
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.1.1
      - name: co master
        uses: actions/checkout@v4.1.1
        with:
          ref: 'master'

      # Runs a set of commands using the runners shell
      - name: Run
        run: |
          git config --global user.email "action@github.com"
          git config --global user.name "GitHub Action[bot]"
          git checkout adlist-maker
          /bin/bash ./scripts/build-list.sh
          git stash -a
          git checkout master
          git checkout stash@{0}^3 -- adblock-for-dnsmasq.conf
          git checkout stash@{0}^3 -- anti-ad-*
          git add * -A
          git commit -am "Auto renew the anti-AD list."
          git stash clear
      - name: push
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.PERSON_TOKEN }}
          branch: 'master'
      - name: sync
        run: |
          curl -s -m 30 -X POST "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/workflows/sync-to-dist.yml/dispatches" -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.PERSON_TOKEN }}" -d '{"ref":"master"}'
      
