name: Localisation Merge
on:
  schedule:
    - cron: '0 4 * * *'
jobs:
  merge-localisation:
    name: Merge Localisation
    if: github.repository == 'OpenRCT2/OpenRCT2'
    runs-on: ubuntu-latest
    steps:
      - name: Store private SSH
        run: |
          echo "Store private SSH deploy key..."
          mkdir -p ~/.ssh
          echo "${{ secrets.OPENRCT2_DEPLOY_KEY }}" > ~/.ssh/id_rsa
          chmod 700 ~/.ssh
          chmod 600 ~/.ssh/id_rsa
      - name: Clone repositories
        run: |
          echo "Cloning repositories..."
          git clone -b master --depth 1 git@github.com:OpenRCT2/Localisation.git Localisation
          git clone -b develop git@github.com:OpenRCT2/OpenRCT2.git OpenRCT2
      - name: Copy over language files
        run: |
          echo "Copying language files..."
          for f in ./Localisation/data/language/*
          do
              filename=$(basename $f)
              cp $f "./OpenRCT2/data/language/$filename"
          done
      - name: Commit and push
        working-directory: OpenRCT2
        run: |
          if [[ $(git status --porcelain) ]]; then
              echo "Committing and pushing..."
              git add .
              git config --global user.name "OpenRCT2 git bot"
              git config --global user.email "gitbot@openrct2.org"
              git commit -m "Merge Localisation/master into OpenRCT2/develop"
              git push
              echo "Complete"
          else
              echo "No changes to merge."
          fi
