-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-github-push.ps1
More file actions
112 lines (99 loc) · 6.91 KB
/
fix-github-push.ps1
File metadata and controls
112 lines (99 loc) · 6.91 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
#!/usr/bin/env pwsh
# ═══════════════════════════════════════════════════════════════
# 🔧 Fix GitHub Push - تصليح الدفع لـ GitHub
# ═══════════════════════════════════════════════════════════════
Write-Host "════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "🚀 Fix GitHub Push Script" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
# ────────────────────────────────────────────────────────────────
# 1️⃣ Check if GitHub CLI is installed
# ────────────────────────────────────────────────────────────────
Write-Host "1️⃣ Checking GitHub CLI..." -ForegroundColor Yellow
$ghExists = Get-Command gh -ErrorAction SilentlyContinue
if (-not $ghExists) {
Write-Host "⚠️ GitHub CLI not installed" -ForegroundColor Red
Write-Host " Installing via winget..." -ForegroundColor Yellow
winget install --id GitHub.cli --silent --accept-source-agreements --accept-package-agreements
Write-Host "✅ GitHub CLI installed" -ForegroundColor Green
} else {
Write-Host "✅ GitHub CLI already installed" -ForegroundColor Green
}
# ────────────────────────────────────────────────────────────────
# 2️⃣ Check GitHub authentication
# ────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "2️⃣ Checking GitHub authentication..." -ForegroundColor Yellow
$authStatus = gh auth status 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "⚠️ Not logged in to GitHub" -ForegroundColor Red
Write-Host " Launching browser for authentication..." -ForegroundColor Yellow
gh auth login --web --git-protocol https
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Successfully authenticated" -ForegroundColor Green
} else {
Write-Host "❌ Authentication failed" -ForegroundColor Red
exit 1
}
} else {
Write-Host "✅ Already authenticated" -ForegroundColor Green
}
# ────────────────────────────────────────────────────────────────
# 3️⃣ Check if repository exists
# ────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "3️⃣ Checking if repository exists..." -ForegroundColor Yellow
$repoExists = gh repo view gratech-sa/gratech-cometx 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "⚠️ Repository does not exist" -ForegroundColor Red
Write-Host " Creating repository..." -ForegroundColor Yellow
gh repo create gratech-sa/gratech-cometx `
--private `
--description "CometX - AI-Powered Development Platform" `
--confirm
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Repository created" -ForegroundColor Green
} else {
Write-Host "❌ Failed to create repository" -ForegroundColor Red
Write-Host " You may need to create it manually at:" -ForegroundColor Yellow
Write-Host " https://github.com/organizations/gratech-sa/repositories/new" -ForegroundColor Cyan
exit 1
}
} else {
Write-Host "✅ Repository exists" -ForegroundColor Green
}
# ────────────────────────────────────────────────────────────────
# 4️⃣ Fix remote URL (remove trailing slash if exists)
# ────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "4️⃣ Fixing remote URL..." -ForegroundColor Yellow
git remote remove origin 2>$null
git remote add origin https://github.com/gratech-sa/gratech-cometx.git
Write-Host "✅ Remote URL fixed" -ForegroundColor Green
# ────────────────────────────────────────────────────────────────
# 5️⃣ Push to GitHub
# ────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "5️⃣ Pushing to GitHub..." -ForegroundColor Yellow
git push -u origin main
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Successfully pushed to GitHub" -ForegroundColor Green
Write-Host ""
Write-Host "════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "🎉 Success! GitHub Actions will now:" -ForegroundColor Green
Write-Host " • Build Docker image" -ForegroundColor White
Write-Host " • Run Trivy security scan" -ForegroundColor White
Write-Host " • Deploy to Container Apps" -ForegroundColor White
Write-Host ""
Write-Host "📊 Monitor progress at:" -ForegroundColor Yellow
Write-Host " https://github.com/gratech-sa/gratech-cometx/actions" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════════════" -ForegroundColor Cyan
} else {
Write-Host "❌ Failed to push" -ForegroundColor Red
Write-Host ""
Write-Host "🔍 Possible issues:" -ForegroundColor Yellow
Write-Host " 1. Wrong branch name (try 'git branch' to check)" -ForegroundColor White
Write-Host " 2. Permission denied (check GitHub token scopes)" -ForegroundColor White
Write-Host " 3. Authentication expired (run 'gh auth refresh')" -ForegroundColor White
exit 1
}