|
| 1 | +name: Build Modules |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + from_ci: |
| 6 | + type: boolean |
| 7 | + required: false |
| 8 | + default: true |
| 9 | + |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + run: |
| 14 | + permissions: write-all |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/setup-java@v4 |
| 18 | + with: |
| 19 | + distribution: "zulu" |
| 20 | + java-version: "17" |
| 21 | + |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + submodules: true |
| 27 | + |
| 28 | + - name: Set execute permissions for required scripts |
| 29 | + run: | |
| 30 | + chmod +x ./build.sh |
| 31 | + chmod +x bin/toml/tq-x86_64 |
| 32 | +
|
| 33 | + - name: Update config |
| 34 | + if: ${{ inputs.from_ci }} |
| 35 | + run: | |
| 36 | + if git checkout origin/update build.md; then |
| 37 | + UPDATE_CFG=$(./build.sh config.toml --config-update) |
| 38 | + if [ "$UPDATE_CFG" ]; then |
| 39 | + echo "$UPDATE_CFG" > config.json |
| 40 | + fi |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Get next version code |
| 44 | + id: next_ver_code |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + run: | |
| 48 | + TAG=$(gh release list -L 1 | awk -F '\t' '{print $3}') |
| 49 | + if [ -z "$TAG" ]; then TAG=0; fi |
| 50 | + echo "NEXT_VER_CODE=$((TAG + 1))" >> $GITHUB_OUTPUT |
| 51 | +
|
| 52 | + - name: Build modules/APKs |
| 53 | + run: if [ -f "config.json" ]; then ./build.sh config.json; else ./build.sh config.toml; fi |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + GITHUB_REPOSITORY: $GITHUB_REPOSITORY |
| 57 | + NEXT_VER_CODE: ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} |
| 58 | + |
| 59 | + - name: Get output |
| 60 | + id: get_output |
| 61 | + run: | |
| 62 | + DELIM="$(openssl rand -hex 8)" |
| 63 | + echo "BUILD_LOG<<${DELIM}" >> "$GITHUB_OUTPUT" |
| 64 | + cat build.md >> "$GITHUB_OUTPUT" |
| 65 | + echo "${DELIM}" >> "$GITHUB_OUTPUT" |
| 66 | + cp -f build.md build.tmp |
| 67 | +
|
| 68 | + - name: Extract version number |
| 69 | + id: extract_version |
| 70 | + run: | |
| 71 | + # Extract version from the file name |
| 72 | + VERSION=$(ls ./build/youtube-revanced-v*-arm-v7a.apk | head -n 1 | sed -n 's/.*youtube-revanced-v\([0-9.]*\)-arm.*/\1/p') |
| 73 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + - name: Upload modules to release |
| 76 | + uses: svenstaro/upload-release-action@v2 |
| 77 | + with: |
| 78 | + body: ${{ steps.get_output.outputs.BUILD_LOG }} |
| 79 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + file: ./build/* |
| 81 | + release_name: Build ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} | v${{ steps.extract_version.outputs.VERSION }} |
| 82 | + tag: ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} |
| 83 | + file_glob: true |
| 84 | + overwrite: true |
| 85 | + |
| 86 | + - name: Update changelog and Magisk update json |
| 87 | + id: update_config |
| 88 | + run: | |
| 89 | + git checkout -f update || git switch --discard-changes --orphan update |
| 90 | + cp -f build.tmp build.md |
| 91 | + get_update_json() { |
| 92 | + echo "{ |
| 93 | + \"version\": \"$1\", |
| 94 | + \"versionCode\": ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}, |
| 95 | + \"zipUrl\": \"$2\", |
| 96 | + \"changelog\": \"https://raw.githubusercontent.com/$GITHUB_REPOSITORY/update/build.md\" |
| 97 | + }" |
| 98 | + } |
| 99 | +
|
| 100 | + cd build || { echo "build folder not found"; exit 1; } |
| 101 | + for OUTPUT in *magisk*.zip; do |
| 102 | + [ "$OUTPUT" = "*magisk*.zip" ] && continue |
| 103 | + ZIP_S=$(unzip -p "$OUTPUT" module.prop) |
| 104 | + if ! UPDATE_JSON=$(echo "$ZIP_S" | grep updateJson); then continue; fi |
| 105 | + UPDATE_JSON="${UPDATE_JSON##*/}" |
| 106 | + VER=$(echo "$ZIP_S" | grep version=) |
| 107 | + VER="${VER##*=}" |
| 108 | + DLURL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}/${OUTPUT}" |
| 109 | + get_update_json "$VER" "$DLURL" >"../$UPDATE_JSON" |
| 110 | + done |
| 111 | + cd .. |
| 112 | +
|
| 113 | + find . -name "*-update.json" | grep . || : >dummy-update.json |
| 114 | +
|
| 115 | + - uses: stefanzweifel/git-auto-commit-action@v5 |
| 116 | + with: |
| 117 | + branch: update |
| 118 | + skip_checkout: true |
| 119 | + file_pattern: build.md *-update.json |
| 120 | + commit_message: Bump version ${{ steps.next_ver_code.outputs.NEXT_VER_CODE }} |
| 121 | + |
| 122 | + - name: Report to Telegram |
| 123 | + env: |
| 124 | + TG_TOKEN: ${{ secrets.TG_TOKEN }} |
| 125 | + if: env.TG_TOKEN != null |
| 126 | + run: | |
| 127 | + cd build || { echo "build folder not found"; exit 1; } |
| 128 | +
|
| 129 | + TG_CHAT="@rvc_magisk" |
| 130 | + NL=$'\n' |
| 131 | + APKS="" |
| 132 | + MODULES="" |
| 133 | + for OUTPUT in *; do |
| 134 | + DL_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/${{ steps.next_ver_code.outputs.NEXT_VER_CODE }}/${OUTPUT}" |
| 135 | + if [[ $OUTPUT = *.apk ]]; then |
| 136 | + APKS+="${NL}📦[${OUTPUT}](${DL_URL})" |
| 137 | + elif [[ $OUTPUT = *.zip ]]; then |
| 138 | + MODULES+="${NL}📦[${OUTPUT}](${DL_URL})" |
| 139 | + fi |
| 140 | + done |
| 141 | + MODULES=${MODULES#"$NL"} |
| 142 | + APKS=${APKS#"$NL"} |
| 143 | +
|
| 144 | + BODY="$(sed 's/^\* \*\*/↪ \*\*/g; s/^\* `/↪ \*\*/g; s/`/\*/g; s/^\* /\↪/g; s/\*\*/\*/g; s/###//g; s/^- /↪ /g; /^==/d;' ../build.md)" |
| 145 | + MSG="*New build!* |
| 146 | +
|
| 147 | + ${BODY} |
| 148 | +
|
| 149 | + *▼ Download Links:* |
| 150 | + Modules: |
| 151 | + ${MODULES} |
| 152 | +
|
| 153 | + APKs: |
| 154 | + ${APKS} |
| 155 | + " |
| 156 | + echo "'$MSG'" |
| 157 | + MSG=${MSG:0:9450} |
| 158 | + POST="https://api.telegram.org/bot${TG_TOKEN}/sendMessage" |
| 159 | + 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" |
0 commit comments