From bb84ab5aefc4a2e162f9ee164dc3bb01daf1aa49 Mon Sep 17 00:00:00 2001 From: SinachPat Date: Sat, 15 Aug 2026 14:08:45 +0100 Subject: [PATCH] ci: bidirectional mirror between GitHub and Gitea --- .gitea/workflows/mirror.yml | 22 ++++++++++++++++++++++ .github/workflows/mirror.yml | 22 ++++++++++++++++++++++ scripts/mirror.sh | 22 ++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 .gitea/workflows/mirror.yml create mode 100644 .github/workflows/mirror.yml create mode 100755 scripts/mirror.sh diff --git a/.gitea/workflows/mirror.yml b/.gitea/workflows/mirror.yml new file mode 100644 index 0000000..0a8c512 --- /dev/null +++ b/.gitea/workflows/mirror.yml @@ -0,0 +1,22 @@ +name: Mirror to GitHub + +on: + push: + branches: [main] + +concurrency: + group: mirror + cancel-in-progress: true + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Reconcile with GitHub + run: bash scripts/mirror.sh + env: + MIRROR_URL: https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/SinachPat/wursor.git diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 0000000..0465737 --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,22 @@ +name: Mirror to Gitea + +on: + push: + branches: [main] + +concurrency: + group: mirror + cancel-in-progress: true + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Reconcile with Gitea + run: bash scripts/mirror.sh + env: + MIRROR_URL: https://x-access-token:${{ secrets.GITEA_TOKEN }}@git.weown.tools/Wursor/s004.git diff --git a/scripts/mirror.sh b/scripts/mirror.sh new file mode 100755 index 0000000..a007461 --- /dev/null +++ b/scripts/mirror.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +BRANCH="${BRANCH:-main}" + +git config user.name "mirror-bot" +git config user.email "mirror-bot@noreply.local" + +git remote remove mirror 2>/dev/null || true +git remote add mirror "$MIRROR_URL" + +git fetch origin "$BRANCH" +git fetch mirror "$BRANCH" + +if git rev-parse --verify -q "mirror/$BRANCH" >/dev/null; then + if ! git merge-base --is-ancestor "mirror/$BRANCH" HEAD; then + git merge --no-edit "mirror/$BRANCH" + fi +fi + +git push origin "HEAD:$BRANCH" +git push mirror "HEAD:$BRANCH"