Skip to content

Commit

Permalink
refactor: Simplify multisrc structure (#2942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky authored Mar 4, 2024
1 parent 0064c56 commit 42159cc
Show file tree
Hide file tree
Showing 418 changed files with 672 additions and 1,078 deletions.
73 changes: 16 additions & 57 deletions .github/scripts/bump-versions.sh
Original file line number Diff line number Diff line change
@@ -1,64 +1,12 @@
#!/bin/bash
versionStr="extVersionCode ="
multisrcVersionStr="overrideVersionCode ="
versionStr="VersionCode ="
bumpedFiles=""


# cut -d "=" -f 2 -> string.split("=")[1]
# "extVersionCode = 6" -> ["extVersionCode ", " 6"] -> " 6" -> "6"
getValue() { cut -d "=" -f 2 | cut -d " " -f 2;}
getVersion() {
if [[ $1 =~ ^multisrc/ ]]; then
# We are going to be piped, so no file specified, just read from stdin.
grep -Po "$multisrcVersionStr \d+" | getValue
else
grep "$versionStr" "$1" | getValue
fi
}

# expected input: multisrc/overrides/<theme>/<override>/....
# if override is default, then it will bump all overrides.
bumpMultisrcVersion() {
local overridePath=$1
# Prevents bumping extensions multiple times.
# Ex: When a theme uses a extractor per default, but one extension(override)
# also uses another, so if both libs are modifyed, such extension will be
# bumped only once instead of two times.
if [[ $bumpedFiles =~( |^)$overridePath( |$) ]]; then
return 0
fi

bumpedFiles+="$overridePath "

# Bump all extensions from a multisrc that implements a lib by default
if [[ $overridePath =~ .*/default/.* ]]; then
local themeBase=$(echo $overridePath | cut -d/ -f-3)
for file in $(ls $themeBase | grep -v default); do
bumpMultisrcVersion $themeBase/$file/
done
else
local theme=$(echo $overridePath | cut -d/ -f3)
local themePath="multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/$theme"
local sourceName=$(echo $overridePath | cut -d/ -f4)
local generator=$(echo $themePath/*Generator.kt)
bumpedFiles+="$generator " # Needed to commit the changes

local sourceLine=$(grep "Lang(" $generator | grep -i $sourceName)
local oldVersion=$(echo $sourceLine | getVersion $generator)
local newVersionStr="$multisrcVersionStr $((oldVersion + 1))"

if [[ $sourceLine =~ .*$multisrcVersionStr.* ]]; then
# if the override already have a "overrideVersionCode" param at
# the generator, then just bump it
local newSourceLine=${sourceLine/$multisrcVersionStr $oldVersion/$newVersionStr}
else
# else, add overrideVersionCode param to its line on the generator
local newSourceLine=${sourceLine/)/, $newVersionStr)}
fi

echo -e "\nmultisrc $sourceName($theme): $oldVersion -> $((oldVersion + 1))\n"
sed -i "s@$sourceLine@$newSourceLine@g" $generator
fi
grep "$versionStr" "$1" | getValue
}

bumpVersion() {
Expand All @@ -70,13 +18,24 @@ bumpVersion() {
sed -i "s/$versionStr $oldVersion/$versionStr $newVersion/" $file
}

bumpLibMultisrcVersion() {
local themeName=$(echo $1 | grep -Eo "lib-multisrc/\w+" | cut -c 14-)
for file in $(grep -l -R "themePkg = '$themeName'" --include build.gradle src/); do
# prevent bumping the same extension multiple times
if [[ ! $bumpedFiles =~ ( |^)$file( |$) ]]; then
bumpedFiles+="$file "
bumpVersion $file
fi
done
}

findAndBump() {
for lib in $@; do
for file in $(grep -l -R ":lib:$lib" --include "build.gradle" --include "additional.gradle"); do
for file in $(grep -l -R ":lib:$lib" --include "build.gradle" --include "build.gradle.kts" src/ lib-multisrc/); do
# prevent bumping the same extension multiple times
if [[ ! $bumpedFiles =~ ( |^)$file( |$) ]]; then
if [[ $file =~ ^multisrc ]]; then
bumpMultisrcVersion ${file/additional.gradle/}
if [[ $file =~ ^lib-multisrc ]]; then
bumpLibMultisrcVersion ${file/build.gradle.kts/}
else
bumpedFiles+="$file "
bumpVersion $file
Expand Down
95 changes: 5 additions & 90 deletions .github/workflows/build_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,121 +21,37 @@ jobs:
runs-on: ubuntu-latest
outputs:
individualMatrix: ${{ steps.generate-matrices.outputs.individualMatrix }}
multisrcMatrix: ${{ steps.generate-matrices.outputs.multisrcMatrix }}
isIndividualChanged: ${{ steps.parse-changed-files.outputs.isIndividualChanged }}
isMultisrcChanged: ${{ steps.parse-changed-files.outputs.isMultisrcChanged }}
env:
CI_MODULE_GEN: true
steps:
- name: Clone repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@27152f6fa06a6b8062ef7195c795692e51fc2c81 # v2

- name: Set up JDK
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4
with:
java-version: 17
distribution: temurin

- id: get-changed-files
name: Get changed files
uses: Ana06/get-changed-files@e0c398b7065a8d84700c471b6afc4116d1ba4e96 # v2.2.0

- id: parse-changed-files
name: Parse changed files
run: |
isIndividualChanged=0
isMultisrcChanged=0
for changedFile in ${{ steps.get-changed-files.outputs.all }}; do
if [[ ${changedFile} == src/* ]]; then
isIndividualChanged=1
elif [[ ${changedFile} == multisrc/* ]]; then
isMultisrcChanged=1
elif [[ ${changedFile} == .github/workflows/issue_moderator.yml ]]; then
true
elif [[ ${changedFile} == *.md ]]; then
true
else
isIndividualChanged=1
isMultisrcChanged=1
break
fi
done
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' }}
run: ./gradlew :multisrc:generateExtensions
uses: gradle/wrapper-validation-action@a494d935f4b56874c4a5a87d19af7afcf3a163d0 # v2

- name: Get number of modules
run: |
set -x
./gradlew -q projects | grep '.*extensions\:\(individual\|multisrc\)\:.*\:.*' > projects.txt
projects=(src/*/*)
echo "NUM_INDIVIDUAL_MODULES=$(cat projects.txt | grep '.*\:individual\:.*' | wc -l)" >> $GITHUB_ENV
echo "NUM_MULTISRC_MODULES=$(cat projects.txt | grep '.*\:multisrc\:.*' | wc -l)" >> $GITHUB_ENV
echo "NUM_INDIVIDUAL_MODULES=${#projects[@]}" >> $GITHUB_ENV
- id: generate-matrices
name: Create output matrices
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const numIndividualModules = process.env.NUM_INDIVIDUAL_MODULES;
const numMultisrcModules = process.env.NUM_MULTISRC_MODULES;
const chunkSize = process.env.CI_CHUNK_SIZE;
const numIndividualChunks = Math.ceil(numIndividualModules / chunkSize);
const numMultisrcChunks = Math.ceil(numMultisrcModules / chunkSize);
console.log(`Individual modules: ${numIndividualModules} (${numIndividualChunks} chunks of ${chunkSize})`);
console.log(`Multi-source modules: ${numMultisrcModules} (${numMultisrcChunks} chunks of ${chunkSize})`);
core.setOutput('individualMatrix', { 'chunk': [...Array(numIndividualChunks).keys()] });
core.setOutput('multisrcMatrix', { 'chunk': [...Array(numMultisrcChunks).keys()] });
build_multisrc:
name: Build multisrc modules
needs: prepare
if: ${{ needs.prepare.outputs.isMultisrcChanged == '1' }}
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.multisrcMatrix) }}
steps:
- name: Checkout PR
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up JDK
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4
with:
java-version: 17
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
env:
CI_MODULE_GEN: "true"
run: ./gradlew :multisrc:generateExtensions

