Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ say "Date: $(date -u '+%Y-%m-%dT%H:%M:%SZ')"
cd "$PROJECT_DIR"

# ---------------------------------------------------------
# 1) Pull latest code from origin/main
# 0) Stop service before touching files (prevents file locks)
# ---------------------------------------------------------
if command -v systemctl >/dev/null 2>&1; then
say "Step 0/4 — Stopping ${APP_NAME} service…"
systemctl stop "${APP_NAME}.service" || true
fi

# ---------------------------------------------------------
# 1) Pull latest code from origin/main (hard reset — no merge conflicts)
# ---------------------------------------------------------
say "Step 1/4 — Fetching latest code from origin/main…"
git fetch --all
git reset --hard origin/main
git clean -fd
say "Now at: $(git rev-parse --short HEAD)"

# ---------------------------------------------------------
Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2526,11 +2526,17 @@ bot.command('deploy', async (ctx) => {
.editMessageText(ctx.chat.id, status.message_id, null, text, { parse_mode: 'Markdown' })
.catch(() => {});

// ── Step 1: git pull ──────────────────────────────────────────
const gitResult = await runCmd('git', ['pull', 'origin', 'main'], PROJECT_DIR, 30000);
// ── Step 1: fetch + hard reset (avoids hang on dirty tree / merge conflicts) ──
const fetchResult = await runCmd('git', ['fetch', '--all'], PROJECT_DIR, 30000);
const gitResult = fetchResult.ok
? await runCmd('git', ['reset', '--hard', 'origin/main'], PROJECT_DIR, 15000)
: fetchResult;
if (gitResult.ok) {
await runCmd('git', ['clean', '-fd'], PROJECT_DIR, 10000).catch(() => {});
}
const gitLine = gitResult.ok
? `✅ *git pull:* \`${sanitizeCmdOutput(gitResult.out.split('\n')[0])}\``
: `⚠️ *git pull failed:* \`${sanitizeCmdOutput(gitResult.err)}\``;
? `✅ *git update:* \`${sanitizeCmdOutput(gitResult.out.split('\n')[0])}\``
: `⚠️ *git update failed:* \`${sanitizeCmdOutput(gitResult.err || fetchResult.err)}\``;

await edit(
`🚀 *Deployment in progress* — ${ts()}\n\n`
Expand Down
12 changes: 7 additions & 5 deletions prod-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ say "Project directory: $PROJECT_DIR"
say "Running as: $(id -un) (uid=$(id -u) gid=$(id -g))"

# ---------------------------------------------------------
# 1) Pull latest code from origin main [FIRST — before anything]
# 1) Fetch + hard reset to origin/main [FIRST — before anything]
# Using fetch+reset instead of pull avoids hangs on dirty trees / conflicts.
# ---------------------------------------------------------
say "Pulling latest code from origin main..."
if git -C "$PROJECT_DIR" pull origin main 2>&1; then
say "Git pull successful"
say "Fetching latest code from origin main..."
if git -C "$PROJECT_DIR" fetch --all 2>&1 && git -C "$PROJECT_DIR" reset --hard origin/main 2>&1; then
git -C "$PROJECT_DIR" clean -fd 2>&1 || true
say "Git fetch + reset successful: $(git -C "$PROJECT_DIR" rev-parse --short HEAD)"
else
warn "Git pull failed — continuing with local copy"
warn "Git fetch/reset failed — continuing with local copy"
fi

# ---------------------------------------------------------
Expand Down
Loading