forked from SideStore/SideStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_apps.py
executable file
·192 lines (161 loc) · 6.04 KB
/
update_apps.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
import os
import json
import sys
# SIDESTORE_BUNDLE_ID = "com.SideStore.SideStore"
# Set environment variables with default values
VERSION_IPA = os.getenv("VERSION_IPA")
VERSION_DATE = os.getenv("VERSION_DATE")
IS_BETA = os.getenv("IS_BETA")
RELEASE_CHANNEL = os.getenv("RELEASE_CHANNEL")
SIZE = os.getenv("SIZE")
SHA256 = os.getenv("SHA256")
LOCALIZED_DESCRIPTION = os.getenv("LOCALIZED_DESCRIPTION")
DOWNLOAD_URL = os.getenv("DOWNLOAD_URL")
# BUNDLE_IDENTIFIER = os.getenv("BUNDLE_IDENTIFIER", SIDESTORE_BUNDLE_ID)
BUNDLE_IDENTIFIER = os.getenv("BUNDLE_IDENTIFIER")
# Uncomment to debug/test by simulating dummy input locally
# VERSION_IPA = os.getenv("VERSION_IPA", "0.0.0")
# VERSION_DATE = os.getenv("VERSION_DATE", "2000-12-18T00:00:00Z")
# IS_BETA = os.getenv("IS_BETA", True)
# RELEASE_CHANNEL = os.getenv("RELEASE_CHANNEL", "alpha")
# SIZE = int(os.getenv("SIZE", "0")) # Convert to integer
# SHA256 = os.getenv("SHA256", "")
# LOCALIZED_DESCRIPTION = os.getenv("LOCALIZED_DESCRIPTION", "Invalid Update")
# DOWNLOAD_URL = os.getenv("DOWNLOAD_URL", "https://github.com/SideStore/SideStore/releases/download/0.0.0/SideStore.ipa")
# Check if input file is provided
if len(sys.argv) < 2:
print("Usage: python3 update_apps.py <input_file>")
sys.exit(1)
input_file = sys.argv[1]
print(f"Input File: {input_file}")
# Debugging the environment variables
print(" ====> Required parameter list <====")
print("Bundle Identifier:", BUNDLE_IDENTIFIER)
print("Version:", VERSION_IPA)
print("Version Date:", VERSION_DATE)
print("IsBeta:", IS_BETA)
print("ReleaseChannel:", RELEASE_CHANNEL)
print("Size:", SIZE)
print("Sha256:", SHA256)
print("Localized Description:", LOCALIZED_DESCRIPTION)
print("Download URL:", DOWNLOAD_URL)
if IS_BETA is None:
print("Setting IS_BETA = False since no value was provided")
IS_BETA = False
if str(IS_BETA).lower() in ["true", "1", "yes"]:
IS_BETA = True
# Read the input JSON file
try:
with open(input_file, "r") as file:
data = json.load(file)
except Exception as e:
print(f"Error reading the input file: {e}")
sys.exit(1)
if (not BUNDLE_IDENTIFIER or
not VERSION_IPA or
not VERSION_DATE or
not RELEASE_CHANNEL or
not SIZE or
not SHA256 or
not LOCALIZED_DESCRIPTION or
not DOWNLOAD_URL):
print("One or more required parameter(s) were not defined as environment variable(s)")
sys.exit(1)
# Convert to integer
SIZE = int(SIZE)
# Process the JSON data
updated = False
# apps = data.get("apps", [])
# appsToUpdate = [app for app in apps if app.get("bundleIdentifier") == BUNDLE_IDENTIFIER]
# if len(appsToUpdate) == 0:
# print("No app with the specified bundle identifier found.")
# sys.exit(1)
# if len(appsToUpdate) > 1:
# print(f"Multiple apps with same `bundleIdentifier` = ${BUNDLE_IDENTIFIER} are not allowed!")
# sys.exit(1)
# app = appsToUpdate[0]
# # Update app-level metadata for store front page
# app.update({
# "beta": IS_BETA,
# })
# versions = app.get("versions", [])
# versionIfExists = [version for version in versions if version == VERSION_IPA]
# if versionIfExists: # current version is a duplicate, so reject it
# print(f"`version` = ${VERSION_IPA} already exists!, new build cannot have an existing version, Aborting!")
# sys.exit(1)
# # create an entry and keep ready
# new_version = {
# "version": VERSION_IPA,
# "date": VERSION_DATE,
# "localizedDescription": LOCALIZED_DESCRIPTION,
# "downloadURL": DOWNLOAD_URL,
# "size": SIZE,
# "sha256": SHA256,
# }
# if versions is []:
# versions.append(new_version)
# else:
# # versions.insert(0, new_version) # insert at front
# versions[0] = new_version # replace top one
# make it lowecase
RELEASE_CHANNEL = RELEASE_CHANNEL.lower()
version = data.get("version", 1)
if int(version) < 2:
print("Only v2 and above are supported for direct updates to sources.json on push")
sys.exit(1)
for app in data.get("apps", []):
if app.get("bundleIdentifier") == BUNDLE_IDENTIFIER:
if RELEASE_CHANNEL == "stable" :
# Update app-level metadata for store front page
app.update({
"version": VERSION_IPA,
"versionDate": VERSION_DATE,
"size": SIZE,
"sha256": SHA256,
"localizedDescription": LOCALIZED_DESCRIPTION,
"downloadURL": DOWNLOAD_URL,
})
# Process the versions array
channels = app.get("releaseChannels", [])
if not channels:
app["releaseChannels"] = channels
# create an entry and keep ready
new_version = {
"version": VERSION_IPA,
"date": VERSION_DATE,
"localizedDescription": LOCALIZED_DESCRIPTION,
"downloadURL": DOWNLOAD_URL,
"size": SIZE,
"sha256": SHA256,
}
tracks = [track for track in channels if track.get("track") == RELEASE_CHANNEL]
if len(tracks) > 1:
print(f"Multiple tracks with same `track` name = ${RELEASE_CHANNEL} are not allowed!")
sys.exit(1)
if not tracks:
# there was no entries in this release channel so create one
track = {
"track": RELEASE_CHANNEL,
"releases": [new_version]
}
channels.insert(0, track)
else:
track = tracks[0] # first result is the selected track
# Update the existing TOP version object entry
track["releases"][0] = new_version
updated = True
break
if not updated:
print("No app with the specified bundle identifier found.")
sys.exit(1)
# Save the updated JSON to the input file
try:
print("\nUpdated Sources File:\n")
print(json.dumps(data, indent=2, ensure_ascii=False))
with open(input_file, "w", encoding="utf-8") as file:
json.dump(data, file, indent=2, ensure_ascii=False)
print("JSON successfully updated.")
except Exception as e:
print(f"Error writing to the file: {e}")
sys.exit(1)