- name: Build extensions (chunk ${{ matrix.chunk }})
env:
CI_MULTISRC: "true"
CI_CHUNK_NUM: ${{ matrix.chunk }}
run: ./gradlew assembleDebug
build_individual:
name: Build individual modules
needs: prepare
if: ${{ needs.prepare.outputs.isIndividualChanged == '1' }}
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.individualMatrix) }}
Expand All @@ -150,12 +66,11 @@ jobs:
distribution: temurin

- name: Set up Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3
with:
cache-read-only: true

- name: Build extensions (chunk ${{ matrix.chunk }})
env:
CI_MULTISRC: "false"
CI_CHUNK_NUM: ${{ matrix.chunk }}
run: ./gradlew assembleDebug
run: ./gradlew -p src assembleDebug
86 changes: 7 additions & 79 deletions .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
runs-on: ubuntu-latest
outputs:
individualMatrix: ${{ steps.generate-matrices.outputs.individualMatrix }}
multisrcMatrix: ${{ steps.generate-matrices.outputs.multisrcMatrix }}
env:
CI_MODULE_GEN: true
steps:
- name: Clone repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
Expand Down Expand Up @@ -58,95 +55,28 @@ jobs:
./.github/scripts/bump-versions.sh ${{ steps.modified-libs.outputs.all_changed_files }}
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@27152f6fa06a6b8062ef7195c795692e51fc2c81 # v2

