forked from AlmightyHak/extensions-source
Initial commit
This commit is contained in:
commit
98ed7e8839
2263 changed files with 108711 additions and 0 deletions
75
.github/scripts/bump-versions.py
vendored
Normal file
75
.github/scripts/bump-versions.py
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
|
||||
import itertools
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
VERSION_STR = "VersionCode ="
|
||||
VERSION_REGEX = re.compile(f"{VERSION_STR} (\\d+)")
|
||||
BUMPED_FILES: list[Path] = []
|
||||
|
||||
BOT_EMAIL = "aniyomi-bot@aniyomi.org"
|
||||
BOT_NAME = "aniyomi-bot[bot]"
|
||||
|
||||
def has_match(query: str, file: Path) -> tuple[Path, bool]:
|
||||
return (file, query in file.read_text())
|
||||
|
||||
def find_files_with_match(query: str, include_multisrc: bool = True) -> list[Path]:
|
||||
files = Path("src").glob("*/*/build.gradle")
|
||||
if include_multisrc:
|
||||
files = itertools.chain(files, Path("lib-multisrc").glob("*/build.gradle.kts"))
|
||||
|
||||
# Prevent bumping files twice.
|
||||
files = filter(lambda file: file not in BUMPED_FILES, files)
|
||||
|
||||
# Use multiple threads to find matches.
|
||||
with ThreadPoolExecutor() as executor:
|
||||
futures = [executor.submit(has_match, query, file) for file in files]
|
||||
results = map(Future.result, as_completed(futures))
|
||||
return [path for path, result in results if result]
|
||||
|
||||
def replace_version(match: re.Match) -> str:
|
||||
version = int(match.group(1))
|
||||
print(f"{version} -> {version + 1}")
|
||||
return f"{VERSION_STR} {version + 1}"
|
||||
|
||||
def bump_version(file: Path):
|
||||
BUMPED_FILES.append(file)
|
||||
with file.open("r+") as f:
|
||||
print(f"\n{file}: ", end="")
|
||||
text = VERSION_REGEX.sub(replace_version, f.read())
|
||||
# Move the cursor to the start again, to prevent writing at the end
|
||||
f.seek(0)
|
||||
f.write(text)
|
||||
|
||||
def bump_lib_multisrc(theme: str):
|
||||
for file in find_files_with_match(f"themePkg = '{theme}'", include_multisrc=False):
|
||||
bump_version(file)
|
||||
|
||||
def commit_changes():
|
||||
paths = [str(path.resolve()) for path in BUMPED_FILES]
|
||||
subprocess.check_call(["git", "config", "--local", "user.email", BOT_EMAIL])
|
||||
subprocess.check_call(["git", "config", "--local", "user.name", BOT_NAME])
|
||||
subprocess.check_call(["git", "add"] + paths)
|
||||
subprocess.check_call(["git", "commit", "-S", "-m", "[skip ci] chore: Mass-bump on extensions"])
|
||||
subprocess.check_call(["git", "push"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
# Regex to match the lib name in the path, like "unpacker" or "dood-extractor".
|
||||
lib_regex = re.compile(r"lib/([a-z0-9-]+)/")
|
||||
# Find matches and remove None results.
|
||||
matches = filter(None, map(lib_regex.search, sys.argv[1:]))
|
||||
for match in matches:
|
||||
project_path = ":lib:" + match.group(1)
|
||||
for file in find_files_with_match(project_path):
|
||||
if file.parent.parent.name == "lib-multisrc":
|
||||
bump_lib_multisrc(file.parent.name)
|
||||
else:
|
||||
bump_version(file)
|
||||
|
||||
if len(BUMPED_FILES) > 0:
|
||||
commit_changes()
|
17
.github/scripts/commit-repo.sh
vendored
Normal file
17
.github/scripts/commit-repo.sh
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
rsync -a --delete --exclude .git --exclude .gitignore ../master/repo/ .
|
||||
git config --global user.email "aniyomi-bot@aniyomi.org"
|
||||
git config --global user.name "aniyomi-bot[bot]"
|
||||
git status
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git add .
|
||||
git commit -S -m "Update extensions repo"
|
||||
git push
|
||||
|
||||
# Purge cached index on jsDelivr
|
||||
curl https://purge.jsdelivr.net/gh/aniyomiorg/aniyomi-extensions@repo/index.min.json
|
||||
else
|
||||
echo "No changes to commit"
|
||||
fi
|
108
.github/scripts/create-repo.py
vendored
Normal file
108
.github/scripts/create-repo.py
vendored
Normal file
|
@ -0,0 +1,108 @@
|
|||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
PACKAGE_NAME_REGEX = re.compile(r"package: name='([^']+)'")
|
||||
VERSION_CODE_REGEX = re.compile(r"versionCode='([^']+)'")
|
||||
VERSION_NAME_REGEX = re.compile(r"versionName='([^']+)'")
|
||||
IS_NSFW_REGEX = re.compile(r"'tachiyomi.animeextension.nsfw' value='([^']+)'")
|
||||
APPLICATION_LABEL_REGEX = re.compile(r"^application-label:'([^']+)'", re.MULTILINE)
|
||||
APPLICATION_ICON_320_REGEX = re.compile(
|
||||
r"^application-icon-320:'([^']+)'", re.MULTILINE
|
||||
)
|
||||
LANGUAGE_REGEX = re.compile(r"aniyomi-([^\.]+)")
|
||||
|
||||
*_, ANDROID_BUILD_TOOLS = (Path(os.environ["ANDROID_HOME"]) / "build-tools").iterdir()
|
||||
REPO_DIR = Path("repo")
|
||||
REPO_APK_DIR = REPO_DIR / "apk"
|
||||
REPO_ICON_DIR = REPO_DIR / "icon"
|
||||
|
||||
REPO_ICON_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with open("output.json", encoding="utf-8") as f:
|
||||
inspector_data = json.load(f)
|
||||
|
||||
index_data = []
|
||||
index_min_data = []
|
||||
|
||||
for apk in REPO_APK_DIR.iterdir():
|
||||
badging = subprocess.check_output(
|
||||
[
|
||||
ANDROID_BUILD_TOOLS / "aapt",
|
||||
"dump",
|
||||
"--include-meta-data",
|
||||
"badging",
|
||||
apk,
|
||||
]
|
||||
).decode()
|
||||
|
||||
package_info = next(x for x in badging.splitlines() if x.startswith("package: "))
|
||||
package_name = PACKAGE_NAME_REGEX.search(package_info).group(1)
|
||||
application_icon = APPLICATION_ICON_320_REGEX.search(badging).group(1)
|
||||
|
||||
with ZipFile(apk) as z, z.open(application_icon) as i, (
|
||||
REPO_ICON_DIR / f"{package_name}.png"
|
||||
).open("wb") as f:
|
||||
f.write(i.read())
|
||||
|
||||
language = LANGUAGE_REGEX.search(apk.name).group(1)
|
||||
sources = inspector_data[package_name]
|
||||
|
||||
if len(sources) == 1:
|
||||
source_language = sources[0]["lang"]
|
||||
|
||||
if (
|
||||
source_language != language
|
||||
and source_language not in {"all", "other"}
|
||||
and language not in {"all", "other"}
|
||||
):
|
||||
language = source_language
|
||||
|
||||
common_data = {
|
||||
"name": APPLICATION_LABEL_REGEX.search(badging).group(1),
|
||||
"pkg": package_name,
|
||||
"apk": apk.name,
|
||||
"lang": language,
|
||||
"code": int(VERSION_CODE_REGEX.search(package_info).group(1)),
|
||||
"version": VERSION_NAME_REGEX.search(package_info).group(1),
|
||||
"nsfw": int(IS_NSFW_REGEX.search(badging).group(1)),
|
||||
}
|
||||
min_data = {
|
||||
**common_data,
|
||||
"sources": [],
|
||||
}
|
||||
|
||||
for source in sources:
|
||||
min_data["sources"].append(
|
||||
{
|
||||
"name": source["name"],
|
||||
"lang": source["lang"],
|
||||
"id": source["id"],
|
||||
"baseUrl": source["baseUrl"],
|
||||
}
|
||||
)
|
||||
|
||||
index_min_data.append(min_data)
|
||||
index_data.append(
|
||||
{
|
||||
**common_data,
|
||||
"hasReadme": 0,
|
||||
"hasChangelog": 0,
|
||||
"sources": sources,
|
||||
}
|
||||
)
|
||||
|
||||
index_data.sort(key=lambda x: x["pkg"])
|
||||
index_min_data.sort(key=lambda x: x["pkg"])
|
||||
|
||||
with (REPO_DIR / "index.json").open("w", encoding="utf-8") as f:
|
||||
index_data_str = json.dumps(index_data, ensure_ascii=False, indent=2)
|
||||
|
||||
print(index_data_str)
|
||||
f.write(index_data_str)
|
||||
|
||||
with (REPO_DIR / "index.min.json").open("w", encoding="utf-8") as f:
|
||||
json.dump(index_min_data, f, ensure_ascii=False, separators=(",", ":"))
|
16
.github/scripts/move-apks.py
vendored
Normal file
16
.github/scripts/move-apks.py
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
REPO_APK_DIR = Path("repo/apk")
|
||||
|
||||
try:
|
||||
shutil.rmtree(REPO_APK_DIR)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
REPO_APK_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for apk in (Path.home() / "apk-artifacts").glob("**/*.apk"):
|
||||
apk_name = apk.name.replace("-release.apk", ".apk")
|
||||
|
||||
shutil.move(apk, REPO_APK_DIR / apk_name)
|
52
.github/scripts/sign-apks.sh
vendored
Normal file
52
.github/scripts/sign-apks.sh
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
TOOLS="$(ls -d ${ANDROID_HOME}/build-tools/* | tail -1)"
|
||||
|
||||
shopt -s globstar nullglob extglob
|
||||
APKS=( **/*".apk" )
|
||||
|
||||
# Fail if too little extensions seem to have been built
|
||||
if [ "${#APKS[@]}" -le "50" ]; then
|
||||
echo "Insufficient amount of APKs found. Please check the project configuration."
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# Take base64 encoded key input and put it into a file
|
||||
STORE_PATH=$PWD/signingkey.jks
|
||||
rm -f $STORE_PATH && touch $STORE_PATH
|
||||
echo $1 | base64 -d > $STORE_PATH
|
||||
|
||||
STORE_ALIAS=$2
|
||||
export KEY_STORE_PASSWORD=$3
|
||||
export KEY_PASSWORD=$4
|
||||
|
||||
DEST=$PWD/apk
|
||||
rm -rf $DEST && mkdir -p $DEST
|
||||
|
||||
MAX_PARALLEL=4
|
||||
|
||||
# Sign all of the APKs
|
||||
for APK in ${APKS[@]}; do
|
||||
(
|
||||
BASENAME=$(basename $APK)
|
||||
APKNAME="${BASENAME%%+(-release*)}.apk"
|
||||
APKDEST="$DEST/$APKNAME"
|
||||
|
||||
${TOOLS}/zipalign -c -v -p 4 $APK
|
||||
|
||||
cp $APK $APKDEST
|
||||
${TOOLS}/apksigner sign --ks $STORE_PATH --ks-key-alias $STORE_ALIAS --ks-pass env:KEY_STORE_PASSWORD --key-pass env:KEY_PASSWORD $APKDEST
|
||||
) &
|
||||
|
||||
# Allow to execute up to $MAX_PARALLEL jobs in parallel
|
||||
if [[ $(jobs -r -p | wc -l) -ge $MAX_PARALLEL ]]; then
|
||||
wait -n
|
||||
fi
|
||||
done
|
||||
|
||||
wait
|
||||
|
||||
rm $STORE_PATH
|
||||
unset KEY_STORE_PASSWORD
|
||||
unset KEY_PASSWORD
|
Loading…
Add table
Add a link
Reference in a new issue