Selaa lähdekoodia

fix: auto-push

Dew-OF-Aurora 3 viikkoa sitten
vanhempi
sitoutus
2559e8007a
1 muutettua tiedostoa jossa 31 lisäystä ja 0 poistoa
  1. 31 0
      scripts/run_update_and_commit.sh

+ 31 - 0
scripts/run_update_and_commit.sh

@@ -53,4 +53,35 @@ git -C "$APP_DIR" \
   -c user.email="$commit_email" \
   commit -m "chore: rotate preferred domain to ${after} (${ts})"
 
+push_remote="${GIT_PUSH_REMOTE:-origin}"
+if ! git -C "$APP_DIR" remote get-url "$push_remote" >/dev/null 2>&1; then
+  push_remote=""
+  while IFS= read -r r; do
+    push_remote="$r"
+    break
+  done < <(git -C "$APP_DIR" remote)
+fi
+
+current_branch="$(git -C "$APP_DIR" symbolic-ref --quiet --short HEAD 2>/dev/null || true)"
+
+if [[ -z "$push_remote" ]]; then
+  echo "[vmess-domain-rotator] no remote found, skip git push"
+elif [[ -z "$current_branch" ]]; then
+  echo "[vmess-domain-rotator] detached HEAD, skip git push"
+else
+  if git -C "$APP_DIR" rev-parse --abbrev-ref --symbolic-full-name "@{u}" >/dev/null 2>&1; then
+    if git -C "$APP_DIR" push; then
+      echo "[vmess-domain-rotator] pushed to ${push_remote}/${current_branch}"
+    else
+      echo "[vmess-domain-rotator] git push failed"
+    fi
+  else
+    if git -C "$APP_DIR" push -u "$push_remote" "$current_branch"; then
+      echo "[vmess-domain-rotator] pushed to ${push_remote}/${current_branch} (set upstream)"
+    else
+      echo "[vmess-domain-rotator] git push failed"
+    fi
+  fi
+fi
+
 echo "[vmess-domain-rotator] committed domain change: ${before} -> ${after}"