-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_to_github.sh
More file actions
143 lines (120 loc) · 5.64 KB
/
Copy pathdeploy_to_github.sh
File metadata and controls
143 lines (120 loc) · 5.64 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
138
139
140
141
142
143
#!/usr/bin/env bash
# ═══════════════════════════════════════════════════════════════
# LEO DEVOPS — PHASE 4: REPLIT → GITHUB DEPLOYMENT
# SHS LAB | Auto-creates repo and pushes all source code
# ═══════════════════════════════════════════════════════════════
set -euo pipefail
# ── Credentials (from Replit Secrets) ──
GITHUB_PAT="${GITHUB_TOKEN:?ERROR: GITHUB_TOKEN secret is not set}"
GITHUB_USER="${GITHUB_USER:-The-JDdev}"
REPO_NAME="Leo-SHS-LAB"
REPO_DESC="Official source code for Leo System Agent by SHS LAB."
BRANCH="main"
BOLD="\033[1m"
CYAN="\033[0;36m"
MAGENTA="\033[0;35m"
YELLOW="\033[0;33m"
GREEN="\033[0;32m"
RED="\033[0;31m"
RESET="\033[0m"
log() { echo -e "${CYAN}[Leo DevOps]${RESET} $1"; }
warn() { echo -e "${YELLOW}[Leo DevOps]${RESET} $1"; }
ok() { echo -e "${GREEN}[Leo DevOps]${RESET} $1"; }
err() { echo -e "${RED}[Leo DevOps] ERROR:${RESET} $1"; exit 1; }
echo -e ""
echo -e "${MAGENTA}${BOLD}════════════════════════════════════════${RESET}"
echo -e "${CYAN}${BOLD} LEO PHASE 4 — GITHUB DEPLOYMENT INIT ${RESET}"
echo -e "${MAGENTA}${BOLD}════════════════════════════════════════${RESET}"
echo -e ""
# ════════════════════════════════════════════
# STEP A: REPO CREATION VIA GITHUB REST API
# ════════════════════════════════════════════
log "Checking if repository '${REPO_NAME}' exists..."
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer ${GITHUB_PAT}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${GITHUB_USER}/${REPO_NAME}")
if [ "$HTTP_STATUS" = "200" ]; then
warn "Repository '${REPO_NAME}' already exists — skipping creation."
else
log "Repository not found (HTTP ${HTTP_STATUS}). Creating private repo..."
CREATE_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST \
-H "Authorization: Bearer ${GITHUB_PAT}" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
"https://api.github.com/user/repos" \
-d "{
\"name\": \"${REPO_NAME}\",
\"description\": \"${REPO_DESC}\",
\"private\": true,
\"auto_init\": false
}")
CREATE_STATUS=$(echo "$CREATE_RESPONSE" | tail -1)
CREATE_BODY=$(echo "$CREATE_RESPONSE" | sed '$d')
if [ "$CREATE_STATUS" = "201" ]; then
ok "Repository '${REPO_NAME}' created successfully (private)."
else
# Extract error message
MSG=$(echo "$CREATE_BODY" | grep -o '"message":"[^"]*"' | head -1 | cut -d'"' -f4)
err "Repo creation failed (HTTP ${CREATE_STATUS}): ${MSG}"
fi
fi
# ════════════════════════════════════════════
# STEP B: GIT OPERATIONS
# ════════════════════════════════════════════
SECURE_REMOTE="https://${GITHUB_PAT}@github.com/${GITHUB_USER}/${REPO_NAME}.git"
log "Configuring Git identity..."
git config --global user.email "leo@shslab.ai" 2>/dev/null || true
git config --global user.name "Leo SHS LAB" 2>/dev/null || true
# Init if not already a git repo
if [ ! -d ".git" ]; then
log "Initializing Git repository..."
git init
fi
log "Switching to branch '${BRANCH}'..."
git checkout -b "${BRANCH}" 2>/dev/null || git checkout "${BRANCH}" 2>/dev/null || true
log "Staging all files..."
# Exclude secrets and build artifacts
cat > .gitignore << 'GITIGNORE'
# Build outputs
android-leo/app/build/
android-leo/.gradle/
android-leo/local.properties
*.keystore
*.jks
# Replit internals
.upm/
.cache/
node_modules/
.local/
# Secrets
.env
*.secret
GITIGNORE
git add .
# Check if there are changes to commit
if git diff --cached --quiet; then
warn "Nothing new to commit — working tree clean."
else
log "Committing source code..."
git commit -m "Auto-deployed Phase 1-3 source code from Replit"
fi
log "Configuring remote origin..."
if git remote get-url origin &>/dev/null; then
git remote set-url origin "${SECURE_REMOTE}"
warn "Remote 'origin' already existed — URL updated."
else
git remote add origin "${SECURE_REMOTE}"
fi
log "Pushing to GitHub (force)..."
git push -u origin "${BRANCH}" --force
# ════════════════════════════════════════════
# STEP C: SUCCESS LOG
# ════════════════════════════════════════════
echo -e ""
echo -e "${MAGENTA}${BOLD}════════════════════════════════════════════════════════════${RESET}"
echo -e "${GREEN}${BOLD} [Leo DevOps]: Source code successfully deployed to GitHub! ${RESET}"
echo -e "${CYAN} Repo: https://github.com/${GITHUB_USER}/${REPO_NAME}${RESET}"
echo -e "${MAGENTA}${BOLD}════════════════════════════════════════════════════════════${RESET}"
echo -e ""