diff --git a/.github/workflows/build-manager-manual.yml b/.github/workflows/build-manager-manual.yml new file mode 100644 index 00000000..f4d9ce58 --- /dev/null +++ b/.github/workflows/build-manager-manual.yml @@ -0,0 +1,275 @@ +name: Build Manager Manual + +on: + push: + branches: [ "main" ] + paths: + - '.github/workflows/build-manager-manual.yml' + - 'manager/**' + - 'kernel/**' + - 'userspace/ksud/**' + - 'userspace/susfs/**' + - 'userspace/kpmmgr/**' + pull_request: + branches: [ "main" ] + paths: + - 'manager/**' + workflow_call: + workflow_dispatch: + inputs: + build_lkm: + required: true + type: choice + default: "auto" + options: + - "true" + - "false" + - "auto" + description: "Whether to build lkm" + upload_lkm: + required: true + type: boolean + default: true + description: "Whether to upload lkm" +jobs: + check-build-lkm: + runs-on: self-hosted + outputs: + build_lkm: ${{ steps.check-build.outputs.build_lkm }} + upload_lkm: ${{ steps.check-build.outputs.upload_lkm }} + steps: + - name: check build + id: check-build + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.build_lkm }}" != "auto" ]; then + kernel_changed="${{ inputs.build_lkm }}" + else + kernel_changed=true + mkdir tmp + cd tmp + git config --global init.defaultBranch bot + git config --global user.name 'Bot' + git config --global user.email 'bot@github.shirkneko.io' + git init . + git remote add origin https://github.com/${{ github.repository }} + CURRENT_COMMIT="${{ github.event.head_commit.id }}" + git fetch origin $CURRENT_COMMIT --depth=1 + git fetch origin lkm --depth=1 + LKM_COMMIT="$(git log --format=%B -n 1 origin/lkm | head -n 1)" + LKM_COMMIT="${LKM_COMMIT#Upload LKM from }" + LKM_COMMIT=$(echo "$LKM_COMMIT" | tr -d '[:space:]') + echo "LKM_COMMIT=$LKM_COMMIT" + git fetch origin "$LKM_COMMIT" --depth=1 + git diff --quiet "$LKM_COMMIT" "$CURRENT_COMMIT" -- kernel :!kernel/setup.sh .github/workflows/build-lkm-local.yml .github/workflows/build-kernel-*.yml && kernel_changed=false + cd .. + rm -rf tmp + fi + if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == 'refs/heads/main' ]; then + need_upload=true + elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + need_upload="${{ inputs.upload_lkm }}" + else + need_upload=false + fi + echo "kernel changed: $kernel_changed" + echo "need upload: $need_upload" + echo "build_lkm=$kernel_changed" >> "$GITHUB_OUTPUT" + echo "upload_lkm=$need_upload" >> "$GITHUB_OUTPUT" + + build-lkm: + needs: check-build-lkm + uses: ./.github/workflows/build-lkm.yml + if: ${{ needs.check-build-lkm.outputs.build_lkm == 'true' }} + with: + upload: ${{ needs.check-build-lkm.outputs.upload_lkm == 'true' }} + secrets: inherit + build-susfs: + if: ${{ always() }} + needs: [ check-build-lkm, build-lkm ] + strategy: + matrix: + include: + - target: aarch64-linux-android + os: ubuntu-latest + uses: ./.github/workflows/susfs.yml + with: + target: ${{ matrix.target }} + os: ${{ matrix.os }} + + build-kpmmgr: + if: ${{ always() }} + needs: [ check-build-lkm, build-lkm ] + strategy: + matrix: + include: + - target: aarch64-linux-android + os: ubuntu-latest + uses: ./.github/workflows/kpmmgr.yml + with: + target: ${{ matrix.target }} + os: ${{ matrix.os }} + + build-ksud: + if: ${{ always() }} + needs: [ check-build-lkm, build-lkm ] + strategy: + matrix: + include: + - target: aarch64-linux-android + os: ubuntu-latest + - target: x86_64-linux-android + os: ubuntu-latest + - target: armv7-linux-androideabi + os: ubuntu-latest + uses: ./.github/workflows/ksud.yml + with: + target: ${{ matrix.target }} + os: ${{ matrix.os }} + pack_lkm: true + pull_lkm: ${{ needs.check-build-lkm.outputs.build_lkm != 'true' }} + + build-manager: + if: ${{ always() }} + needs: build-ksud + runs-on: self-hosted + defaults: + run: + working-directory: ./manager + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup need_upload + id: need_upload + run: | + if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then + echo "UPLOAD=true" >> $GITHUB_OUTPUT + else + echo "UPLOAD=false" >> $GITHUB_OUTPUT + fi + + - name: Write key + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref == 'refs/heads/susfs' || github.ref_type == 'tag' }} + run: | + if [ ! -z "${{ secrets.KEYSTORE }}" ]; then + { + echo KEYSTORE_PASSWORD='${{ secrets.KEYSTORE_PASSWORD }}' + echo KEY_ALIAS='${{ secrets.KEY_ALIAS }}' + echo KEY_PASSWORD='${{ secrets.KEY_PASSWORD }}' + echo KEYSTORE_FILE='key.jks' + } >> gradle.properties + echo "${{ secrets.KEYSTORE }}" | base64 -d > key.jks + fi + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Download arm64 susfs + uses: actions/download-artifact@v4 + with: + name: susfs-aarch64-linux-android + path: . + + - name: Download arm64 kpmmgr + uses: actions/download-artifact@v4 + with: + name: kpmmgr-aarch64-linux-android + path: . + + - name: Download arm64 ksud + uses: actions/download-artifact@v4 + with: + name: ksud-aarch64-linux-android + path: . + + - name: Download x86_64 ksud + uses: actions/download-artifact@v4 + with: + name: ksud-x86_64-linux-android + path: . + + - name: Download arm ksud + uses: actions/download-artifact@v4 + with: + name: ksud-armv7-linux-androideabi + path: . + + - name: Copy ksud to app jniLibs + run: | + mkdir -p app/src/main/jniLibs/arm64-v8a + mkdir -p app/src/main/jniLibs/x86_64 + mkdir -p app/src/main/jniLibs/armeabi-v7a + cp -f ../aarch64-linux-android/release/zakozako ../manager/app/src/main/jniLibs/arm64-v8a/libzakozako.so + cp -f ../x86_64-linux-android/release/zakozako ../manager/app/src/main/jniLibs/x86_64/libzakozako.so + cp -f ../armv7-linux-androideabi/release/zakozako ../manager/app/src/main/jniLibs/armeabi-v7a/libzakozako.so + + - name: Copy kpmmgr to app jniLibs + run: | + mkdir -p app/src/main/jniLibs/arm64-v8a + cp -f ../arm64-v8a/kpmmgr ../manager/app/src/main/jniLibs/arm64-v8a/libkpmmgr.so + + - name: Copy susfs to app jniLibs + run: | + mkdir -p app/src/main/jniLibs/arm64-v8a + cp -f ../arm64-v8a/zakozakozako ../manager/app/src/main/jniLibs/arm64-v8a/libzakozakozako.so + + - name: Build with Gradle + run: | + { + echo 'org.gradle.parallel=true' + echo 'org.gradle.vfs.watch=true' + echo 'org.gradle.jvmargs=-Xmx2048m' + echo 'android.native.buildOutput=verbose' + } >> gradle.properties + sed -i 's/org.gradle.configuration-cache=true//g' gradle.properties + ./gradlew clean assembleRelease + - name: Upload build artifact + uses: actions/upload-artifact@v4 + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} + with: + name: manager + path: manager/app/build/outputs/apk/release/*.apk + + - name: Upload mappings + uses: actions/upload-artifact@v4 + if: ${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} + with: + name: "mappings" + path: "manager/app/build/outputs/mapping/release/" + + - name: Bot session cache + if: github.event_name != 'pull_request' && steps.need_upload.outputs.UPLOAD == 'true' + id: bot_session_cache + uses: actions/cache@v4 + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Upload to telegram + if: github.event_name != 'pull_request' && steps.need_upload.outputs.UPLOAD == 'true' + env: + CHAT_ID: ${{ vars.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ vars.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + TITLE: Manager + run: | + if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then + export VERSION=$(git rev-list --count HEAD) + APK=$(find ./app/build/outputs/apk/release -name "*.apk") + python3 $GITHUB_WORKSPACE/scripts/ksubot.py $APK + fi \ No newline at end of file