From 08e7e47427ddc6e5837f0489ebd968b35f4454f1 Mon Sep 17 00:00:00 2001 From: PiX <69745008+pixincreate@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:50:04 +0530 Subject: [PATCH] ci(gh-actions): introduce auto-updater and builder ci --- .github/workflows/android_build.yml | 75 +++++++++++++++++++++++++++++ .github/workflows/update_fork.yml | 68 ++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 .github/workflows/android_build.yml create mode 100644 .github/workflows/update_fork.yml diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml new file mode 100644 index 000000000..762b035fb --- /dev/null +++ b/.github/workflows/android_build.yml @@ -0,0 +1,75 @@ +name: Android CI + +on: + workflow_dispatch: + workflow_call: + +permissions: + contents: write + +env: + GRADLE_OPTS: -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx4g -XX:MaxMetaspaceSize=2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout Forked Repo + uses: actions/checkout@v4 + with: + repository: pixincreate/Shizuku + ref: master + fetch-depth: 0 + submodules: true + + - name: Setup Keystore File + run: | + touch signing.properties + echo KEYSTORE_PASSWORD='${{ secrets.KEYSTORE_PASSWORD }}' >> signing.properties + echo KEYSTORE_ALIAS='${{ secrets.KEYSTORE_ALIAS_NAME }}' >> signing.properties + echo KEYSTORE_ALIAS_PASSWORD='${{ secrets.KEYSTORE_PASSWORD_ALIAS }}' >> signing.properties + echo KEYSTORE_FILE=../key.jks >> signing.properties + + echo '${{ secrets.KEYSTORE_FILE }}' > keystore.jks.asc + gpg -d --passphrase '${{ secrets.KEYSTORE_PASSWORD_GPG }}' --batch keystore.jks.asc > key.jks + + - name: set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + cache: "gradle" + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + id: buildWithGradle + run: | + echo 'org.gradle.caching=true' >> gradle.properties + echo 'org.gradle.parallel=true' >> gradle.properties + echo 'org.gradle.vfs.watch=true' >> gradle.properties + + ./gradlew :manager:assembleRelease :manager:assembleDebug + releaseName=`ls manager/build/outputs/apk/release/shizuku*-v*-release.apk | awk -F '(/|.apk)' '{print $6}'` && echo "releaseName=$releaseName" >> $GITHUB_OUTPUT + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.buildWithGradle.outputs.releaseName }} + path: "manager/build/outputs/apk/release/*.apk" + retention-days: 2 + + - name: Release APK + uses: "dciborow/action-github-releases@v1.0.1" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: ${{ steps.buildWithGradle.outputs.releaseName }} + prerelease: false + title: ${{ steps.buildWithGradle.outputs.releaseName }} + files: | + manager/build/outputs/apk/release/*.apk \ No newline at end of file diff --git a/.github/workflows/update_fork.yml b/.github/workflows/update_fork.yml new file mode 100644 index 000000000..182292914 --- /dev/null +++ b/.github/workflows/update_fork.yml @@ -0,0 +1,68 @@ +name: Update Fork + +on: + workflow_dispatch: + schedule: + - cron: "30 5 * * MON" # runs every monday at 05:30 UTC + +permissions: + contents: write + actions: write + +jobs: + update_fork: + runs-on: ubuntu-latest + + steps: + - name: Checkout Forked Repo + uses: actions/checkout@v4 + with: + repository: pixincreate/Shizuku + ref: master + fetch-depth: "0" + submodules: true + + - name: Setup Git + run: git config --global user.email ${{ secrets.EMAIL }} && git config --global user.name PiX + + - name: Fetch from Upstream + run: | + git remote add upstream https://github.com/RikkaApps/Shizuku.git + git fetch upstream master + upstream_commit="$(git rev-parse upstream/master)" + echo "Upstream latest commit: ${upstream_commit}" + for forked_commit in $(git rev-list -n 20 master); do + if [ $upstream_commit != $forked_commit ]; then + has_new_commits=true + continue + else + has_new_commits=false + break + fi + done + if [ $has_new_commits == "true" ]; then + git checkout master + if ! git rebase upstream/master; then + git diff + echo "ERROR: Merge conflict encountered during rebase!" + git rebase --abort + exit 1 + fi + git submodule update --init --recursive # Update the submodule + git push -f origin master + echo "Rebase successful!" + else + echo "ERROR: No commits to be synced!" + exit 1 + fi + + build_app: + needs: update_fork + uses: ./.github/workflows/android_build.yml + secrets: inherit + +# References: +# https://stackoverflow.com/questions/75192546/is-it-possible-to-call-another-workflow-file-from-another-workflow-files-condit/75225285#75225285 +# https://stackoverflow.com/questions/75191443/how-to-check-if-upstreams-head-latest-commit-is-present-in-forked-repo +# https://stackoverflow.com/questions/75191328/why-does-git-rebase-upstream-main-behaves-differently-when-used-github-actions +# https://stackoverflow.com/questions/62750603/github-actions-trigger-another-action-after-one-action-is-completed \ No newline at end of file