Debug
This commit is contained in:
parent
fe992c7e96
commit
0cca0db22f
@ -2,19 +2,19 @@ import os
|
|||||||
import yaml
|
import yaml
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
# 🔁 Repos to scan for monitoring.yaml files
|
||||||
REPOS = {
|
REPOS = {
|
||||||
"dev-tools": "https://git.dvirlabs.com/dvirlabs/dev-tools.git",
|
"dev-tools": "https://git.dvirlabs.com/dvirlabs/dev-tools.git",
|
||||||
"infra": "https://git.dvirlabs.com/dvirlabs/infra.git",
|
"infra": "https://git.dvirlabs.com/dvirlabs/infra.git",
|
||||||
"observability-stack": "https://git.dvirlabs.com/dvirlabs/observability-stack.git",
|
"observability-stack": "https://git.dvirlabs.com/dvirlabs/observability-stack.git",
|
||||||
"sandbox": "https://git.dvirlabs.com/dvirlabs/sandbox.git",
|
"sandbox": "https://git.dvirlabs.com/dvirlabs/sandbox.git",
|
||||||
|
# ✅ Add GitHub repo to REPOS list (not hardcoded separately)
|
||||||
|
"lab-monitor": f"https://{os.getenv('GITHUB_TOKEN')}@github.com/dvirlabs/lab-monitor.git",
|
||||||
}
|
}
|
||||||
|
|
||||||
# ✅ CORRECT GitHub repo (lab-monitor, not apps-gitops)
|
|
||||||
GITHUB_REPO = f"https://{os.getenv('GITHUB_TOKEN')}@github.com/dvirlabs/lab-monitor.git"
|
|
||||||
|
|
||||||
BASE_DIR = "./repos"
|
BASE_DIR = "./repos"
|
||||||
WORKFLOW_FILE = "./repos/lab-monitor/.github/workflows/monitor.yml"
|
|
||||||
REPO_PATH = os.path.join(BASE_DIR, "lab-monitor")
|
REPO_PATH = os.path.join(BASE_DIR, "lab-monitor")
|
||||||
|
WORKFLOW_FILE = os.path.join(REPO_PATH, ".github/workflows/monitor.yml")
|
||||||
|
|
||||||
|
|
||||||
def clone_repos():
|
def clone_repos():
|
||||||
@ -30,6 +30,8 @@ def clone_repos():
|
|||||||
def extract_urls():
|
def extract_urls():
|
||||||
urls = []
|
urls = []
|
||||||
for repo in REPOS:
|
for repo in REPOS:
|
||||||
|
if repo == "lab-monitor":
|
||||||
|
continue # skip this, it's where we push
|
||||||
manifests_path = os.path.join(BASE_DIR, repo, "manifests")
|
manifests_path = os.path.join(BASE_DIR, repo, "manifests")
|
||||||
if not os.path.isdir(manifests_path):
|
if not os.path.isdir(manifests_path):
|
||||||
continue
|
continue
|
||||||
@ -110,17 +112,15 @@ jobs:
|
|||||||
|
|
||||||
|
|
||||||
def push_workflow():
|
def push_workflow():
|
||||||
# ✅ Clone lab-monitor repo from GitHub
|
|
||||||
if not os.path.exists(REPO_PATH):
|
|
||||||
print("📥 Cloning lab-monitor...")
|
|
||||||
result = subprocess.run(["git", "clone", GITHUB_REPO, REPO_PATH])
|
|
||||||
if result.returncode != 0:
|
|
||||||
raise Exception("❌ Failed to clone lab-monitor repo")
|
|
||||||
subprocess.run(["ls", "-l", REPO_PATH])
|
subprocess.run(["ls", "-l", REPO_PATH])
|
||||||
|
|
||||||
# ✅ Checkout main (GitHub default branch)
|
# Detect default branch (main or master)
|
||||||
subprocess.run(["git", "-C", REPO_PATH, "fetch"], check=True)
|
result = subprocess.run(
|
||||||
subprocess.run(["git", "-C", REPO_PATH, "checkout", "main"], check=True)
|
["git", "-C", REPO_PATH, "symbolic-ref", "refs/remotes/origin/HEAD"],
|
||||||
|
capture_output=True, text=True, check=True
|
||||||
|
)
|
||||||
|
default_branch = result.stdout.strip().split("/")[-1]
|
||||||
|
subprocess.run(["git", "-C", REPO_PATH, "checkout", default_branch], check=True)
|
||||||
|
|
||||||
# Git identity
|
# Git identity
|
||||||
subprocess.run(["git", "-C", REPO_PATH, "config", "user.name", "lab-monitor-bot"])
|
subprocess.run(["git", "-C", REPO_PATH, "config", "user.name", "lab-monitor-bot"])
|
||||||
@ -129,10 +129,10 @@ def push_workflow():
|
|||||||
# Add + Commit + Push
|
# Add + Commit + Push
|
||||||
subprocess.run(["git", "-C", REPO_PATH, "add", ".github/workflows/monitor.yml"])
|
subprocess.run(["git", "-C", REPO_PATH, "add", ".github/workflows/monitor.yml"])
|
||||||
subprocess.run(["git", "-C", REPO_PATH, "commit", "-m", "update monitor.yml from monitoring.yaml"], check=False)
|
subprocess.run(["git", "-C", REPO_PATH, "commit", "-m", "update monitor.yml from monitoring.yaml"], check=False)
|
||||||
result = subprocess.run(["git", "-C", REPO_PATH, "push", "--set-upstream", "origin", "main"])
|
result = subprocess.run(["git", "-C", REPO_PATH, "push", "--set-upstream", "origin", default_branch])
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception("❌ Failed to push monitor.yml to origin/main")
|
raise Exception(f"❌ Failed to push monitor.yml to origin/{default_branch}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user