name: Sync to Gitea

on:
  push:
    branches:
      - main

jobs:
  sync:
    if: github.repository == 'community-scripts/ProxmoxVED'
    runs-on: ubuntu-latest

    steps:
     - name: Checkout source repo
       uses: actions/checkout@v4
       with:
        fetch-depth: 0
     - name: Set Git identity for actions
       run: |
        git config --global user.name "Push From Github"
        git config --global user.email "actions@github.com"
     - name: Add Gitea remote
       run: git remote add gitea https://$GITEA_USER:$GITEA_TOKEN@git.community-scripts.org/community-scripts/ProxmoxVED.git
       env:
         GITEA_USER: ${{ secrets.GITEA_USERNAME }}
         GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
     - name: Pull Gitea changes
       run: |
         git fetch gitea
         git merge --strategy=ours gitea/main
       env:
         GITEA_USER: ${{ secrets.GITEA_USERNAME }}
         GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
      
     - name: Push to Gitea
       run: git push gitea main --force
       env:
         GITEA_USER: ${{ secrets.GITEA_USERNAME }}
         GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
