name: Copy EasyDutch as Back-up

on:
  schedule:
    - cron: "00 06 1/14 * *"
  workflow_dispatch:

# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-only-cancel-in-progress-jobs-or-runs-for-the-current-workflow
concurrency: 
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  publish:
    name: Update EasyDutch
    runs-on: ubuntu-latest
    steps:
      - name: Clone EasyDutch as Back-up
        uses: actions/checkout@v3
        with: 
          ref: master
      - name: Copy EasyDutch to AdBlockFilters
        run: |
          TMPFILE=$(mktemp -d)
          git clone --depth=1 --single-branch --branch=main https://github.com/EasyDutch-uBO/EasyDutch.git $TMPFILE
          cp $TMPFILE/EasyDutch/*.txt easylistdutch/
          cp $TMPFILE/EasyDutch.txt EasyDutch.txt
          cp $TMPFILE/.github/*.yml .github/
          cp $TMPFILE/.github/*.md .github/
          cp $TMPFILE/.github/ISSUE_TEMPLATE/*.yml .github/ISSUE_TEMPLATE/
          # cp $TMPFILE/.github/workflows/*.yml .github/workflows/
          # cp $TMPFILE/tools/*.template tools/
          # cp $TMPFILE/tools/*.sh tools/
          # cp $TMPFILE/tools/*.mjs tools/
          cp $TMPFILE/.gitattribute* .gitattributes
          cp $TMPFILE/CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md
          cp $TMPFILE/CONTRIBUTING.md CONTRIBUTING.md
          cp $TMPFILE/LICENS* LICENSE
          cp $TMPFILE/README.md README.md
      - name: Commit changes (if any)
        run: |
          if [[ -n $(git diff) ]]; then
            git config user.name "JohnyP36"
            git config user.email "<>"
            git add -u easylistdutch/ EasyDutch.txt .github/ .github/ISSUE_TEMPLATE/ .gitattributes CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE README.md 
            git commit -m "Updated from @EasyDutch-uBO"
            git ls-files -z | while read -d '' path; do touch -d $(git log -1 --format="@%ct" "$path") "$path"; done
            git push origin master
          fi
