name: Deployment on pietervdvn
on:
  push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup and validate themes
        uses: ./.github/actions/setup-and-validate

      - name: Clone deployment repo
        env:
          DEPLOY_KEY_PIETERVDVN: ${{ secrets.DEPLOY_KEY_PIETERVDVN }}
        run: |
          echo "Cloning destination repo"
          git config --global user.email "pietervdvn@posteo.net"
          git config --global user.name "pietervdvn"
          git clone --depth 1 --single-branch --branch master "https://x-access-token:$DEPLOY_KEY_PIETERVDVN@github.com/pietervdvn/pietervdvn.github.io.git"
          echo "Destination repo is cloned"

      - name: Sync repo
        env:
          DEPLOY_KEY_PIETERVDVN: ${{ secrets.DEPLOY_KEY_PIETERVDVN }}
        run: |
          cd pietervdvn.github.io
          git pull

      - name: "Copying files"
        run: |
          echo "Deploying"
          TARGET=${GITHUB_REF:11}
          rm -rf pietervdvn.github.io/mc/$TARGET/*
          mkdir -p pietervdvn.github.io/mc/$TARGET/
          cp -r dist/* pietervdvn.github.io/mc/$TARGET/
          cd pietervdvn.github.io/
          git add *
          if git status | grep -q "Changes to be committed"
          then
            git commit -am "Deploying a new version of mapcomplete"
            git push
          else
            echo "No changes to commit"
          fi
