name: sync list to dist

on:
  push:
    branches: 
      - 'master'
    paths: 
      - 'anti-ad-**.*'
      - 'adblock-for-dnsmasq.conf'
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: clone the website
      run: git clone https://github.com/privacy-protection-tools/anti-ad.github.io.git ~/website
    - name: copy some list files
      run: |
        cp ./anti-ad-easylist.txt ~/website/docs/easylist.txt
        cp ./anti-ad-easylist.txt.md5 ~/website/docs/easylist.txt.md5
        cp ./anti-ad-adguard.txt ~/website/docs/adguard.txt
        cp ./anti-ad-adguard.txt.md5 ~/website/docs/adguard.txt.md5
        cp ./adblock-for-dnsmasq.conf ~/website/docs/dnsmasq.conf
        cp ./adblock-for-dnsmasq.conf ~/website/docs/anti-ad-for-dnsmasq.conf
        cp ./anti-ad-smartdns.conf ~/website/docs/anti-ad-for-smartdns.conf
        cp ./anti-ad-surge.txt ~/website/docs/surge.txt
        cp ./anti-ad-surge2.txt ~/website/docs/surge2.txt
        cp ./anti-ad-clash.yaml ~/website/docs/clash.yaml
        cp ./anti-ad-domains.txt ~/website/docs/domains.txt
    - name: Commit files
      run: |
        cd ~/website
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        git add .
        git commit -m "pull newest list." -a
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.PERSON_TOKEN }}
        branch: 'master'
        directory: '/home/runner/website'
        repository: 'privacy-protection-tools/anti-ad.github.io'