Repository navigation
Expand file tree
/
Copy pathpush_aethercode.ps1
More file actions
137 lines (124 loc) · 5.77 KB
/
Copy pathpush_aethercode.ps1
File metadata and controls
137 lines (124 loc) · 5.77 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright (c) 2026 maijun
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# push_aethercode.ps1
# 一键 push AetherCode 到 GitHub (使用 fine-grained token)
# 用法: 在 PowerShell 里执行 .\push_aethercode.ps1
#
# 安全:
# - token 走 $env:GITHUB_TOKEN, 不会被记入 PowerShell history (默认 ReadLine)
# - 用完自动 Remove-Item Env:GITHUB_TOKEN
# - 这个脚本不含 token, 你需要单独设环境变量 (见下方)
$ErrorActionPreference = 'Stop'
Set-Location $env:AETHERCODE_ROOT
if (-not $env:AETHERCODE_ROOT) {
Set-Location 'D:\work\workspace\idea\engine\AetherCode'
}
Write-Host '=== AetherCode push helper ===' -ForegroundColor Cyan
Write-Host " Workspace: $(Get-Location)"
Write-Host " Branch: $(git branch --show-current)"
Write-Host " Commit: $(git log --oneline -1)"
Write-Host ''
# ================================================================
# 1. 设置 token (3 种方式,选一种)
# ================================================================
if (-not $env:GITHUB_TOKEN) {
Write-Host '=== Token 输入 ===' -ForegroundColor Cyan
Write-Host ' 方式 A: 直接粘贴 (会保存到 env var, session 结束自动清理)'
Write-Host ' 方式 B: 先在另一终端运行 `$env:GITHUB_TOKEN = "..."`,然后执行此脚本'
Write-Host ''
$sec = Read-Host ' GITHUB_TOKEN (粘贴 fine-grained token, 不会回显)'
if (-not $sec) {
Write-Host ' No token, aborting.' -ForegroundColor Red
exit 1
}
$env:GITHUB_TOKEN = $sec
}
# ================================================================
# 2. 验证 token
# ================================================================
Write-Host ''
Write-Host '=== 验证 token ===' -ForegroundColor Cyan
try {
$resp = Invoke-RestMethod -Uri 'https://api.github.com/user' `
-Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } `
-TimeoutSec 15
Write-Host " Authenticated as: $($resp.login)" -ForegroundColor Green
} catch {
Write-Host " Token 验证失败: $($_.Exception.Message)" -ForegroundColor Red
Remove-Item Env:GITHUB_TOKEN -ErrorAction SilentlyContinue
exit 1
}
# ================================================================
# 3. 设置 remote URL (带 token, 不显示)
# ================================================================
Write-Host ''
Write-Host '=== 设置 remote URL ===' -ForegroundColor Cyan
$remoteUrl = "https://maijun-sec:${env:GITHUB_TOKEN}@github.com/maijun-sec/AetherCode.git"
git remote set-url origin $remoteUrl
$display = "https://maijun-sec:****REDACTED****@github.com/maijun-sec/AetherCode.git"
Write-Host " $display" -ForegroundColor Gray
# ================================================================
# 4. 确认分支 (master -> main)
# ================================================================
$branch = git branch --show-current
Write-Host ''
Write-Host "=== Current branch: $branch ===" -ForegroundColor Cyan
if ($branch -ne 'main') {
Write-Host ' Renaming to main...' -ForegroundColor Yellow
git branch -m main
}
# ================================================================
# 5. Push
# ================================================================
Write-Host ''
Write-Host '=== git push -u origin main ===' -ForegroundColor Cyan
Write-Host ' Pushing 2757 files + 2 submodules...' -ForegroundColor Yellow
Write-Host ' Expected: 30s - 2min (depends on network)' -ForegroundColor Gray
Write-Host ''
git push -u origin main --progress
# ================================================================
# 6. 验证结果
# ================================================================
if ($LASTEXITCODE -eq 0) {
Write-Host ''
Write-Host '=== ✅ Push 成功 ===' -ForegroundColor Green
Write-Host ''
Write-Host '=== Remote branch ===' -ForegroundColor Cyan
git log --oneline -3 origin/main
Write-Host ''
Write-Host '=== Remote head ===' -ForegroundColor Cyan
git ls-remote --heads origin main
} else {
Write-Host ''
Write-Host '=== ❌ Push 失败 ===' -ForegroundColor Red
Write-Host " Exit code: $LASTEXITCODE" -ForegroundColor Red
Write-Host ''
Write-Host ' Debug:' -ForegroundColor Yellow
Write-Host ' - 网络? try: Test-NetConnection github.com -Port 443'
Write-Host ' - Token 权限? try: curl -H "Authorization: Bearer $env:GITHUB_TOKEN" https://api.github.com/repos/maijun-sec/AetherCode | jq .permissions'
Write-Host ' - Branch protection? GitHub repo Settings -> Branches -> main'
Write-Host ' - 详细: GIT_CURL_VERBOSE=1 git push -u origin main -v'
}
# ================================================================
# 7. 清 token
# ================================================================
Remove-Item Env:GITHUB_TOKEN -ErrorAction SilentlyContinue
Write-Host ''
Write-Host '(Env var cleared.)' -ForegroundColor Gray