-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
102 lines (89 loc) · 3.56 KB
/
deploy.ps1
File metadata and controls
102 lines (89 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# GitHub Pages 部署脚本
# 使用方法:在 PowerShell 中运行此脚本
Write-Host "=== PyTorch 教程博客 GitHub Pages 部署脚本 ===" -ForegroundColor Cyan
Write-Host ""
# 检查是否在正确的目录
$currentDir = Get-Location
Write-Host "当前目录: $currentDir" -ForegroundColor Yellow
# 检查必要文件是否存在
$requiredFiles = @("index.html", "styles.css", "script.js")
$missingFiles = @()
foreach ($file in $requiredFiles) {
if (-not (Test-Path $file)) {
$missingFiles += $file
}
}
if ($missingFiles.Count -gt 0) {
Write-Host "错误: 缺少以下文件:" -ForegroundColor Red
foreach ($file in $missingFiles) {
Write-Host " - $file" -ForegroundColor Red
}
Write-Host ""
Write-Host "请确保在项目根目录运行此脚本" -ForegroundColor Red
exit 1
}
Write-Host "✓ 所有必要文件都存在" -ForegroundColor Green
Write-Host ""
# 初始化 Git 仓库(如果还没有)
if (-not (Test-Path .git)) {
Write-Host "初始化 Git 仓库..." -ForegroundColor Yellow
git init
Write-Host "✓ Git 仓库已初始化" -ForegroundColor Green
} else {
Write-Host "✓ Git 仓库已存在" -ForegroundColor Green
}
Write-Host ""
# 添加文件
Write-Host "添加文件到 Git..." -ForegroundColor Yellow
git add .
Write-Host "✓ 文件已添加" -ForegroundColor Green
Write-Host ""
# 检查是否有未提交的更改
$status = git status --porcelain
if ($status) {
Write-Host "创建提交..." -ForegroundColor Yellow
git commit -m "Update: PyTorch tutorial blog website"
Write-Host "✓ 提交已创建" -ForegroundColor Green
} else {
Write-Host "没有需要提交的更改" -ForegroundColor Yellow
}
Write-Host ""
# 检查远程仓库
$remote = git remote get-url origin 2>$null
if ($remote) {
Write-Host "远程仓库: $remote" -ForegroundColor Cyan
Write-Host ""
Write-Host "推送到 GitHub..." -ForegroundColor Yellow
git push origin main 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ 代码已推送到 GitHub" -ForegroundColor Green
} else {
Write-Host "尝试推送到 master 分支..." -ForegroundColor Yellow
git push origin master 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ 代码已推送到 GitHub" -ForegroundColor Green
} else {
Write-Host "推送失败,请手动执行: git push -u origin main" -ForegroundColor Red
}
}
} else {
Write-Host "未配置远程仓库" -ForegroundColor Yellow
Write-Host ""
Write-Host "请按照以下步骤操作:" -ForegroundColor Cyan
Write-Host "1. 在 GitHub 上创建新仓库" -ForegroundColor White
Write-Host "2. 仓库名建议: 你的用户名.github.io" -ForegroundColor White
Write-Host "3. 执行以下命令连接远程仓库:" -ForegroundColor White
Write-Host " git remote add origin https://github.com/YOUR_USERNAME/YOUR_USERNAME.github.io.git" -ForegroundColor Gray
Write-Host " git branch -M main" -ForegroundColor Gray
Write-Host " git push -u origin main" -ForegroundColor Gray
Write-Host ""
Write-Host "或者运行此脚本后手动执行上述命令" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "=== 部署完成 ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "下一步:" -ForegroundColor Yellow
Write-Host "1. 在 GitHub 仓库设置中启用 Pages" -ForegroundColor White
Write-Host "2. 选择 main 分支和 / (root) 文件夹" -ForegroundColor White
Write-Host "3. 等待几分钟后访问: https://YOUR_USERNAME.github.io" -ForegroundColor White
Write-Host ""