Skip to content

Commit

Permalink
Added: Add support for TERMUX_PACKAGE_MANAGER to build APKs with di…
Browse files Browse the repository at this point in the history
…fferent 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.
  • Loading branch information
agnostic-apollo committed Apr 26, 2022
1 parent 4b3b1a5 commit 105a19a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/attach_debug_apks_to_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
22 changes: 15 additions & 7 deletions .github/workflows/debug_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -29,7 +36,7 @@ jobs:
# Set RELEASE_VERSION_NAME to "<CURRENT_VERSION_NAME>+<last_commit_hash>"
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
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
26 changes: 18 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,6 +38,7 @@ android {
versionCode 118
versionName "0.118.0"

versionName += "+" + project.ext.packageManager
if (appVersionName) versionName = appVersionName
validateVersionName(versionName)

Expand Down Expand Up @@ -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")
}
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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 + "\"")
}
}
}

Expand Down

0 comments on commit 105a19a

Please sign in to comment.