name: Mirror to Codeberg

on:
  push:
    branches:
      - main

jobs:
  mirror:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0   

      - name: Set up SSH
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.CODEBERG_SSH_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan codeberg.org >> ~/.ssh/known_hosts

      - name: Push to Codeberg
        run: |
          git remote remove codeberg || true
          git remote add codeberg git@codeberg.org:SecureBitChat/securebit-chat.git
          git push codeberg main --force
