diff --git a/automation/alerts/generate_monitor_workflow.py b/automation/alerts/generate_monitor_workflow.py index 6d51459..e6f5bd8 100644 --- a/automation/alerts/generate_monitor_workflow.py +++ b/automation/alerts/generate_monitor_workflow.py @@ -1,13 +1,15 @@ import os import yaml -import requests import subprocess REPOS = { "dev-tools": "https://git.dvirlabs.com/dvirlabs/dev-tools.git", "infra": "https://git.dvirlabs.com/dvirlabs/infra.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" WORKFLOW_FILE = "./repos/lab-monitor/.github/workflows/monitor.yml" REPO_PATH = os.path.join(BASE_DIR, "lab-monitor") @@ -106,27 +108,26 @@ jobs: def push_workflow(): - # clone if needed + # ✅ 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") - # checkout main if needed + # ✅ Checkout main (GitHub default branch) subprocess.run(["git", "-C", REPO_PATH, "fetch"], check=True) - subprocess.run(["git", "-C", REPO_PATH, "checkout", "-B", "main", "origin/main"], check=False) + subprocess.run(["git", "-C", REPO_PATH, "checkout", "main"], check=True) - # Set Git identity + # Git identity subprocess.run(["git", "-C", REPO_PATH, "config", "user.name", "lab-monitor-bot"]) subprocess.run(["git", "-C", REPO_PATH, "config", "user.email", "bot@dvirlabs.com"]) - # Add + Commit + # Add + Commit + Push 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) - - # Push with upstream set to main result = subprocess.run(["git", "-C", REPO_PATH, "push", "--set-upstream", "origin", "main"]) + if result.returncode != 0: raise Exception("❌ Failed to push monitor.yml to origin/main")