Build Modules #135
This file contains hidden or 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
| name: Build Modules | |
| on: | |
| workflow_call: | |
| inputs: | |
| from_ci: | |
| type: boolean | |
| required: false | |
| default: true | |
| workflow_dispatch: | |
| repository_dispatch: | |
| types: [revanced-patches-release, anddea-patches-release, morphe-patches-release] | |
| jobs: | |
| run: | |
| permissions: write-all | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: "zulu" | |
| java-version: "17" | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| submodules: true | |
| - name: Cache stamp | |
| id: cache_stamp | |
| run: echo "DATE=$(date +%Y-%m-%d)" >> "$GITHUB_OUTPUT" | |
| - name: Restore APK/prebuilt cache | |
| id: apk_cache_restore | |
| uses: actions/cache/restore@v4 | |
| with: | |
| key: ${{ runner.os }}-apk-cache-${{ github.ref_name }}-${{ steps.cache_stamp.outputs.DATE }} | |
| restore-keys: | | |
| ${{ runner.os }}-apk-cache-${{ github.ref_name }}- | |
| ${{ runner.os }}-apk-cache- | |
| path: | | |
| temp/*.apk | |
| temp/*.apkm | |
| temp/apkeditor.jar | |
| temp/*-rv/*.jar | |
| temp/*-rv/*.rvp | |
| temp/*-rv/*.mpp | |
| revanced-magisk/bin/arm64/cmpr | |
| revanced-magisk/bin/arm/cmpr | |
| revanced-magisk/bin/x86/cmpr | |
| revanced-magisk/bin/x64/cmpr | |
| - 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.json | |
| fi | |
| fi | |
| - name: Get next version code | |
| id: next_ver_code | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG=$(gh release list -L 1 2>/dev/null | awk -F '\t' '{print $3}' || echo "") | |
| if [ -z "$TAG" ] || ! [[ "$TAG" =~ ^[0-9]+$ ]]; then TAG=0; fi | |
| echo "NEXT_VER_CODE=$((TAG + 1))" >> $GITHUB_OUTPUT | |
| - name: Build modules/APKs | |
| run: if [ -f "config.json" ]; then ./build.sh config.json; else ./build.sh config.toml; fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_REPOSITORY: $GITHUB_REPOSITORY | |
| NEXT_VER_CODE: ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} | |
| - name: Save APK/prebuilt cache | |
| if: always() && steps.apk_cache_restore.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| key: ${{ steps.apk_cache_restore.outputs.cache-primary-key }} | |
| path: | | |
| temp/*.apk | |
| temp/*.apkm | |
| temp/apkeditor.jar | |
| temp/*-rv/*.jar | |
| temp/*-rv/*.rvp | |
| temp/*-rv/*.mpp | |
| revanced-magisk/bin/arm64/cmpr | |
| revanced-magisk/bin/arm/cmpr | |
| revanced-magisk/bin/x86/cmpr | |
| revanced-magisk/bin/x64/cmpr | |
| - name: Get output | |
| id: get_output | |
| run: | | |
| DELIM="$(openssl rand -hex 8)" | |
| echo "BUILD_LOG<<${DELIM}" >> "$GITHUB_OUTPUT" | |
| if [ -f "build.md" ]; then | |
| cat build.md >> "$GITHUB_OUTPUT" | |
| cp -f build.md build.tmp | |
| else | |
| echo "No build output available" >> "$GITHUB_OUTPUT" | |
| touch build.tmp | |
| fi | |
| echo "${DELIM}" >> "$GITHUB_OUTPUT" | |
| - name: Upload modules to release | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| body: ${{ steps.get_output.outputs.BUILD_LOG }} | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| file: ./build/* | |
| release_name: ReVanced | |
| tag: ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} | |
| file_glob: true | |
| overwrite: true | |
| - name: Update changelog and Magisk update json | |
| id: update_config | |
| run: | | |
| git checkout -f update || git switch --discard-changes --orphan update | |
| if [ -f "build.tmp" ]; then | |
| cp -f build.tmp build.md | |
| else | |
| echo "No build output available" > build.md | |
| fi | |
| get_update_json() { | |
| echo "{ | |
| \"version\": \"$1\", | |
| \"versionCode\": ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}, | |
| \"zipUrl\": \"$2\", | |
| \"changelog\": \"https://raw.githubusercontent.com/$GITHUB_REPOSITORY/update/build.md\" | |
| }" | |
| } | |
| cd build || { echo "build folder not found"; exit 1; } | |
| for OUTPUT in *magisk*.zip; do | |
| [ "$OUTPUT" = "*magisk*.zip" ] && continue | |
| ZIP_S=$(unzip -p "$OUTPUT" module.prop) | |
| if ! UPDATE_JSON=$(echo "$ZIP_S" | grep updateJson); then continue; fi | |
| UPDATE_JSON="${UPDATE_JSON##*/}" | |
| VER=$(echo "$ZIP_S" | grep version=) | |
| VER="${VER##*=}" | |
| DLURL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}/${OUTPUT}" | |
| get_update_json "$VER" "$DLURL" >"../$UPDATE_JSON" | |
| done | |
| cd .. | |
| if ! find . -name "*-update.json" -type f | grep -q .; then | |
| touch dummy-update.json | |
| fi | |
| - uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| branch: update | |
| skip_checkout: true | |
| file_pattern: build.md *-update.json | |
| commit_message: Bump version ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} | |
| - name: Report to Telegram | |
| env: | |
| TG_TOKEN: ${{ secrets.TG_TOKEN }} | |
| if: env.TG_TOKEN != null | |
| run: | | |
| cd build || { echo "build folder not found"; exit 1; } | |
| TG_CHAT="@rvc_magisk" | |
| NL=$'\n' | |
| APKS="" | |
| MODULES="" | |
| for OUTPUT in *; do | |
| DL_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}/${OUTPUT}" | |
| if [[ $OUTPUT = *.apk ]]; then | |
| APKS+="${NL}📦[${OUTPUT}](${DL_URL})" | |
| elif [[ $OUTPUT = *.zip ]]; then | |
| MODULES+="${NL}📦[${OUTPUT}](${DL_URL})" | |
| fi | |
| done | |
| MODULES=${MODULES#"$NL"} | |
| APKS=${APKS#"$NL"} | |
| if [ -f "../build.md" ]; then | |
| BODY="$(sed 's/^\* \*\*/↪ \*\*/g; s/^\* `/↪ \*\*/g; s/`/\*/g; s/^\* /\↪/g; s/\*\*/\*/g; s/###//g; s/^- /↪ /g; /^==/d;' ../build.md)" | |
| else | |
| BODY="Build completed successfully" | |
| fi | |
| MSG="*New build!* | |
| ${BODY} | |
| *▼ Download Links:* | |
| Modules: | |
| ${MODULES} | |
| APKs: | |
| ${APKS} | |
| " | |
| echo "'$MSG'" | |
| MSG=${MSG:0:9450} | |
| POST="https://api.telegram.org/bot${TG_TOKEN}/sendMessage" | |
| curl -X POST --data-urlencode "parse_mode=Markdown" --data-urlencode "disable_web_page_preview=true" --data-urlencode "text=${MSG}" --data-urlencode "chat_id=${TG_CHAT}" "$POST" |