Files
iotlcm/.gitea/workflows/mirror-to-gitee.yml
T
MiFaZhan f7cab5ad5c
mirror-to-gitee / mirror (push) Successful in 14s
chore: 整合为单仓 iotlcm(12 个仓 → 1 个仓)
把原来 12 个独立仓合并为单仓多服务结构,各仓完整提交历史通过
read-tree 并入保留(137 个提交,blame 可追溯)。

目录:
  admin-svr/ admin-ui/ app/{server,app}/ openapi/ worker-svr/
  upstream-chan/ upstream-proxy/ sms/ bot/ docs/ onelink-mock/ deploy/

同时:
- 新增根 README(目录说明、快速开始、源码构建、镜像发布、许可)
- 新增根 Makefile(make build / test / images / docs)
- 新增根 .gitattributes / .gitignore,删掉 12 份重复的 Apache LICENSE
  (admin-ui/ 与 app/app/ 的 MIT 上游许可保留)
- 各服务的 .gitea/workflows 收敛到仓根:trigger-jenkins.yml(tag 构建全部
  服务)+ mirror-to-gitee.yml(自动建 Gitee 仓后镜像)
- 文档内跨仓绝对链接改为仓内相对路径;部署/构建文档改为单仓路径
2026-11-02 13:35:58 +08:00

81 lines
2.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: mirror-to-gitee
# 把本仓镜像到 Gitee 企业仓 <GITEE_OWNER>/<同名仓库>。
# 触发:main 分支推送、v* tag 推送、手动;另有每日兜底重试。
on:
push:
branches:
- main
tags:
- 'v*'
schedule:
# Gitea Actions 的 cron 用 UTC:18:30 UTC = 次日 02:30 北京时间
- cron: '30 18 * * *'
workflow_dispatch:
concurrency:
group: mirror-${{ github.ref }}
cancel-in-progress: true
jobs:
mirror:
runs-on: host
steps:
- name: 同步到 Gitee
env:
SRC_TOKEN: ${{ secrets.SRC_GIT_TOKEN }}
DST_TOKEN: ${{ secrets.GITEE_TOKEN }}
DST_OWNER: ${{ secrets.GITEE_OWNER }}
DST_USER: ${{ secrets.GITEE_USER }}
run: |
set -u
# 仓库名取当前仓;取不到时回退到单仓名
REPO_NAME="${GITHUB_REPOSITORY#*/}"
if [ -z "${REPO_NAME:-}" ] || [ "$REPO_NAME" = "${GITHUB_REPOSITORY:-}" ]; then
REPO_NAME="iotlcm"
fi
SRC="git.5iot.com/iotlcm-public/${REPO_NAME}.git"
DST="gitee.com/${DST_OWNER}/${REPO_NAME}.git"
echo "源:$SRC"
echo "目标:$DST"
# Gitee 不支持 push 建仓,目标仓不存在时先按企业 API 创建(已存在会报 400,忽略)
if ! git ls-remote "https://${DST_USER}:${DST_TOKEN}@${DST}" >/dev/null 2>&1; then
echo "目标仓不存在,尝试创建 ${DST_OWNER}/${REPO_NAME}"
curl -sS -X POST \
"https://gitee.com/api/v5/enterprises/${DST_OWNER}/repos?access_token=${DST_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{\"name\":\"${REPO_NAME}\",\"auto_init\":false,\"description\":\"iotLCM 物联网卡全生命周期管理平台(开源版)\"}" \
-o /tmp/repo-create.json -w '建仓 HTTP %{http_code}\n' || true
head -c 300 /tmp/repo-create.json 2>/dev/null; echo
else
echo "目标仓已存在"
fi
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
git clone --mirror "https://jenkins:${SRC_TOKEN}@${SRC%/}" "$WORK/repo.git"
cd "$WORK/repo.git"
echo "本地 ref:$(git for-each-ref --format='%(refname:short)' | tr '\n' ' ')"
# Gitee 在推送密集时会返回 429 Pending queue overflowed / 408 Authorization server timeout,
# 属服务端限流,退避重试即可。
attempt=0
while [ "$attempt" -lt 5 ]; do
attempt=$((attempt + 1))
echo "----- 推送尝试 $attempt/5"
if git push --mirror "https://${DST_USER}:${DST_TOKEN}@${DST}" 2>&1; then
echo "✅ 已同步到 Gitee"
exit 0
fi
wait_s=$((attempt * 30))
echo "推送失败,${wait_s}s 后重试"
sleep "$wait_s"
done
echo "❌ 连续 5 次推送失败,请检查 Gitee 状态或令牌"
exit 1