Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NoName-exe authored Oct 1, 2023
2 parents 36028cf + cf35886 commit f6e8cc6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 81 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: Build Modules
on: [workflow_call, workflow_dispatch]
on:
workflow_call:
inputs:
from_ci:
type: boolean
required: false
default: true

workflow_dispatch:

jobs:
run:
Expand All @@ -17,19 +25,22 @@ jobs:
fetch-depth: 0
submodules: true

- name: Get last tag
id: last_tag
uses: oprypin/find-latest-tag@v1
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
releases-only: true
- name: Update config
if: ${{ inputs.from_ci }}
run: |
if git checkout origin/update build.md; then
UPDATE_CFG=$(./build.sh config.toml --config-update)
if [ "$UPDATE_CFG" ]; then
echo "$UPDATE_CFG" > config.toml
fi
fi
- name: Get next version code
id: next_ver_code
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.last_tag.outputs.tag }}"
TAG=$(gh release list -L 1 | awk -F '\t' '{print $3}')
if [ -z "$TAG" ]; then TAG=0; fi
echo "NEXT_VER_CODE=$((TAG + 1))" >> $GITHUB_OUTPUT
Expand Down
59 changes: 8 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,23 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source utils.sh
toml_prep "$(cat config.toml)"
is_youtube_latest() {
t=$(toml_get_table YouTube)
v=$(toml_get "$t" "version") || v=""
if isoneof "$v" latest beta; then
cur_yt=$(sed -n 's/.*YouTube: \(.*\)/\1/p' build.md | xargs)
[ -z "$cur_yt" ] && return 1 # empty, fail=>dont build
if [ "$v" = beta ]; then aav="true"; else aav="false"; fi
last_ver=$(get_apkmirror_vers youtube "$aav" | get_largest_ver)
[ -z "$last_ver" ] && return 1 # cant fetch, dont build
echo "current yt version: '$cur_yt'"
echo "latest yt version: '$last_ver'"
[ "$cur_yt" != "$last_ver" ] # test success=>build, fail=>dont build
else
return 1 # not experimental, dont build
fi
}
is_patches_latest() {
declare -A sources
sources["inotia00/revanced-patches"]=1
for table_name in $(toml_get_table_names); do
if [ -z "$table_name" ]; then continue; fi
t=$(toml_get_table "$table_name")
enabled=$(toml_get "$t" enabled) || enabled=true
if [ "$enabled" = false ]; then continue; fi
PATCHES_SRC=$(toml_get "$t" patches-source)
if [ "$PATCHES_SRC" ]; then sources[$PATCHES_SRC]=1; fi
done
for PATCHES_SRC in "${!sources[@]}"; do
echo "chk: '$PATCHES_SRC'"
last_patches_url=$(gh_req "https://api.github.com/repos/${PATCHES_SRC}/releases/latest" - | json_get 'browser_download_url' | grep 'jar')
last_patches=${last_patches_url##*/}
cur_patches=$(sed -n "s/.*Patches: ${PATCHES_SRC%%/*}\/\(.*\)/\1/p" build.md | xargs)
echo "current patches version: $cur_patches"
echo "latest patches version: $last_patches"
if [ -z "$cur_patches" ] || [ -z "$last_patches" ]; then continue; fi
if [ "$cur_patches" != "$last_patches" ]; then return 0; fi
done
return 1
}
if ! git checkout update; then
if ! git checkout origin/update build.md; then
echo "first time building!"
echo "SHOULD_BUILD=1" >> $GITHUB_OUTPUT
elif is_patches_latest || is_youtube_latest; then
echo "build!"
echo "SHOULD_BUILD=1" >> $GITHUB_OUTPUT
else
echo "dont build!"
echo "SHOULD_BUILD=0" >> $GITHUB_OUTPUT
UPDATE_CFG=$(./build.sh config.toml --config-update)
if [ "$UPDATE_CFG" ]; then
echo "SHOULD_BUILD=1" >> $GITHUB_OUTPUT
else
echo "SHOULD_BUILD=0" >> $GITHUB_OUTPUT
fi
fi
- name: Clear older runs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh run list -L400 --json databaseId -q '.[].databaseId' | tail -n+10 | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE || :
gh run list -L400 --json databaseId -q '.[].databaseId' | tail -n+10 | xargs -IID gh api "repos/$GITHUB_REPOSITORY/actions/runs/ID" -X DELETE || :
outputs:
SHOULD_BUILD: ${{ steps.should_build.outputs.SHOULD_BUILD }}
Expand Down
24 changes: 14 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ if [ "${1:-}" = "clean" ]; then
fi

source utils.sh
: >build.md

vtf() { if ! isoneof "${1}" "true" "false"; then abort "ERROR: '${1}' is not a valid option for '${2}': only true or false is allowed"; fi; }

toml_prep "$(cat 2>/dev/null "${1:-config.toml}")" || abort "could not find config file '${1:-config.toml}'\n\tUsage: $0 <config.toml>"
# -- Main config --
main_config_t=$(toml_get_table "")
COMPRESSION_LEVEL=$(toml_get "$main_config_t" compression-level) || COMPRESSION_LEVEL="9"
ENABLE_MAGISK_UPDATE=$(toml_get "$main_config_t" enable-magisk-update) || ENABLE_MAGISK_UPDATE=true
if [ "$ENABLE_MAGISK_UPDATE" = true ] && [ -z "${GITHUB_REPOSITORY:-}" ]; then
pr "You are building locally. Magisk updates will not be enabled."
ENABLE_MAGISK_UPDATE=false
fi
if ! PARALLEL_JOBS=$(toml_get "$main_config_t" parallel-jobs); then
if [ "$OS" = Android ]; then PARALLEL_JOBS=1; else PARALLEL_JOBS=$(nproc); fi
fi
Expand All @@ -33,17 +27,27 @@ DEF_PATCHES_SRC=$(toml_get "$main_config_t" patches-source) || DEF_PATCHES_SRC="
DEF_INTEGRATIONS_SRC=$(toml_get "$main_config_t" integrations-source) || DEF_INTEGRATIONS_SRC="ReVanced/revanced-integrations"
DEF_CLI_SRC=$(toml_get "$main_config_t" cli-source) || DEF_CLI_SRC="j-hc/revanced-cli"
DEF_RV_BRAND=$(toml_get "$main_config_t" rv-brand) || DEF_RV_BRAND="ReVanced"
# -- Main config --
mkdir -p $TEMP_DIR $BUILD_DIR
if [ "${2:-}" = "--config-update" ]; then
config_update
exit 0
fi
: >build.md
ENABLE_MAGISK_UPDATE=$(toml_get "$main_config_t" enable-magisk-update) || ENABLE_MAGISK_UPDATE=true
if [ "$ENABLE_MAGISK_UPDATE" = true ] && [ -z "${GITHUB_REPOSITORY:-}" ]; then
pr "You are building locally. Magisk updates will not be enabled."
ENABLE_MAGISK_UPDATE=false
fi
# -----------------

mkdir -p $TEMP_DIR $BUILD_DIR
if ((COMPRESSION_LEVEL > 9)) || ((COMPRESSION_LEVEL < 0)); then abort "compression-level must be within 0-9"; fi
if [ "$LOGGING_F" = true ]; then mkdir -p logs; fi

#check_deps
# -- check_deps --
jq --version >/dev/null || abort "\`jq\` is not installed. install it with 'apt install jq' or equivalent"
java --version >/dev/null || abort "\`openjdk 17\` is not installed. install it with 'apt install openjdk-17-jre' or equivalent"
zip --version >/dev/null || abort "\`zip\` is not installed. install it with 'apt install zip' or equivalent"
# --
# ----------------
get_prebuilts

set_prebuilts() {
Expand Down
50 changes: 40 additions & 10 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ toml_get_table_names() {
fi
echo "$tn"
}
toml_get_table() { sed -n "/\[${1}]/,/^\[.*]$/p" <<<"$__TOML__"; }
toml_get_table() { sed -n "/\[${1}]/,/^\[.*]$/p" <<<"$__TOML__" | sed '${/^\[/d;}'; }
toml_get() {
local table=$1 key=$2 val
val=$(grep -m 1 "^${key}=" <<<"$table") && sed -e "s/^\"//; s/\"$//" <<<"${val#*=}"
Expand Down Expand Up @@ -94,7 +94,8 @@ get_prebuilts() {
if [ "$OS" = Android ]; then
local arch
if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi
dl_if_dne ${TEMP_DIR}/aapt2 https://github.com/rendiix/termux-aapt/raw/d7d4b4a344cc52b94bcdab3500be244151261d8e/prebuilt-binary/${arch}/aapt2 && chmod +x "${TEMP_DIR}/aapt2"
dl_if_dne ${TEMP_DIR}/aapt2 https://github.com/rendiix/termux-aapt/raw/d7d4b4a344cc52b94bcdab3500be244151261d8e/prebuilt-binary/${arch}/aapt2
chmod +x "${TEMP_DIR}/aapt2"
fi
mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm
dl_if_dne "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a"
Expand All @@ -119,6 +120,31 @@ get_prebuilts() {
fi
}

config_update() {
declare -A sources
for table_name in $(toml_get_table_names); do
if [ -z "$table_name" ]; then continue; fi
t=$(toml_get_table "$table_name")
enabled=$(toml_get "$t" enabled) || enabled=true
if [ "$enabled" = false ]; then continue; fi
PATCHES_SRC=$(toml_get "$t" patches-source) || PATCHES_SRC=$DEF_PATCHES_SRC
if [[ -v sources[$PATCHES_SRC] ]]; then
if [ "${sources[$PATCHES_SRC]}" = 1 ]; then echo "$t"; fi
else
sources[$PATCHES_SRC]=0
if ! last_patches_url=$(gh_req "https://api.github.com/repos/${PATCHES_SRC}/releases/latest" - 2>&1 | json_get 'browser_download_url' | grep 'jar'); then
abort oops
fi
last_patches=${last_patches_url##*/}
cur_patches=$(sed -n "s/.*Patches: ${PATCHES_SRC%%/*}\/\(.*\)/\1/p" build.md | xargs)
if [ "$cur_patches" ] && [ "$last_patches" ] && [ "${cur_patches}" != "$last_patches" ]; then
sources[$PATCHES_SRC]=1
echo "$t"
fi
fi
done
}

_req() {
if [ "$2" = - ]; then
wget -nv -O "$2" --header="$3" "$1"
Expand Down Expand Up @@ -269,10 +295,9 @@ get_apkmonk_pkg_name() { grep -oP '.*apkmonk\.com\/app\/\K([,\w,\.]*)' <<<"$1";
# --------------------------------------------------

patch_apk() {
local stock_input=$1 patched_apk=$2 patcher_args=$3 rv_cli_jar=$4 rv_patches_jar=$5 riplib=$6
local stock_input=$1 patched_apk=$2 patcher_args=$3 rv_cli_jar=$4 rv_patches_jar=$5
declare -r tdir=$(mktemp -d -p $TEMP_DIR)
local cmd="java -jar $rv_cli_jar patch $stock_input -r $tdir -p -o $patched_apk -b $rv_patches_jar --keystore=ks.keystore $patcher_args"
if [ "$riplib" = true ]; then cmd+=" --rip-lib x86_64 --rip-lib x86 --rip-lib armeabi-v7a"; fi
if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${TEMP_DIR}/aapt2"; fi
pr "$cmd"
if [ "${DRYRUN:-}" = true ]; then
Expand Down Expand Up @@ -425,6 +450,14 @@ build_rv() {
# fi
# fi

if [ "${args[riplib]}" = true ]; then
p_patcher_args+=("--rip-lib x86_64 --rip-lib x86 --rip-lib armeabi-v7a")
if [ "$arch" = "arm64-v8a" ]; then
p_patcher_args+=("--rip-lib armeabi-v7a")
elif [ "$arch" = "arm-v7a" ]; then
p_patcher_args+=("--rip-lib arm64-v8a")
fi
fi
if [ "$mode_arg" = module ]; then
build_mode_arr=(module)
elif [ "$mode_arg" = apk ]; then
Expand All @@ -448,14 +481,11 @@ build_rv() {
else
patched_apk="${TEMP_DIR}/${app_name_l}-${rv_brand_f}-${version_f}-${arch_f}.apk"
fi
if [ "$build_mode" = module ]; then
if [ "${args[riplib]}" = true ]; then patcher_args+=("--unsigned"); fi
if [ "${args[riplib]}" = true ] && { [ $is_bundle = false ] || [ "${args[include_stock]}" = false ]; }; then
patcher_args+=("--rip-lib arm64-v8a --rip-lib armeabi-v7a")
fi
if [ "$build_mode" = module ] && [ "${args[riplib]}" = true ]; then
patcher_args+=("--unsigned --rip-lib arm64-v8a --rip-lib armeabi-v7a")
fi
if [ ! -f "$patched_apk" ] || [ "$REBUILD" = true ]; then
if ! patch_apk "$stock_apk" "$patched_apk" "${patcher_args[*]}" "${args[cli]}" "${args[ptjar]}" "${args[riplib]}"; then
if ! patch_apk "$stock_apk" "$patched_apk" "${patcher_args[*]}" "${args[cli]}" "${args[ptjar]}"; then
epr "Building '${table}' failed!"
return 0
fi
Expand Down

0 comments on commit f6e8cc6

Please sign in to comment.