-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate.py
More file actions
64 lines (58 loc) · 2.11 KB
/
Copy pathupdate.py
File metadata and controls
64 lines (58 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import traceback
from decouple import config
from pathlib import Path
from subprocess import check_output
from subprocess import run as bashrun
try:
print("Default var for upstream repo & branch will used if none were given!")
ALWAYS_DEPLOY_LATEST = config(
"ALWAYS_DEPLOY_LATEST",
default=False,
cast=bool)
AUPR = config("ALWAYS_UPDATE_PY_REQ", default=False, cast=bool)
UPSTREAM_REPO = config(
"UPSTREAM_REPO",
default="https://github.com/Nubuki-all/Genshin_bot")
UPSTREAM_BRANCH = config("UPSTREAM_BRANCH", default="neon")
except Exception:
print("Environment vars Missing")
traceback.print_exc()
update_check = Path("update")
cmd = (
f"git switch {UPSTREAM_BRANCH} -q \
&& git pull -q "
"&& git reset --hard @{u} -q \
&& git clean -df -q"
)
cmd2 = f"git init -q \
&& git config --global user.email 117080364+Niffy-the-conqueror@users.noreply.github.com \
&& git config --global user.name Niffy-the-conqueror \
&& git add . \
&& git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO} \
&& git fetch origin -q \
&& git reset --hard origin/{UPSTREAM_BRANCH} -q \
&& git switch {UPSTREAM_BRANCH} -q"
try:
if ALWAYS_DEPLOY_LATEST is True or update_check.is_file():
if UPSTREAM_BRANCH == "main":
bashrun(["rm -rf .git"], shell=True)
if os.path.exists('.git') and check_output(
["git config --get remote.origin.url"],
shell=True).decode().strip() == UPSTREAM_REPO:
update = bashrun([cmd], shell=True)
else:
update = bashrun([cmd2], shell=True)
if AUPR:
bashrun(["pip3", "install", "-r", "requirements.txt"])
if update.returncode == 0:
print('Successfully updated with latest commit from UPSTREAM_REPO')
else:
print('Something went wrong while updating,maybe invalid upstream repo?')
if update_check.is_file():
os.remove("update")
else:
print("Auto-update is disabled.")
except Exception:
traceback.print_exc()