Skip to content

Commit 177421c

Browse files
authored
ci: Port move-apks and create-repo to Python (keiyoushi#194)
* ci: Port move-apks and create-repo to Python * move-apks: Fix APK path
1 parent abdebd9 commit 177421c

File tree

5 files changed

+124
-95
lines changed

5 files changed

+124
-95
lines changed

.github/scripts/create-repo.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import json
2+
import os
3+
import re
4+
import subprocess
5+
from pathlib import Path
6+
from zipfile import ZipFile
7+
8+
PACKAGE_NAME_REGEX = re.compile(r"package: name='([^']+)'")
9+
VERSION_CODE_REGEX = re.compile(r"versionCode='([^']+)'")
10+
VERSION_NAME_REGEX = re.compile(r"versionName='([^']+)'")
11+
IS_NSFW_REGEX = re.compile(r"'tachiyomi.extension.nsfw' value='([^']+)'")
12+
APPLICATION_LABEL_REGEX = re.compile(r"^application-label:'([^']+)'", re.MULTILINE)
13+
APPLICATION_ICON_320_REGEX = re.compile(
14+
r"^application-icon-320:'([^']+)'", re.MULTILINE
15+
)
16+
LANGUAGE_REGEX = re.compile(r"tachiyomi-([^\.]+)")
17+
18+
*_, ANDROID_BUILD_TOOLS = (Path(os.environ["ANDROID_HOME"]) / "build-tools").iterdir()
19+
REPO_DIR = Path("repo")
20+
REPO_APK_DIR = REPO_DIR / "apk"
21+
REPO_ICON_DIR = REPO_DIR / "icon"
22+
23+
REPO_ICON_DIR.mkdir(parents=True, exist_ok=True)
24+
25+
with open("output.json", encoding="utf-8") as f:
26+
inspector_data = json.load(f)
27+
28+
index_data = []
29+
index_min_data = []
30+
31+
for apk in REPO_APK_DIR.iterdir():
32+
badging = subprocess.check_output(
33+
[
34+
ANDROID_BUILD_TOOLS / "aapt",
35+
"dump",
36+
"--include-meta-data",
37+
"badging",
38+
apk,
39+
]
40+
).decode()
41+
42+
package_info = next(x for x in badging.splitlines() if x.startswith("package: "))
43+
package_name = PACKAGE_NAME_REGEX.search(package_info).group(1)
44+
application_icon = APPLICATION_ICON_320_REGEX.search(badging).group(1)
45+
46+
with ZipFile(apk) as z, z.open(application_icon) as i, (
47+
REPO_ICON_DIR / f"{package_name}.png"
48+
).open("wb") as f:
49+
f.write(i.read())
50+
51+
language = LANGUAGE_REGEX.search(apk.name).group(1)
52+
sources = inspector_data[package_name]
53+
54+
if len(sources) == 1:
55+
source_language = sources[0]["lang"]
56+
57+
if (
58+
source_language != language
59+
and source_language not in {"all", "other"}
60+
and language not in {"all", "other"}
61+
):
62+
language = source_language
63+
64+
common_data = {
65+
"name": APPLICATION_LABEL_REGEX.search(badging).group(1),
66+
"pkg": package_name,
67+
"apk": apk.name,
68+
"lang": language,
69+
"code": int(VERSION_CODE_REGEX.search(package_info).group(1)),
70+
"version": VERSION_NAME_REGEX.search(package_info).group(1),
71+
"nsfw": int(IS_NSFW_REGEX.search(badging).group(1)),
72+
}
73+
min_data = {
74+
**common_data,
75+
"sources": [],
76+
}
77+
78+
for source in sources:
79+
min_data["sources"].append(
80+
{
81+
"name": source["name"],
82+
"lang": source["lang"],
83+
"id": source["id"],
84+
"baseUrl": source["baseUrl"],
85+
}
86+
)
87+
88+
index_min_data.append(min_data)
89+
index_data.append(
90+
{
91+
**common_data,
92+
"hasReadme": 0,
93+
"hasChangelog": 0,
94+
"sources": sources,
95+
}
96+
)
97+
98+
with (REPO_DIR / "index.json").open("w", encoding="utf-8") as f:
99+
index_data_str = json.dumps(index_data, ensure_ascii=False, indent=2)
100+
101+
print(index_data_str)
102+
f.write(index_data_str)
103+
104+
with (REPO_DIR / "index.min.json").open("w", encoding="utf-8") as f:
105+
json.dump(index_min_data, f, ensure_ascii=False, separators=(",", ":"))

.github/scripts/create-repo.sh

Lines changed: 0 additions & 66 deletions
This file was deleted.

.github/scripts/move-apks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pathlib import Path
2+
import shutil
3+
4+
REPO_APK_DIR = Path("repo/apk")
5+
6+
try:
7+
shutil.rmtree(REPO_APK_DIR)
8+
except FileNotFoundError:
9+
pass
10+
11+
REPO_APK_DIR.mkdir(parents=True, exist_ok=True)
12+
13+
for apk in (Path.home() / "apk-artifacts").glob("**/*.apk"):
14+
apk_name = apk.name.replace("-release.apk", ".apk")
15+
16+
shutil.move(apk, REPO_APK_DIR / apk_name)

.github/scripts/move-apks.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/build_push.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ jobs:
187187
- name: Create repo artifacts
188188
run: |
189189
cd main
190-
./.github/scripts/move-apks.sh
190+
python ./.github/scripts/move-apks.py
191191
INSPECTOR_LINK="$(curl -s "https://api.github.com/repos/tachiyomiorg/tachiyomi-extensions-inspector/releases/latest" | jq -r '.assets[0].browser_download_url')"
192192
curl -L "$INSPECTOR_LINK" -o ./Inspector.jar
193-
java -jar ./Inspector.jar "apk" "output.json" "tmp"
194-
./.github/scripts/create-repo.sh
193+
java -jar ./Inspector.jar "repo/apk" "output.json" "tmp"
194+
python ./.github/scripts/create-repo.py
195195
196196
- name: Checkout repo branch
197197
uses: actions/checkout@v4

0 commit comments

Comments
 (0)