From 105a19a2c13a4adde19e3cbd9c22ce58ee097a94 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Tue, 26 Apr 2022 06:29:54 +0500 Subject: [PATCH] Added: Add support for `TERMUX_PACKAGE_MANAGER` to build APKs with different package manager configurations The apk version name and file name will contain the package manager tag so that users/devs can know which variant is being used. Currently, `apt-android-7` and `apt-android-5` will be built for by the workflows but they will fail for `apt-android-5` since `build.gradle` support is currently not enabled and will be enabled by a pull request that adds support for Android 5. The workflow needs to try to build the `apt-android-5` variant so that pull request builds are generated. --- .../attach_debug_apks_to_release.yml | 22 +++++++++++----- .github/workflows/debug_build.yml | 22 +++++++++++----- app/build.gradle | 26 +++++++++++++------ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/.github/workflows/attach_debug_apks_to_release.yml b/.github/workflows/attach_debug_apks_to_release.yml index c27cbf23e9..1a0920bbfc 100644 --- a/.github/workflows/attach_debug_apks_to_release.yml +++ b/.github/workflows/attach_debug_apks_to_release.yml @@ -8,8 +8,13 @@ on: jobs: attach-apks: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package_manager: [ apt-android-7, apt-android-5 ] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: - name: Clone repository uses: actions/checkout@v2 @@ -18,6 +23,8 @@ jobs: - name: Build and attach APKs to release shell: bash {0} + env: + PACKAGE_MANAGER: ${{ matrix.package_manager }} run: | exit_on_error() { echo "$1" @@ -34,13 +41,14 @@ jobs: fi APK_DIR_PATH="./app/build/outputs/apk/debug" - APK_VERSION_TAG="$RELEASE_VERSION_NAME+github-debug" + APK_VERSION_TAG="$RELEASE_VERSION_NAME+${{ env.PACKAGE_MANAGER }}-github-debug" APK_BASENAME_PREFIX="termux-app_$APK_VERSION_TAG" - echo "Building APKs for '$RELEASE_VERSION_NAME' release" + echo "Building APKs for 'APK_VERSION_TAG' release" export TERMUX_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle + export TERMUX_PACKAGE_MANAGER="${{ env.PACKAGE_MANAGER }}" # Used by app/build.gradle if ! ./gradlew assembleDebug; then - exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release." + exit_on_error "Build failed for '$APK_VERSION_TAG' release." fi echo "Validating APKs" @@ -58,8 +66,8 @@ jobs: "${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \ "${APK_BASENAME_PREFIX}_x86_64.apk" \ "${APK_BASENAME_PREFIX}_x86.apk" \ - > sha256sums); then - exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release." + > "${APK_BASENAME_PREFIX}_sha256sums"); then + exit_on_error "Generate sha25sums failed for '$APK_VERSION_TAG' release." fi echo "Attaching APKs to github release" @@ -70,7 +78,7 @@ jobs: -a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \ -a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_x86_64.apk" \ -a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_x86.apk" \ - -a "$APK_DIR_PATH/sha256sums" \ + -a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_sha256sums" \ "$RELEASE_VERSION_NAME"; then - exit_on_error "Attach APKs to release failed for '$RELEASE_VERSION_NAME' release." + exit_on_error "Attach APKs to release failed for '$APK_VERSION_TAG' release." fi diff --git a/.github/workflows/debug_build.yml b/.github/workflows/debug_build.yml index 2e81829374..796c4fe2ce 100644 --- a/.github/workflows/debug_build.yml +++ b/.github/workflows/debug_build.yml @@ -11,12 +11,19 @@ on: jobs: build: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package_manager: [ apt-android-7, apt-android-5 ] + steps: - name: Clone repository uses: actions/checkout@v2 - name: Build APKs shell: bash {0} + env: + PACKAGE_MANAGER: ${{ matrix.package_manager }} run: | exit_on_error() { echo "$1"; exit 1; } @@ -29,7 +36,7 @@ jobs: # Set RELEASE_VERSION_NAME to "+" CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$' CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")" - RELEASE_VERSION_NAME="v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}" # The "+" is necessary so that versioning precedence is not affected + RELEASE_VERSION_NAME="v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}-${{ env.PACKAGE_MANAGER }}" # The "+" is necessary so that versioning precedence is not affected if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then exit_on_error "The versionName '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html." fi @@ -43,11 +50,12 @@ jobs: echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV - echo "Building APKs for '$RELEASE_VERSION_NAME' build" + echo "Building APKs for 'APK_VERSION_TAG' build" export TERMUX_APP_VERSION_NAME="${RELEASE_VERSION_NAME/v/}" # Used by app/build.gradle export TERMUX_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle + export TERMUX_PACKAGE_MANAGER="${{ env.PACKAGE_MANAGER }}" # Used by app/build.gradle if ! ./gradlew assembleDebug; then - exit_on_error "Build failed for '$RELEASE_VERSION_NAME' build." + exit_on_error "Build failed for '$APK_VERSION_TAG' build." fi echo "Validating APKs" @@ -65,8 +73,8 @@ jobs: "${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \ "${APK_BASENAME_PREFIX}_x86_64.apk" \ "${APK_BASENAME_PREFIX}_x86.apk" \ - > sha256sums); then - exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release." + > "${APK_BASENAME_PREFIX}_sha256sums"); then + exit_on_error "Generate sha25sums failed for '$APK_VERSION_TAG' release." fi - name: Attach universal APK file @@ -112,7 +120,7 @@ jobs: - name: Attach sha256sums file uses: actions/upload-artifact@v2 with: - name: sha256sums + name: ${{ env.APK_BASENAME_PREFIX }}_sha256sums path: | - ${{ env.APK_DIR_PATH }}/sha256sums + ${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_sha256sums ${{ env.APK_DIR_PATH }}/output-metadata.json diff --git a/app/build.gradle b/app/build.gradle index a4fe8b3153..d6de845d52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,6 +2,10 @@ plugins { id "com.android.application" } +ext { + packageManager = System.getenv("TERMUX_PACKAGE_MANAGER") ?: "apt-android-7" +} + android { compileSdkVersion project.properties.compileSdkVersion.toInteger() ndkVersion = System.getenv("JITPACK_NDK_VERSION") ?: project.properties.ndkVersion @@ -34,6 +38,7 @@ android { versionCode 118 versionName "0.118.0" + versionName += "+" + project.ext.packageManager if (appVersionName) versionName = appVersionName validateVersionName(versionName) @@ -115,10 +120,10 @@ android { variant.outputs.all { output -> if (variant.buildType.name == "debug") { def abi = output.getFilter(com.android.build.OutputFile.ABI) - outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : "debug") + "_" + (abi ? abi : "universal") + ".apk") + outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageManager + "-" + "debug") + "_" + (abi ? abi : "universal") + ".apk") } else if (variant.buildType.name == "release") { def abi = output.getFilter(com.android.build.OutputFile.ABI) - outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : "release") + "_" + (abi ? abi : "universal") + ".apk") + outputFileName = new File("termux-app_" + (apkVersionTag ? apkVersionTag : project.ext.packageManager + "-" + "release") + "_" + (abi ? abi : "universal") + ".apk") } } } @@ -161,7 +166,7 @@ def downloadBootstrap(String arch, String expectedChecksum, String version) { if (checksum == expectedChecksum) { return } else { - logger.quiet("Deleting old local file with wrong hash: " + localUrl) + logger.quiet("Deleting old local file with wrong hash: " + localUrl + ": expected: " + expectedChecksum + ", actual: " + checksum) file.delete() } } @@ -196,11 +201,16 @@ clean { task downloadBootstraps() { doLast { - def version = "2022.04.22-r1" - downloadBootstrap("aarch64", "ec8a6043644594fc24681cffaf9c7b32f5bc68df7491c5df9a060e40e1934c70", version) - downloadBootstrap("arm", "f8ec9505081b81da0ee66413762c52e6cb4a6ebd7be1a2a5ddee8953e0795dc9", version) - downloadBootstrap("i686", "0491f12ed84a5ef3c28bd742311fed9f176e32100a2c6bbdb017df8f48044484", version) - downloadBootstrap("x86_64", "94073a0e136bf5a9c05c1997a55dc261248f4ccb8bffaa9a950a132529cd1529", version) + def packageManager = project.ext.packageManager + if (packageManager == "apt-android-7") { + def version = "2022.04.22-r1" + "+" + packageManager + downloadBootstrap("aarch64", "ec8a6043644594fc24681cffaf9c7b32f5bc68df7491c5df9a060e40e1934c70", version) + downloadBootstrap("arm", "f8ec9505081b81da0ee66413762c52e6cb4a6ebd7be1a2a5ddee8953e0795dc9", version) + downloadBootstrap("i686", "0491f12ed84a5ef3c28bd742311fed9f176e32100a2c6bbdb017df8f48044484", version) + downloadBootstrap("x86_64", "94073a0e136bf5a9c05c1997a55dc261248f4ccb8bffaa9a950a132529cd1529", version) + } else { + throw new GradleException("Unsupported TERMUX_PACKAGE_MANAGER \"" + packageManager + "\"") + } } }