From dd8a5356e15b791c9e92cb5d5f556e94e0711f59 Mon Sep 17 00:00:00 2001 From: Igor Krauch <243803173+igareck@users.noreply.github.com> Date: Fri, 28 Aug 2026 23:55:12 -0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B5=D1=80=D0=BA=D0=B0=D0=BB=D0=BE=20/?= =?UTF-8?q?=20Mirror=20to=20Bitbucket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Зеркало на Bitbucket.org Mirror on Bitbucket.org Switch Bitbucket mirror to fast-forward updates. --- .github/workflows/mirror-to-bitbucket.yml | 101 ++++++++++++++-------- 1 file changed, 67 insertions(+), 34 deletions(-) diff --git a/.github/workflows/mirror-to-bitbucket.yml b/.github/workflows/mirror-to-bitbucket.yml index db32430e83..dfe58c55b7 100644 --- a/.github/workflows/mirror-to-bitbucket.yml +++ b/.github/workflows/mirror-to-bitbucket.yml @@ -6,6 +6,7 @@ on: - main workflow_dispatch: + concurrency: group: mirror-to-bitbucket cancel-in-progress: false @@ -19,50 +20,82 @@ jobs: timeout-minutes: 20 steps: - - name: Checkout GitHub repository + - name: Checkout latest GitHub main uses: actions/checkout@v6 with: - fetch-depth: 0 + ref: main + fetch-depth: 1 + path: source + persist-credentials: false - - name: Configure Git identity - run: | - git config user.name "github-actions" - git config user.email "github-actions@github.com" - - - name: Adapt repository for Bitbucket mirror - run: | - set -euo pipefail - - # Replace main README only in the temporary GitHub Actions checkout. - curl -fsSL "https://raw.githubusercontent.com/igareck/GoldCaviar/main/Files/README-BITBUCKET.md" -o README.md - - test -s README.md - - # Remove README variants that render poorly in Bitbucket. - git rm -f README-EN-US.md README-FA-IR.md README-ZH-CN.md 2>/dev/null || true - - git add README.md - - if ! git diff --cached --quiet; then - git commit -m "Adapt README files for Bitbucket mirror" - else - echo "No Bitbucket README adaptation changes" - fi - - - name: Push main branch to Bitbucket + - name: Clone current Bitbucket main env: BITBUCKET_TOKEN: ${{ secrets.BITBUCKET_MIRROR_TOKEN }} run: | set -euo pipefail - git remote remove bitbucket 2>/dev/null || true - git remote add bitbucket "https://x-token-auth:${BITBUCKET_TOKEN}@bitbucket.org/igareck/vpn-configs-for-russia.git" + test -n "$BITBUCKET_TOKEN" + + git clone \ + --depth=1 \ + --single-branch \ + --branch=main \ + --no-tags \ + "https://x-token-auth:${BITBUCKET_TOKEN}@bitbucket.org/igareck/vpn-configs-for-russia.git" \ + mirror + + git -C mirror config user.name "github-actions" + git -C mirror config user.email "github-actions@github.com" + + - name: Synchronize GitHub snapshot onto Bitbucket main + id: prepare + run: | + set -euo pipefail + + source_dir="${GITHUB_WORKSPACE}/source" + mirror_dir="${GITHUB_WORKSPACE}/mirror" + + rsync -a --delete --exclude='.git/' "$source_dir/" "$mirror_dir/" + + curl -fsSL \ + "https://raw.githubusercontent.com/igareck/GoldCaviar/main/Files/README-BITBUCKET.md" \ + -o "$mirror_dir/README.md" + test -s "$mirror_dir/README.md" + + rm -f \ + "$mirror_dir/README-EN-US.md" \ + "$mirror_dir/README-FA-IR.md" \ + "$mirror_dir/README-ZH-CN.md" + + git -C "$mirror_dir" add -A + + if git -C "$mirror_dir" diff --cached --quiet; then + echo "Bitbucket already matches the adapted GitHub snapshot" + echo "changed=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + source_sha=$(git -C "$source_dir" rev-parse HEAD) + source_subject=$(git -C "$source_dir" log -1 --format=%s) + + git -C "$mirror_dir" commit \ + -m "$source_subject" \ + -m "Mirrored from GitHub commit ${source_sha}" + + echo "changed=true" >> "$GITHUB_OUTPUT" + + - name: Push fast-forward update to Bitbucket + if: steps.prepare.outputs.changed == 'true' + run: | + set -euo pipefail + + cd "${GITHUB_WORKSPACE}/mirror" for attempt in 1 2 3 4 5; do - echo "Bitbucket push attempt $attempt/5" + echo "Bitbucket fast-forward push attempt ${attempt}/5" - if git push bitbucket HEAD:main --force; then - echo "Bitbucket push successful" + if git push origin main; then + echo "Bitbucket fast-forward push successful" exit 0 fi @@ -71,5 +104,5 @@ jobs: sleep "$sleep_time" done - echo "Bitbucket push failed after all retries" + echo "Bitbucket push failed after all retries" >&2 exit 1