name: Push to Git mirrors

on:
  push:
    branches: [main]
    tags: ['**']
  workflow_dispatch:

concurrency:
  group: push-to-git-mirrors
  cancel-in-progress: false

jobs:
  mirrors:
    name: Push to mirrors
    runs-on: ubuntu-latest
    steps:
      - name: Checkout full history
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Push to Codeberg
        env:
          CODEBERG_USERNAME: ${{ secrets.CODEBERG_USERNAME }}
          CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
        run: |
          git remote add codeberg "https://${CODEBERG_USERNAME}:${CODEBERG_TOKEN}@codeberg.org/aliasvault/aliasvault.git"
          git push codeberg --force origin/main:refs/heads/main
          git push codeberg --tags --force

      - name: Push to GitLab
        if: always()
        env:
          GITLAB_USER: ${{ secrets.GITLAB_USER }}
          GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
        run: |
          git remote add gitlab "https://${GITLAB_USER}:${GITLAB_TOKEN}@gitlab.com/aliasvault/aliasvault.git"
          git push gitlab --force origin/main:refs/heads/main
          git push gitlab --tags --force
