Files
wecom-ai-assistant/scripts/setup-github-secrets.ps1
2026-02-05 16:48:35 +08:00

128 lines
4.2 KiB
PowerShell
Raw Permalink 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.
# GitHub Secrets 配置辅助脚本
# 用途:帮助生成 SSH 密钥并准备配置 GitHub Secrets
Write-Host "=== GitHub Secrets 配置辅助工具 ===" -ForegroundColor Cyan
Write-Host ""
# 检查是否已有 SSH 密钥
$sshKeyPath = "$env:USERPROFILE\.ssh\github-actions-deploy"
$sshKeyPubPath = "$sshKeyPath.pub"
Write-Host "检查 SSH 密钥..." -ForegroundColor Yellow
$useExisting = $false
if (Test-Path $sshKeyPath) {
Write-Host "✓ 找到现有 SSH 密钥: $sshKeyPath" -ForegroundColor Green
$regenerate = Read-Host "是否重新生成? (y/n)"
if ($regenerate -eq "y" -or $regenerate -eq "Y") {
Remove-Item $sshKeyPath -Force -ErrorAction SilentlyContinue
Remove-Item $sshKeyPubPath -Force -ErrorAction SilentlyContinue
} else {
$useExisting = $true
}
}
if (-not $useExisting) {
Write-Host ""
Write-Host "生成新的 SSH 密钥对..." -ForegroundColor Yellow
ssh-keygen -t ed25519 -C "github-actions-deploy" -f $sshKeyPath -N '""'
Write-Host "✓ SSH 密钥已生成" -ForegroundColor Green
}
# 显示密钥信息
Write-Host ""
Write-Host "=== SSH 密钥信息 ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "1. 私钥(需要添加到 GitHub Secrets 的 PROD_SSH_KEY:" -ForegroundColor Yellow
Write-Host "---" -ForegroundColor Gray
Get-Content $sshKeyPath
Write-Host "---" -ForegroundColor Gray
Write-Host ""
Write-Host "2. 公钥(需要添加到生产服务器的 ~/.ssh/authorized_keys:" -ForegroundColor Yellow
Write-Host "---" -ForegroundColor Gray
Get-Content $sshKeyPubPath
Write-Host "---" -ForegroundColor Gray
Write-Host ""
# 保存到文件
$privKeyFile = "github-actions-deploy.key"
$pubKeyFile = "github-actions-deploy.pub"
Copy-Item $sshKeyPath $privKeyFile -Force
Copy-Item $sshKeyPubPath $pubKeyFile -Force
Write-Host "✓ 密钥已保存到项目根目录:" -ForegroundColor Green
Write-Host " - $privKeyFile (私钥)" -ForegroundColor Gray
Write-Host " - $pubKeyFile (公钥)" -ForegroundColor Gray
Write-Host ""
Write-Host "⚠ 注意: 请妥善保管私钥文件,不要提交到 Git" -ForegroundColor Red
Write-Host ""
# 生成配置清单
Write-Host "=== GitHub Secrets 配置清单 ===" -ForegroundColor Cyan
Write-Host ""
$secretsGuide = @"
访 GitHub Secrets:
https://github.com/bujie9527/wecom-ai-assistant/settings/secrets/actions
Secrets:
1. PROD_HOST
: [ IP]
: IP
2. PROD_USER
: [SSH root ubuntu]
: SSH
3. PROD_SSH_KEY
: []
: SSH GitHub Actions
4. PROD_DOMAIN
: [: api.yourdomain.com]
:
5. PROD_SSH_PORT ()
: 22
: SSH 22
6. PROD_APP_PATH ()
: /opt/wecom-ai-assistant
:
:
1. "New repository secret"
2. Name Secret
3. "Add secret"
4. Secrets
Workflow :
1. : Settings Actions General
2. "Workflow permissions"
3. "Read and write permissions"
4. "Save"
"@
$secretsGuide | Out-File "GITHUB_SECRETS_SETUP.md" -Encoding UTF8
Write-Host $secretsGuide
Write-Host ""
Write-Host "=== 下一步操作 ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "1. 将公钥添加到生产服务器:" -ForegroundColor Yellow
Write-Host " ssh user@your-server" -ForegroundColor Gray
Write-Host " mkdir -p ~/.ssh" -ForegroundColor Gray
Write-Host " echo '$(Get-Content $pubKeyFile)' >> ~/.ssh/authorized_keys" -ForegroundColor Gray
Write-Host " chmod 600 ~/.ssh/authorized_keys" -ForegroundColor Gray
Write-Host ""
Write-Host "2. 配置 GitHub Secrets:" -ForegroundColor Yellow
Write-Host " 查看文件: GITHUB_SECRETS_SETUP.md" -ForegroundColor Gray
Write-Host " 或访问: https://github.com/bujie9527/wecom-ai-assistant/settings/secrets/actions" -ForegroundColor Gray
Write-Host ""
Write-Host "3. 测试 SSH 连接:" -ForegroundColor Yellow
Write-Host " ssh -i $privKeyFile user@your-server" -ForegroundColor Gray
Write-Host ""