chore: refine sync_to_enterprise.yml by improving error handling during repo cloning and enhancing commit configuration

This commit is contained in:
wood911010 committed 2026-03-13 20:41:43 +08:00
1 parent 1fb4940625
commit 224d36dcf1
1 file changed
+17 -25
+17 -25
View File
@@ -15,47 +15,39 @@ jobs:
with:
fetch-depth: 0
- name: Debug info
env:
TOKEN: ${{ secrets.ENTERPRISE_REPO_TOKEN }}
run: |
echo "=== Debug Info ==="
echo "Token prefix: ${TOKEN:0:10}"
# 用 gh API 检查仓库是否存在
echo "Checking repo via API..."
curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/cedar-v/license-manager-enterprise" | head -20
echo ""
echo "Checking user repos..."
curl -s -H "Authorization: token $TOKEN" \
"https://api.github.com/user/repos?per_page=100" | grep -o '"full_name":"[^"]*license-manager[^"]*"' || echo "No matching repo found"
- name: Sync to enterprise repo
env:
TOKEN: ${{ secrets.ENTERPRISE_REPO_TOKEN }}
run: |
# 直接用认证 URL clone 和 push
# 设置 git config
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# 用认证 URL
REPO_URL="https://x-access-token:$TOKEN@github.com/cedar-v/license-manager-enterprise.git"
echo "Cloning enterprise repo..."
git clone "$REPO_URL" /tmp/enterprise-repo || {
echo "Clone failed!"
exit 1
git clone "$REPO_URL" /tmp/enterprise-repo 2>/dev/null || {
mkdir -p /tmp/enterprise-repo
cd /tmp/enterprise-repo
git init
git remote add origin "$REPO_URL"
}
cd /tmp/enterprise-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
echo "Copying files..."
# 复制新文件覆盖
rm -rf .git
cd "$GITHUB_WORKSPACE"
cp -r . /tmp/enterprise-repo/
cd /tmp/enterprise-repo
git init
git add -A
git commit -m "Sync from license-manager - $(date)" || echo "Nothing to commit"
git -c "user.email=github-actions[bot]@users.noreply.github.com" \
-c "user.name=github-actions[bot]" \
commit -m "Sync from license-manager - $(date)" || echo "Nothing to commit"
git push origin master --force
echo "Done!"