Skip to content

Commit 30ec785

Browse files
committed
add build workflow
1 parent a9989e1 commit 30ec785

2 files changed

Lines changed: 174 additions & 0 deletions

File tree

.github/scripts/create-repo.py

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

.github/workflows/build_push.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '**'
9+
- '!**.md'
10+
- '!.github/**'
11+
- '.github/scripts/**'
12+
- '.github/workflows/build_push.yml'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build:
20+
name: build repo
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout main branch
24+
uses: actions/checkout@v4.2.2
25+
with:
26+
ref: main
27+
path: main
28+
29+
- name: Set up JDK
30+
uses: actions/setup-java@v4.6.0
31+
with:
32+
java-version: 17
33+
distribution: temurin
34+
35+
- name: Prepare signing key
36+
run: |
37+
echo ${{ secrets.KEYSTORE }} | base64 -d > main/signingkey.jks
38+
39+
- name: Set up Gradle
40+
uses: gradle/actions/setup-gradle@v4.2.2
41+
42+
- name: Grant execute permission for gradlew
43+
run: chmod +x main/gradlew
44+
45+
- name: Build extensions (chunk ${{ matrix.chunk }})
46+
env:
47+
ALIAS: ${{ secrets.ALIAS }}
48+
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
49+
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
50+
run: |
51+
cd main
52+
./gradlew -p src assembleRelease
53+
54+
- name: Clean up CI files
55+
run: rm main/signingkey.jks
56+
57+
- name: Checkout repo branch
58+
uses: actions/checkout@v4.2.2
59+
with:
60+
ref: repo
61+
path: repo
62+
63+
- name: Create repo artifacts
64+
run: |
65+
cd main
66+
mkdir -p repo/apk
67+
mv **/*.apk repo/apk/
68+
INSPECTOR_LINK="$(curl -s "https://api.github.com/repos/keiyoushi/extensions-inspector/releases/latest" | jq -r '.assets[0].browser_download_url')"
69+
curl -L "$INSPECTOR_LINK" -o ./Inspector.jar
70+
java -jar ./Inspector.jar "repo/apk" "output.json" "tmp"
71+
python ./.github/scripts/create-repo.py
72+
73+
- name: Commit repo
74+
run: |
75+
cd repo
76+
rsync -a --delete --exclude .git --exclude .gitignore --exclude repo.json ../main/repo/ .
77+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
78+
git config --global user.name "github-actions[bot]"
79+
git status
80+
if [ -n "$(git status --porcelain)" ]; then
81+
git add .
82+
git commit -m "Update extensions repo"
83+
git push
84+
else
85+
echo "No changes to commit"
86+
fi

0 commit comments

Comments
 (0)