-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use python scripts and remove unnessecary manifests (#2876)
Co-authored-by: jmir1 <[email protected]>
- Loading branch information
1 parent
3d05621
commit 5068d25
Showing
184 changed files
with
291 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=(",", ":")) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ name: PR build check | |
|
||
on: | ||
pull_request: | ||
paths-ignore: | ||
- '**.md' | ||
- '.github/workflows/issue_moderator.yml' | ||
paths: | ||
- '**' | ||
- '!**.md' | ||
- '!.github/**' | ||
- '.github/workflows/build_pull_request.yml' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
|
@@ -26,20 +28,20 @@ jobs: | |
CI_MODULE_GEN: true | ||
steps: | ||
- name: Clone repo | ||
uses: actions/checkout@v4 | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | ||
|
||
- name: Validate Gradle Wrapper | ||
uses: gradle/wrapper-validation-action@v1 | ||
uses: gradle/wrapper-validation-action@27152f6fa06a6b8062ef7195c795692e51fc2c81 # v2 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4 | ||
with: | ||
java-version: 17 | ||
distribution: adopt | ||
distribution: temurin | ||
|
||
- id: get-changed-files | ||
name: Get changed files | ||
uses: Ana06/[email protected] | ||
uses: Ana06/get-changed-files@e0c398b7065a8d84700c471b6afc4116d1ba4e96 # v2.2.0 | ||
|
||
- id: parse-changed-files | ||
name: Parse changed files | ||
|
@@ -64,11 +66,12 @@ jobs: | |
echo "isIndividualChanged=$isIndividualChanged" >> $GITHUB_OUTPUT | ||
echo "isMultisrcChanged=$isMultisrcChanged" >> $GITHUB_OUTPUT | ||
- name: Set up Gradle | ||
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3 | ||
|
||
- name: Generate multisrc sources | ||
if: ${{ steps.parse-changed-files.outputs.isMultisrcChanged == '1' }} | ||
uses: gradle/gradle-build-action@v2 | ||
with: | ||
arguments: :multisrc:generateExtensions | ||
run: ./gradlew :multisrc:generateExtensions | ||
|
||
- name: Get number of modules | ||
run: | | ||
|
@@ -80,7 +83,7 @@ jobs: | |
- id: generate-matrices | ||
name: Create output matrices | ||
uses: actions/github-script@v7 | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 | ||
with: | ||
script: | | ||
const numIndividualModules = process.env.NUM_INDIVIDUAL_MODULES; | ||
|
@@ -105,30 +108,29 @@ jobs: | |
matrix: ${{ fromJSON(needs.prepare.outputs.multisrcMatrix) }} | ||
steps: | ||
- name: Checkout PR | ||
uses: actions/checkout@v4 | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4 | ||
with: | ||
java-version: 17 | ||
distribution: adopt | ||
distribution: temurin | ||
|
||
- name: Set up Gradle | ||
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3 | ||
with: | ||
cache-read-only: true | ||
|
||
- name: Generate sources from the multi-source library | ||
uses: gradle/gradle-build-action@v2 | ||
env: | ||
CI_MODULE_GEN: "true" | ||
with: | ||
arguments: :multisrc:generateExtensions | ||
cache-read-only: true | ||
run: ./gradlew :multisrc:generateExtensions | ||
|
||
- name: Build extensions (chunk ${{ matrix.chunk }}) | ||
uses: gradle/gradle-build-action@v2 | ||
env: | ||
CI_MULTISRC: "true" | ||
CI_CHUNK_NUM: ${{ matrix.chunk }} | ||
with: | ||
arguments: assembleDebug | ||
cache-read-only: true | ||
run: ./gradlew assembleDebug | ||
|
||
build_individual: | ||
name: Build individual modules | ||
|
@@ -139,19 +141,21 @@ jobs: | |
matrix: ${{ fromJSON(needs.prepare.outputs.individualMatrix) }} | ||
steps: | ||
- name: Checkout PR | ||
uses: actions/checkout@v4 | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4 | ||
with: | ||
java-version: 17 | ||
distribution: adopt | ||
distribution: temurin | ||
|
||
- name: Set up Gradle | ||
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3 | ||
with: | ||
cache-read-only: true | ||
|
||
- name: Build extensions (chunk ${{ matrix.chunk }}) | ||
uses: gradle/gradle-build-action@v2 | ||
env: | ||
CI_MULTISRC: "false" | ||
CI_CHUNK_NUM: ${{ matrix.chunk }} | ||
with: | ||
arguments: assembleDebug | ||
cache-read-only: true | ||
run: ./gradlew assembleDebug |
Oops, something went wrong.