Files
nix-config/.github/workflows/mirror_to_gitee.yml
T
Ryan Yin 94312fc2e5 ci: bound and retry the Gitee mirror push
Gitee's SSH gateway intermittently accepts the connection and key, then never
answers the initial git-receive-pack and drops the session ~100s later with
"the remote end hung up upon initial contact". The same failure mode shows up
sporadically since 2026-10-02 and spiked on 2026-10-07 (9 of 14 runs failed).

Bound each push attempt with `timeout`, retry up to six times with exponential
backoff, and add ssh connect/keepalive timeouts. Serialize runs (a push to main
and a tag on the same commit used to race for Gitee's per-repo push lock), cap
the job at 30 minutes, and allow manual workflow_dispatch reruns.
2026-10-07 19:02:46 +08:00

76 lines
2.9 KiB
YAML

name: Mirror this repo to Gitee
on:
push:
branches:
- main
tags:
- "*"
workflow_dispatch:
permissions:
contents: read
# A push to main and a tag on the same commit each trigger a run. Queue them so
# two runs never race for Gitee's per-repo push lock.
concurrency:
group: mirror-to-gitee
cancel-in-progress: false
jobs:
mirror:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
with:
fetch-depth: 0
- name: Pin the Gitee host key
run: |
mkdir -p ~/.ssh
cat > ~/.ssh/known_hosts <<'HOSTS'
gitee.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEKxHSJ7084RmkJ4YdEi5tngynE8aZe2uEoVVsB/OvYN
gitee.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMzG3r+88lWSDK9fyjcZmYsWGDBDmGoAasKMAmjoFloGt9HRQX2Qp4f9FY2XK/hsHYinvoh5Xytl9iaUNUWMfYR8q6VEMtOO87DgoAFcfKZHt0/nbAg9RoNTKYt6v8tPwYpr7N0JP/01nE4LFsNDnstr6H0bXSAzbKWCETLZfdPV4l2uSpRn3bU0ugoZ0aSKz5Dc/IloBfGCTvkSsxUydMRd/Chpjt6VxncDbp+Fa6pzsseK8OQzrg6Fgc5783EN3EQqZ2skqyCwExtx95BJlfx1B3luZnWfpkwNDnrZRT/Qx0OrWqyf0q6f9uQr+UG1S8qDcUn3e/9onq3rwBri8/
HOSTS
chmod 600 ~/.ssh/known_hosts
- name: Mirror repo to Gitee
id: mirror-to-gitee
shell: bash
env:
INPUT_SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_GITEE_MIRROR }}
INPUT_TARGET_REPO_URL: git@gitee.com:ryan_yin/nix-config.git
run: |
set -eu
echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -o ConnectTimeout=20 -o ServerAliveInterval=20 -o ServerAliveCountMax=3"
git remote add mirror "$INPUT_TARGET_REPO_URL"
# Gitee's SSH gateway intermittently accepts the connection and key,
# then never answers the initial git-receive-pack and drops the
# session about 100s later ("the remote end hung up upon initial
# contact"). Bound each attempt so a stuck session cannot hang the
# job, and retry with backoff.
attempts=6
for attempt in $(seq 1 "$attempts"); do
echo "::group::Mirror attempt $attempt/$attempts"
if timeout --kill-after=15s 120s \
git push --tags --force --prune mirror "refs/remotes/origin/*:refs/heads/*"; then
echo "::endgroup::"
echo "Mirrored to Gitee on attempt $attempt"
exit 0
fi
echo "::endgroup::"
if [ "$attempt" -lt "$attempts" ]; then
delay=$((15 * 2 ** (attempt - 1)))
echo "Attempt $attempt failed; retrying in ${delay}s"
sleep "$delay"
fi
done
echo "::error::failed to mirror to Gitee after $attempts attempts" >&2
exit 1