mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-05 18:25:31 +08:00
The `TermuxBootstrap` class has been added that defines the `PackageManager` and `PackageVariant` classes for the supported package manager configurations for the app. The variant is defined by the `project.ext.packageVariant` value in the `app/build.gradle` and its value is used by the `build.gradle` to pack its respective bootstrap zips in the app APK at build time and the value is used to set `TermuxBootstrap.TERMUX_APP_PACKAGE_MANAGER` and `TermuxBootstrap.TERMUX_APP_PACKAGE_VARIANT` static values that are used at runtime by the app to run variant specific code. The manager is automatically extracted from the variant as the substring before first dash `-`. The default variant is `apt-android-7` and it can either be replaced in `app/build.gradle` manually or the `TERMUX_PACKAGE_VARIANT` env variable can be exported in which the build command is run. The `TERMUX_APP_PACKAGE_MANAGER` and `TERMUX_APP_PACKAGE_VARIANT` environmental variables will be exported by the app and they will also be added in Termux app info in about page and reports, allowing users and devs to know which variant is currently installed. Bootstrap of a different variant must not be manually installed by the user after app installation by replacing `$PREFIX` since app code is dependant on the variant used to build the APK. Currently, `apt-android-7` and `apt-android-5` variants 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.
127 lines
5.3 KiB
YAML
127 lines
5.3 KiB
YAML
name: Build
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
package_variant: [ apt-android-7, apt-android-5 ]
|
|
|
|
steps:
|
|
- name: Clone repository
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Build APKs
|
|
shell: bash {0}
|
|
env:
|
|
PACKAGE_VARIANT: ${{ matrix.package_variant }}
|
|
run: |
|
|
exit_on_error() { echo "$1"; exit 1; }
|
|
|
|
echo "Setting vars"
|
|
|
|
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
|
|
GITHUB_SHA="${{ github.event.pull_request.head.sha }}" # Do not use last merge commit set in GITHUB_SHA
|
|
fi
|
|
|
|
# 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
|
|
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
|
|
|
|
APK_DIR_PATH="./app/build/outputs/apk/debug"
|
|
APK_VERSION_TAG="$RELEASE_VERSION_NAME-${{ env.PACKAGE_VARIANT }}-github-debug" # Note the "-", GITHUB_SHA will already have "+" before it
|
|
APK_BASENAME_PREFIX="termux-app_$APK_VERSION_TAG"
|
|
|
|
# Used by attachment steps later
|
|
echo "APK_DIR_PATH=$APK_DIR_PATH" >> $GITHUB_ENV
|
|
echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV
|
|
echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV
|
|
|
|
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_VARIANT="${{ env.PACKAGE_VARIANT }}" # Used by app/build.gradle
|
|
if ! ./gradlew assembleDebug; then
|
|
exit_on_error "Build failed for '$APK_VERSION_TAG' build."
|
|
fi
|
|
|
|
echo "Validating APKs"
|
|
for abi in universal arm64-v8a armeabi-v7a x86_64 x86; do
|
|
if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}_$abi.apk"; then
|
|
files_found="$(ls "$APK_DIR_PATH")"
|
|
exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}_$abi.apk'. Files found: "$'\n'"$files_found"
|
|
fi
|
|
done
|
|
|
|
echo "Generating sha25sums file"
|
|
if ! (cd "$APK_DIR_PATH"; sha256sum \
|
|
"${APK_BASENAME_PREFIX}_universal.apk" \
|
|
"${APK_BASENAME_PREFIX}_arm64-v8a.apk" \
|
|
"${APK_BASENAME_PREFIX}_armeabi-v7a.apk" \
|
|
"${APK_BASENAME_PREFIX}_x86_64.apk" \
|
|
"${APK_BASENAME_PREFIX}_x86.apk" \
|
|
> "${APK_BASENAME_PREFIX}_sha256sums"); then
|
|
exit_on_error "Generate sha25sums failed for '$APK_VERSION_TAG' release."
|
|
fi
|
|
|
|
- name: Attach universal APK file
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: ${{ env.APK_BASENAME_PREFIX }}_universal
|
|
path: |
|
|
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_universal.apk
|
|
${{ env.APK_DIR_PATH }}/output-metadata.json
|
|
|
|
- name: Attach arm64-v8a APK file
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: ${{ env.APK_BASENAME_PREFIX }}_arm64-v8a
|
|
path: |
|
|
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_arm64-v8a.apk
|
|
${{ env.APK_DIR_PATH }}/output-metadata.json
|
|
|
|
- name: Attach armeabi-v7a APK file
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: ${{ env.APK_BASENAME_PREFIX }}_armeabi-v7a
|
|
path: |
|
|
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_armeabi-v7a.apk
|
|
${{ env.APK_DIR_PATH }}/output-metadata.json
|
|
|
|
- name: Attach x86_64 APK file
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: ${{ env.APK_BASENAME_PREFIX }}_x86_64
|
|
path: |
|
|
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_x86_64.apk
|
|
${{ env.APK_DIR_PATH }}/output-metadata.json
|
|
|
|
- name: Attach x86 APK file
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: ${{ env.APK_BASENAME_PREFIX }}_x86
|
|
path: |
|
|
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_x86.apk
|
|
${{ env.APK_DIR_PATH }}/output-metadata.json
|
|
|
|
- name: Attach sha256sums file
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: ${{ env.APK_BASENAME_PREFIX }}_sha256sums
|
|
path: |
|
|
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}_sha256sums
|
|
${{ env.APK_DIR_PATH }}/output-metadata.json
|