|
| 1 | +name: Mirror to GitLab |
| 2 | + |
| 3 | +# Non-destructive backup mirror of GitHub -> GitLab. |
| 4 | +# GitLab Free no longer offers native pull mirroring, so we drive the mirror |
| 5 | +# from the GitHub side. Runs on every push to master/main and on tag pushes. |
| 6 | +# |
| 7 | +# Design notes: |
| 8 | +# * No --force, no --mirror, no --prune. This job only ever *adds* to GitLab; |
| 9 | +# it never deletes branches/tags there and never rewrites its history. |
| 10 | +# Deleting the GitHub repo simply stops future pushes; GitLab keeps its state. |
| 11 | +# * A history rewrite (force-push) on GitHub will make this job FAIL rather |
| 12 | +# than silently overwrite the backup -- that is intentional for a backup. |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + - main |
| 19 | + tags: |
| 20 | + - '**' |
| 21 | + workflow_dispatch: {} |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: gitlab-mirror-${{ github.ref }} |
| 25 | + cancel-in-progress: false |
| 26 | + |
| 27 | +jobs: |
| 28 | + mirror: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - name: Checkout (full history + tags) |
| 32 | + uses: actions/checkout@v7 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + fetch-tags: true |
| 36 | + |
| 37 | + - name: Push ref to GitLab |
| 38 | + env: |
| 39 | + GITLAB_MIRROR_TOKEN: ${{ secrets.GITLAB_MIRROR_TOKEN }} |
| 40 | + run: | |
| 41 | + set -euo pipefail |
| 42 | +
|
| 43 | + if [ -z "${GITLAB_MIRROR_TOKEN}" ]; then |
| 44 | + echo "::error::GITLAB_MIRROR_TOKEN secret is not set; cannot mirror." >&2 |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + remote="https://oauth2:${GITLAB_MIRROR_TOKEN}@gitlab.com/Xor-el/HashLib4Pascal.git" |
| 49 | +
|
| 50 | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then |
| 51 | + echo "Mirroring tag ${GITHUB_REF_NAME} to GitLab" |
| 52 | + git push "${remote}" "refs/tags/${GITHUB_REF_NAME}" |
| 53 | + else |
| 54 | + echo "Mirroring branch ${GITHUB_REF_NAME} (and all tags) to GitLab" |
| 55 | + git push "${remote}" "HEAD:refs/heads/${GITHUB_REF_NAME}" |
| 56 | + git push "${remote}" --tags |
| 57 | + fi |
| 58 | +
|
| 59 | + echo "Mirror push completed." |
0 commit comments