@@ -51,40 +51,33 @@ jobs:
51
51
git commit -m "Clean posts directory and remove workflows for theme sync"
52
52
fi
53
53
54
- - name : Check if target repository exists and push
54
+ - name : Setup SSH and push to target repository
55
55
env :
56
- PAT_TOKEN : ${{ secrets.PAT_TOKEN }}
56
+ SSH_PRIVATE_KEY : ${{ secrets.SSH_PRIVATE_KEY }}
57
57
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"
63
64
exit 1
64
65
fi
65
66
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
68
71
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
73
74
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"
85
78
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
88
81
89
82
# 推送到目标仓库
90
83
echo "🚀 Pushing to target repository..."
@@ -96,17 +89,10 @@ jobs:
96
89
echo "🗑️ Cleaned posts directory (kept only markdown.md)"
97
90
echo "🗑️ Removed all workflow files (.github directory)"
98
91
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"
108
93
echo ""
109
94
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