-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobuilder.py
89 lines (77 loc) · 3.12 KB
/
autobuilder.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import subprocess
import time
import zipfile
# Configuration
UNITY_PATH = ".../Editor/Unity.exe" # Path to unity editor .exe
PROJECT_PATH = ".../ProjectRepo" # Path to unity project
BUILD_PATH = os.path.join(PROJECT_PATH, "Build/WebGL") # Path to web build folder
ZIP_PATH = os.path.join(PROJECT_PATH, "Build/WebGL.zip") # Path to archive
ITCH_IO_CHANNEL = "name/gamelink:web" # Itch's user name and game's link name username/game:web
BUTLER_PATH = "butler" # If butler in PATH - use just 'butler'
CHECK_INTERVAL = 60 # Inverval how ofter stript checks new commits
def get_latest_commit_message():
try:
commit_message = subprocess.check_output(["git", "log", "-1", "--pretty=%B"]).strip().decode("utf-8")
return commit_message
except subprocess.CalledProcessError as e:
print(f"Error when get commit: {e}")
return None
def pull_latest_changes():
try:
subprocess.check_call(["git", "pull"])
print("Pulled chenges")
except subprocess.CalledProcessError as e:
print(f"Error git pull: {e}")
def build_webgl():
try:
subprocess.check_call([
UNITY_PATH,
"-quit", "-batchmode",
"-projectPath", PROJECT_PATH,
"-executeMethod", "Editor.WebGLBuilder.PerformWebGLBuild", # Here you can modify method as you want
"-buildTarget", "WebGL",
"-logFile", "unity_build.log"
])
print("Build WebGL succesful")
except subprocess.CalledProcessError as e:
print(f"Build Error: {e}")
return False
return True
def zip_build_folder():
if os.path.exists(ZIP_PATH):
os.remove(ZIP_PATH)
with zipfile.ZipFile(ZIP_PATH, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(BUILD_PATH):
for file in files:
full_path = os.path.join(root, file)
relative_path = os.path.relpath(full_path, BUILD_PATH)
zipf.write(full_path, relative_path)
print("Archive finished.")
def upload_to_itch():
try:
subprocess.check_call([BUTLER_PATH, "push", ZIP_PATH, ITCH_IO_CHANNEL])
print("Upload to itch.io finished.")
except subprocess.CalledProcessError as e:
print(f"Error during upload to itch.io: {e}")
def main():
last_commit_message = ""
while True:
pull_latest_changes()
commit_message = get_latest_commit_message()
if last_commit_message != commit_message:
if commit_message and "[build]" in commit_message: # You can change tag here
print("Tag [build] found, starting build...")
last_commit_message = commit_message
if build_webgl():
zip_build_folder()
upload_to_itch()
else:
print("Build failed")
else:
print("Last commint doesn't contain [build] tag. Skip build.")
else:
print("Same commit. Skip build")
time.sleep(CHECK_INTERVAL)
if __name__ == "__main__":
main()