This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Operation.py
150 lines (135 loc) · 7.35 KB
/
Operation.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from datetime import datetime
from NikGapps.Config.ConfigOperations import ConfigOperations
from NikGapps.Config.NikGappsConfig import NikGappsConfig
from NikGapps.Config.UserBuild.OnDemand import OnDemand
from NikGapps.Helper import FileOp, Git
from NikGapps.Helper.C import C
from NikGapps.Web.Upload import Upload
from Release import Release
from Config import FETCH_PACKAGE
import Config
import pytz
from colorama import Fore
class Operation:
@staticmethod
def fetch():
pkg_list = Release.package(FETCH_PACKAGE)
if pkg_list.__len__() > 0:
message = "Packages Successfully Fetched"
print(message)
else:
message = "Fetching Failed"
print(message)
@staticmethod
def clone_apk_repo(android_version, fresh_clone=False, branch="main"):
apk_source_directory = C.apk_source_directory + str(android_version)
apk_source_repo = C.apk_source_repo + str(android_version) + ".git"
repository = Git(apk_source_directory)
result = repository.clone_repo(repo_url=apk_source_repo, fresh_clone=fresh_clone, branch=branch)
return repository if result else None
@staticmethod
def get_last_commit_date(repo_dir=C.cwd, repo_url=None,
branch="canary" if Config.RELEASE_TYPE.__eq__("canary") else "main", android_version=None):
last_commit_datetime = None
if android_version is not None:
repository = Operation.clone_apk_repo(android_version, branch=branch)
else:
repository = Git(repo_dir)
if repo_url is not None:
repository.clone_repo(repo_url=repo_url, fresh_clone=False, branch=branch)
if repository is not None:
last_commit_datetime = repository.get_latest_commit_date(branch=branch)
return last_commit_datetime
@staticmethod
def get_release_repo():
release_repo = Git(C.release_history_directory)
if not FileOp.dir_exists(C.release_history_directory):
repo_name = "[email protected]:nikgapps/canary-release.git" if Config.RELEASE_TYPE.__eq__(
"canary") else "[email protected]:nikgapps/release.git"
release_repo.clone_repo(repo_name, branch="master", commit_depth=50)
if not FileOp.dir_exists(C.release_history_directory):
print(C.release_history_directory + " doesn't exist!")
return release_repo
@staticmethod
def get_website_repo_for_changelog(repo_dir=C.website_directory, repo_url=C.website_repo,
branch="master"):
repo = Git(repo_dir)
if repo_url is not None:
repo.clone_repo(repo_url=repo_url, fresh_clone=False, branch=branch)
if not FileOp.dir_exists(C.website_directory):
print(f"Repo {repo_dir} doesn't exist!")
return repo
@staticmethod
def is_new_release(source_last_commit_datetime, apk_source_datetime, release_datetime):
if apk_source_datetime is None or release_datetime is None or source_last_commit_datetime is None:
print(f"There never really was a release done for android {str(Config.TARGET_ANDROID_VERSION)}")
return True
source_last_commit_datetime_ago = release_datetime - source_last_commit_datetime
if str(source_last_commit_datetime_ago).startswith("-"):
print("Last Release was " + str(
source_last_commit_datetime_ago * -1) + " before source update." + Fore.GREEN + " Eligible for new release!" + Fore.RESET)
else:
print("Last source update was " + str(
source_last_commit_datetime_ago) + " before release." + Fore.YELLOW + " latest updates are already in the release!" + Fore.RESET)
apk_source_datetime_ago = release_datetime - apk_source_datetime
if str(apk_source_datetime_ago).startswith("-"):
print("Last Release was " + str(
apk_source_datetime_ago * -1) + " before apk update." + Fore.GREEN + " Eligible for new release!" + Fore.RESET)
else:
print("Last Apk update was " + str(
apk_source_datetime_ago) + " before release." + Fore.YELLOW + " latest updates are already in the release!" + Fore.RESET)
# check if apk source or source code is newer than last release
if apk_source_datetime > release_datetime or source_last_commit_datetime > release_datetime:
return True
# if nothing is true yet, it's already a new release
return False
def build(self, git_check=Config.GIT_CHECK, android_versions=None, package_list=Config.BUILD_PACKAGE_LIST,
commit_message=None, upload: Upload = None):
if android_versions is None:
android_versions = [Config.TARGET_ANDROID_VERSION]
if commit_message is None:
commit_message = datetime.now(pytz.timezone('Europe/London')).strftime("%Y-%m-%d %H:%M:%S")
release_repo = None
source_last_commit_datetime = None
if git_check:
source_last_commit_datetime = self.get_last_commit_date(
branch="main" if Config.RELEASE_TYPE.__eq__("stable") else "dev")
print(f"Last {str(Config.RELEASE_TYPE).capitalize()} Source Commit: " + str(source_last_commit_datetime))
release_repo = self.get_release_repo()
else:
print("Git Check is disabled")
for android_version in android_versions:
Config.TARGET_ANDROID_VERSION = android_version
# clone the apk repo if it doesn't exist
if git_check:
release_datetime = None
if release_repo is not None:
release_datetime = release_repo.get_latest_commit_date(branch="master",
filter_key=str(android_version))
print(f"Last Release ({str(android_version)}): " + str(release_datetime))
apk_source_datetime = self.get_last_commit_date(android_version=str(android_version))
if apk_source_datetime is not None:
print("Last Apk Repo (" + str(Config.TARGET_ANDROID_VERSION) + ") Commit: " + str(
apk_source_datetime))
else:
print(C.apk_source_directory + " doesn't exist!")
new_release = self.is_new_release(source_last_commit_datetime, apk_source_datetime, release_datetime)
else:
new_release = True
if Config.OVERRIDE_RELEASE or new_release:
if Config.TARGET_ANDROID_VERSION == 10 and "go" not in Config.BUILD_PACKAGE_LIST:
Config.BUILD_PACKAGE_LIST.append("go")
C.update_android_version_dependencies()
Release.zip(package_list, upload)
if release_repo is not None and git_check:
release_repo.git_push(str(android_version) + ": " + str(commit_message))
if Config.BUILD_EXCLUSIVE:
OnDemand.build_all_configs(android_version, exclusive=True)
if git_check:
website_repo = None
website_repo = self.get_website_repo_for_changelog()
if website_repo is not None:
website_repo.update_changelog()
if Config.UPLOAD_FILES:
config = NikGappsConfig()
ConfigOperations.upload_nikgapps_config(config)