name: Sync to Codeberg
concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true
on:
  push:
  workflow_dispatch:
  schedule:
    - cron: "0 */6 * * *"

jobs:
  DetermineRunner:
    name: Determine Runner
    runs-on: ubuntu-latest
    outputs:
      runner: ${{ steps.set-runner.outputs.runner }}
    steps:
      - name: Determine which runner to use
        id: set-runner
        uses: benjaminmichaelis/get-soonest-available-runner@v1.1.0
        with:
          primary-runner: "self-hosted"
          fallback-runner: "ubuntu-latest"
          min-available-runners: 1
          github-token: ${{ env.GITHUB_TOKEN }}
        env:
          GITHUB_TOKEN: ${{ secrets.ETOKEN }}

  codeberg:
    name: Sync Codeberg and Github
    if: github.repository == 'Equicord/Equicord'
    needs: DetermineRunner
    runs-on: ${{ needs.DetermineRunner.outputs.runner }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: pixta-dev/repository-mirroring-action@674e65a7d483ca28dafaacba0d07351bdcc8bd75 # v1.1.1
        with:
          target_repo_url: "git@codeberg.org:thororen/Equicord.git"
          ssh_private_key: ${{ secrets.CODEBERG }}
