Skip to content

Commit 0812e3b

Browse files
committed
1
1 parent 8142afe commit 0812e3b

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

.github/workflows/sync-to-theme-repo.yml

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,33 @@ jobs:
5151
git commit -m "Clean posts directory and remove workflows for theme sync"
5252
fi
5353
54-
- name: Check if target repository exists and push
54+
- name: Setup SSH and push to target repository
5555
env:
56-
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
56+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
5757
run: |
58-
# 检查是否设置了PAT_TOKEN
59-
if [ -z "$PAT_TOKEN" ]; then
60-
echo "❌ PAT_TOKEN secret not found!"
61-
echo "Please create a Personal Access Token and add it as PAT_TOKEN secret"
62-
echo "Token needs 'repo' permissions to push to the target repository"
58+
# 检查是否设置了SSH_PRIVATE_KEY
59+
if [ -z "$SSH_PRIVATE_KEY" ]; then
60+
echo "❌ SSH_PRIVATE_KEY secret not found!"
61+
echo "Please add your SSH private key as SSH_PRIVATE_KEY secret"
62+
echo "Generate SSH key: ssh-keygen -t rsa -b 4096 -C 'your_email@example.com'"
63+
echo "Add public key to GitHub: https://github.com/settings/keys"
6364
exit 1
6465
fi
6566
66-
# 设置目标仓库URL
67-
TARGET_REPO="https://github.com/fishcpy/astro-theme-fishcpy.git"
67+
# 设置SSH密钥
68+
mkdir -p ~/.ssh
69+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
70+
chmod 600 ~/.ssh/id_rsa
6871
69-
# 检查目标仓库是否存在(如果检查失败也继续执行)
70-
echo "🔍 Checking if target repository exists..."
71-
REPO_CHECK=$(curl -s -H "Authorization: token $PAT_TOKEN" \
72-
"https://api.github.com/repos/fishcpy/astro-theme-fishcpy")
72+
# 添加GitHub到known_hosts
73+
ssh-keyscan github.com >> ~/.ssh/known_hosts
7374
74-
if echo "$REPO_CHECK" | grep -q '"name"'; then
75-
echo "✅ Target repository exists and is accessible"
76-
elif echo "$REPO_CHECK" | grep -q '"message.*Not Found"'; then
77-
echo "❌ Target repository not found"
78-
echo "Please ensure the repository exists: https://github.com/fishcpy/astro-theme-fishcpy"
79-
echo "If it exists, check PAT token permissions (needs 'repo' scope)"
80-
exit 1
81-
else
82-
echo "⚠️ Cannot verify repository existence (may be private)"
83-
echo "Proceeding with push attempt..."
84-
fi
75+
# 测试SSH连接
76+
echo "🔍 Testing SSH connection to GitHub..."
77+
ssh -T git@github.com || echo "SSH connection test completed"
8578
86-
# 添加远程仓库
87-
git remote add theme-repo https://x-access-token:$PAT_TOKEN@github.com/fishcpy/astro-theme-fishcpy.git
79+
# 添加远程仓库(使用SSH)
80+
git remote add theme-repo git@github.com:fishcpy/astro-theme-fishcpy.git
8881
8982
# 推送到目标仓库
9083
echo "🚀 Pushing to target repository..."
@@ -96,17 +89,10 @@ jobs:
9689
echo "🗑️ Cleaned posts directory (kept only markdown.md)"
9790
echo "🗑️ Removed all workflow files (.github directory)"
9891
echo "📝 Updated banner.enable to true"
99-
echo "🔄 Pushed with commit history to https://github.com/fishcpy/astro-theme-fishcpy.git"
100-
echo ""
101-
echo "📋 Setup Instructions (if this was your first run):"
102-
echo "1. Create Personal Access Token: https://github.com/settings/tokens"
103-
echo "2. Add token as PAT_TOKEN secret in repository settings"
104-
echo "3. Ensure target repository exists: https://github.com/fishcpy/astro-theme-fishcpy"own.md)"
105-
echo "🗑️ Removed all workflow files (.github directory)"
106-
echo "📝 Updated banner.enable to true"
107-
echo "🔄 Pushed with commit history to https://github.com/fishcpy/astro-theme-fishcpy.git"
92+
echo "🔄 Pushed with commit history to git@github.com:fishcpy/astro-theme-fishcpy.git"
10893
echo ""
10994
echo "📋 Setup Instructions (if this was your first run):"
110-
echo "1. Create Personal Access Token: https://github.com/settings/tokens"
111-
echo "2. Add token as PAT_TOKEN secret in repository settings"
112-
echo "3. Ensure target repository exists: https://github.com/fishcpy/astro-theme-fishcpy"
95+
echo "1. Generate SSH key: ssh-keygen -t rsa -b 4096 -C 'your_email@example.com'"
96+
echo "2. Add public key to GitHub: https://github.com/settings/keys"
97+
echo "3. Add private key as SSH_PRIVATE_KEY secret in repository settings"
98+
echo "4. Ensure target repository exists: https://github.com/fishcpy/astro-theme-fishcpy"

0 commit comments

Comments
 (0)