Skip to content

Commit

Permalink
feat(bump-versions.sh): Add support to lib-multisrc
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky committed Feb 16, 2024
1 parent b1e2314 commit 76dfd06
Showing 1 changed file with 16 additions and 57 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

0 comments on commit 76dfd06

Please sign in to comment.