Fix workflow py script

This commit is contained in:
dvirlabs 2025-06-29 08:49:53 +03:00
parent dc76d2c924
commit f3a9572f0c

View File

@ -1,13 +1,15 @@
import os import os
import yaml import yaml
import requests
import subprocess import subprocess
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"
} }
# ✅ CORRECT GitHub repo (lab-monitor, not apps-gitops)
GITHUB_REPO = f"https://{os.getenv('GITHUB_TOKEN')}@github.com/dvirlabs/lab-monitor.git" 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" 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")
@ -106,27 +108,26 @@ jobs:
def push_workflow(): def push_workflow():
# clone if needed # ✅ Clone lab-monitor repo from GitHub
if not os.path.exists(REPO_PATH): if not os.path.exists(REPO_PATH):
print("📥 Cloning lab-monitor...") print("📥 Cloning lab-monitor...")
result = subprocess.run(["git", "clone", GITHUB_REPO, REPO_PATH]) result = subprocess.run(["git", "clone", GITHUB_REPO, REPO_PATH])
if result.returncode != 0: if result.returncode != 0:
raise Exception("❌ Failed to clone lab-monitor repo") 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, "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.name", "lab-monitor-bot"])
subprocess.run(["git", "-C", REPO_PATH, "config", "user.email", "bot@dvirlabs.com"]) 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, "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)
# Push with upstream set to main
result = subprocess.run(["git", "-C", REPO_PATH, "push", "--set-upstream", "origin", "main"]) result = subprocess.run(["git", "-C", REPO_PATH, "push", "--set-upstream", "origin", "main"])
if result.returncode != 0: if result.returncode != 0:
raise Exception("❌ Failed to push monitor.yml to origin/main") raise Exception("❌ Failed to push monitor.yml to origin/main")