name: Mirror to GitLab

on:
  push:
    branches: ['**']   # all branches
    tags: ['**']       # all tags (includes releases)
  delete:              # also synchronise branch/tag deletions

jobs:
  mirror:
    name: Push mirror
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0   # full history required

      - name: Push mirror to GitLab
        run: |
          git remote add gitlab \
            https://oauth2:${GITLAB_TOKEN}@gitlab.com/open-works/chromatography.git

          # Push branches without force — GitLab forbids force-push on the
          # default branch and rejects --prune when it would delete it.
          git push gitlab \
            "refs/heads/*:refs/heads/*"

          # Push tags with force so re-created tags are synced correctly.
          git push gitlab --force \
            "refs/tags/*:refs/tags/*"
        env:
          GITLAB_TOKEN: ${{ secrets.GITLAB_MIRROR_TOKEN }}