- name: Set up JDK
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4
with:
java-version: 17
distribution: temurin

- name: Set up Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3

- name: Generate multisrc sources
run: ./gradlew :multisrc:generateExtensions
uses: gradle/wrapper-validation-action@a494d935f4b56874c4a5a87d19af7afcf3a163d0 # v2

- name: Get number of modules
run: |
set -x
./gradlew -q projects | grep '.*extensions\:\(individual\|multisrc\)\:.*\:.*' > projects.txt
projects=(src/*/*)
echo "NUM_INDIVIDUAL_MODULES=$(cat projects.txt | grep '.*\:individual\:.*' | wc -l)" >> $GITHUB_ENV
echo "NUM_MULTISRC_MODULES=$(cat projects.txt | grep '.*\:multisrc\:.*' | wc -l)" >> $GITHUB_ENV
echo "NUM_INDIVIDUAL_MODULES=${#projects[@]}" >> $GITHUB_ENV
- id: generate-matrices
name: Create output matrices
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const numIndividualModules = process.env.NUM_INDIVIDUAL_MODULES;
const numMultisrcModules = process.env.NUM_MULTISRC_MODULES;
const chunkSize = process.env.CI_CHUNK_SIZE;
const numIndividualChunks = Math.ceil(numIndividualModules / chunkSize);
const numMultisrcChunks = Math.ceil(numMultisrcModules / chunkSize);
console.log(`Individual modules: ${numIndividualModules} (${numIndividualChunks} chunks of ${chunkSize})`);
console.log(`Multi-source modules: ${numMultisrcModules} (${numMultisrcChunks} chunks of ${chunkSize})`);
core.setOutput('individualMatrix', { 'chunk': [...Array(numIndividualChunks).keys()] });
core.setOutput('multisrcMatrix', { 'chunk': [...Array(numMultisrcChunks).keys()] });
build_multisrc:
name: Build multisrc modules
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.multisrcMatrix) }}
steps:
- name: Checkout master branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
ref: master

- name: Set up JDK
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4
with:
java-version: 17
distribution: temurin

- name: Prepare signing key
run: |
echo ${{ secrets.SIGNING_KEY }} | base64 -d > signingkey.jks
- name: Set up Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3

- name: Generate sources from the multi-source library
env:
CI_MODULE_GEN: "true"
run: ./gradlew :multisrc:generateExtensions

- name: Build extensions (chunk ${{ matrix.chunk }})
env:
CI_MULTISRC: "true"
CI_CHUNK_NUM: ${{ matrix.chunk }}
ALIAS: ${{ secrets.ALIAS }}
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: ./gradlew assembleRelease

- name: Upload APKs (chunk ${{ matrix.chunk }})
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4
if: "github.repository == 'aniyomiorg/aniyomi-extensions'"
with:
name: "multisrc-apks-${{ matrix.chunk }}"
path: "**/*.apk"
retention-days: 1

- name: Clean up CI files
run: rm signingkey.jks
build_individual:
name: Build individual modules
Expand All @@ -171,19 +101,18 @@ jobs:
echo ${{ secrets.SIGNING_KEY }} | base64 -d > signingkey.jks
- name: Set up Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3

- name: Build extensions (chunk ${{ matrix.chunk }})
env:
CI_MULTISRC: "false"
CI_CHUNK_NUM: ${{ matrix.chunk }}
ALIAS: ${{ secrets.ALIAS }}
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: ./gradlew assembleRelease
run: ./gradlew -p src assembleRelease

- name: Upload APKs (chunk ${{ matrix.chunk }})
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
if: "github.repository == 'aniyomiorg/aniyomi-extensions'"
with:
name: "individual-apks-${{ matrix.chunk }}"
Expand All @@ -196,13 +125,12 @@ jobs:
publish_repo:
name: Publish repo
needs:
- build_multisrc
- build_individual
if: "github.repository == 'aniyomiorg/aniyomi-extensions'"
runs-on: ubuntu-latest
steps:
- name: Download APK artifacts
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4
with:
path: ~/apk-artifacts

Expand Down
11 changes: 0 additions & 11 deletions .run/AnimeStreamGenerator.run.xml

This file was deleted.

Loading

0 comments on commit 42159cc

Please sign in to comment.