correction de bugs de l'auto-déploiement
This commit is contained in:
parent
3d52144ad7
commit
432611d4ee
1 changed files with 8 additions and 4 deletions
|
|
@ -33,16 +33,16 @@ def send_discord_log(status, message, color, author=None, commit_msg=None):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[!] Erreur envoi Discord : {e}")
|
print(f"[!] Erreur envoi Discord : {e}")
|
||||||
|
|
||||||
def run_mep_logic(author, commit_msg):
|
def run_mep_logic(author, commit_msg, branch="main"):
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
send_discord_log("EN COURS", "Déploiement lancé sur la machine de guerre...", 3447003, author, commit_msg)
|
send_discord_log("EN COURS", f"Déploiement branch **{branch}** lancé sur la machine de guerre...", 3447003, author, commit_msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chdir(PROJECT_PATH)
|
os.chdir(PROJECT_PATH)
|
||||||
|
|
||||||
# 1. GIT
|
# 1. GIT
|
||||||
subprocess.run(["git", "fetch", "origin"], check=True)
|
subprocess.run(["git", "fetch", "origin"], check=True)
|
||||||
subprocess.run(["git", "reset", "--hard", "origin/main"], check=True)
|
subprocess.run(["git", "reset", "--hard", f"origin/{branch}"], check=True)
|
||||||
|
|
||||||
duration = (datetime.now() - start_time).total_seconds()
|
duration = (datetime.now() - start_time).total_seconds()
|
||||||
msg = f"✅ **Déploiement réussi en {duration:.2f}s**\nLe bot est à jour et redémarré."
|
msg = f"✅ **Déploiement réussi en {duration:.2f}s**\nLe bot est à jour et redémarré."
|
||||||
|
|
@ -70,8 +70,12 @@ def deploy():
|
||||||
author = data['commits'][0].get('author', {}).get('name', 'Inconnu')
|
author = data['commits'][0].get('author', {}).get('name', 'Inconnu')
|
||||||
commit_msg = data['commits'][0].get('message', 'Pas de message')
|
commit_msg = data['commits'][0].get('message', 'Pas de message')
|
||||||
|
|
||||||
|
# Extraction de la branche
|
||||||
|
ref = data.get('ref', 'refs/heads/main')
|
||||||
|
branch = ref.split('/')[-1] if ref else 'main'
|
||||||
|
|
||||||
# Threading pour répondre vite à GitLab
|
# Threading pour répondre vite à GitLab
|
||||||
threading.Thread(target=run_mep_logic, args=(author, commit_msg)).start()
|
threading.Thread(target=run_mep_logic, args=(author, commit_msg, branch)).start()
|
||||||
|
|
||||||
return {"status": "accepted"}, 202
|
return {"status": "accepted"}, 202
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue