这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 6950e8b

Browse files
Changed: Move to semantic versioning for app version and add commit hash and github to APK file names
The `versionName` will now follow semantic version `2.0.0` spec in the format `major.minor.patch(-prerelease)(+buildmetadata)`. This will make versioning the prerelease and github debug builds versions easier and follow a spec. The @termux devs should make sure that when bumping `versionName` in `build.gradle` file and when creating a tag for new releases on github that they include the patch number as well, like `v0.1.0` instead of just `v0.1`. The `build.gradle` file and `attach_debug_apks_to_release` workflow will now validate the version as well and the build/attachment will fail if `versionName` does not follow the spec. https://semver.org/spec/v2.0.0.html APKs released on github for debug build workflows and releases are now referred as `Github` releases as per termux/termux-app@7b10a35f and termux/termux-app@94e01d68, so APK filenames have been modified to include `github` in the filename. The APKs are still debuggable, so that tag remains too. For github workflows the apk filename format will be `termux-float_<current_version>+<last_commit_hash>-github-debug_<arch>.apk`, like `termux-float_v0.1.0+xxxxxxxx-github-debug_arm64-v8a.apk` and for github releases it will be `termux-float_<release_version>+github-debug_<arch>.apk`, like `termux-float_v0.1+github-debug_arm64-v8a.apk`. The `last_commit_hash` will be the first `8` characters of the commit hash. The `<last_commit_hash>-github-debug` will act as `buildmetadata` and will not affect versioning precedence. For github workflows triggered by `push` and `pull_request` triggers, `<current_version>+<last_commit_hash>` will be used as new `versionName`, like `v0.1.0+xxxxxxxx`. This will make tracking which build a user is using easier and help in resolving issues as well. The `app/build.gradle` now also supports following `TERMUX_FLOAT_` scoped environmental variables and `RELEASE_TAG` variable will not be used anymore since it may conflict with possibly other variables used by users. - `TERMUX_FLOAT_APP_VERSION_NAME` will be used as `versionName` if its set. - `TERMUX_FLOAT_APK_VERSION_TAG` will be used as `termux-float_<TERMUX_FLOAT_APK_VERSION_TAG>.apk` if its set.
1 parent 56af0d4 commit 6950e8b

File tree

4 files changed

+143
-51
lines changed

4 files changed

+143
-51
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Attach Debug APK To Release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
attach-apks:
10+
runs-on: ubuntu-latest
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
steps:
14+
- name: Clone repository
15+
uses: actions/checkout@v2
16+
with:
17+
ref: ${{ env.GITHUB_REF }}
18+
19+
- name: Build and attach APK to release
20+
shell: bash {0}
21+
run: |
22+
exit_on_error() {
23+
echo "$1"
24+
echo "Deleting '$RELEASE_VERSION_NAME' release and '$GITHUB_REF' tag"
25+
hub release delete "$RELEASE_VERSION_NAME"
26+
git push --delete origin "$GITHUB_REF"
27+
exit 1
28+
}
29+
30+
echo "Setting vars"
31+
RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}"
32+
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
33+
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."
34+
fi
35+
36+
APK_DIR_PATH="./app/build/outputs/apk/debug"
37+
APK_VERSION_TAG="$RELEASE_VERSION_NAME+github-debug"
38+
APK_BASENAME_PREFIX="termux-float_$APK_VERSION_TAG"
39+
40+
echo "Building APK for '$RELEASE_VERSION_NAME' release"
41+
export TERMUX_FLOAT_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
42+
if ! ./gradlew assembleDebug; then
43+
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release."
44+
fi
45+
46+
echo "Validating APK"
47+
if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then
48+
files_found="$(ls "$APK_DIR_PATH")"
49+
exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found"
50+
fi
51+
52+
echo "Generating sha25sums file"
53+
if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > sha256sums); then
54+
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
55+
fi
56+
57+
echo "Attaching APK to github release"
58+
if ! hub release edit \
59+
-m "" \
60+
-a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk" \
61+
-a "$APK_DIR_PATH/sha256sums" \
62+
"$RELEASE_VERSION_NAME"; then
63+
exit_on_error "Attach APK to release failed for '$RELEASE_VERSION_NAME' release."
64+
fi

.github/workflows/attach_debug_apks_to_release.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/debug_build.yml

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
11
name: Build
22

3-
on: push
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
build:
713
runs-on: ubuntu-latest
814
steps:
9-
- name: Clone repository
10-
uses: actions/checkout@v2
11-
- name: Build
12-
run: |
13-
./gradlew assembleDebug
14-
- name: Store generated APK file
15-
uses: actions/upload-artifact@v2
16-
with:
17-
name: termux-float
18-
path: |
19-
./app/build/outputs/apk/debug/termux-float-debug.apk
20-
./app/build/outputs/apk/debug/output-metadata.json
15+
- name: Clone repository
16+
uses: actions/checkout@v2
17+
18+
- name: Build APK
19+
shell: bash {0}
20+
run: |
21+
exit_on_error() { echo "$1"; exit 1; }
22+
23+
echo "Setting vars"
24+
# Set RELEASE_VERSION_NAME to "<CURRENT_VERSION_NAME>+<last_commit_hash>"
25+
CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$'
26+
CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")"
27+
RELEASE_VERSION_NAME="v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}" # The "+" is necessary so that versioning precedence is not affected
28+
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
29+
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."
30+
fi
31+
32+
APK_DIR_PATH="./app/build/outputs/apk/debug"
33+
APK_VERSION_TAG="$RELEASE_VERSION_NAME-github-debug" # Note the "-", GITHUB_SHA will already have "+" before it
34+
APK_BASENAME_PREFIX="termux-float_$APK_VERSION_TAG"
35+
36+
# Used by attachment steps later
37+
echo "APK_DIR_PATH=$APK_DIR_PATH" >> $GITHUB_ENV
38+
echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV
39+
echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV
40+
41+
echo "Building APK for '$RELEASE_VERSION_NAME' build"
42+
export TERMUX_FLOAT_APP_VERSION_NAME="${RELEASE_VERSION_NAME/v/}" # Used by app/build.gradle
43+
export TERMUX_FLOAT_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
44+
if ! ./gradlew assembleDebug; then
45+
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' build."
46+
fi
47+
48+
echo "Validating APK"
49+
if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then
50+
files_found="$(ls "$APK_DIR_PATH")"
51+
exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found"
52+
fi
53+
54+
echo "Generating sha25sums file"
55+
if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > sha256sums); then
56+
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
57+
fi
58+
59+
- name: Attach files
60+
uses: actions/upload-artifact@v2
61+
with:
62+
name: ${{ env.APK_BASENAME_PREFIX }}
63+
path: |
64+
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}.apk
65+
${{ env.APK_DIR_PATH }}/sha256sums
66+
${{ env.APK_DIR_PATH }}/output-metadata.json

app/build.gradle

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion project.properties.compileSdkVersion.toInteger()
5+
def appVersionName = System.getenv("TERMUX_FLOAT_APP_VERSION_NAME") ?: ""
6+
def apkVersionTag = System.getenv("TERMUX_FLOAT_APK_VERSION_TAG") ?: ""
7+
58
defaultConfig {
69
applicationId "com.termux.window"
710
minSdkVersion project.properties.minSdkVersion.toInteger()
811
targetSdkVersion project.properties.targetSdkVersion.toInteger()
912
versionCode 14
10-
versionName "0.14"
13+
versionName "0.14.0"
14+
15+
if (appVersionName) versionName = appVersionName
16+
validateVersionName(versionName)
1117

1218
manifestPlaceholders.TERMUX_PACKAGE_NAME = "com.termux"
1319
manifestPlaceholders.TERMUX_APP_NAME = "Termux"
@@ -44,8 +50,9 @@ android {
4450
applicationVariants.all { variant ->
4551
variant.outputs.all { output ->
4652
if (variant.buildType.name == "debug") {
47-
def releaseTag = System.getenv("RELEASE_TAG")
48-
outputFileName = new File("termux-float" + (releaseTag ? "-" + releaseTag : "") + "-debug.apk")
53+
outputFileName = new File("termux-float_" + (apkVersionTag ? apkVersionTag : "debug") + ".apk")
54+
} else if (variant.buildType.name == "release") {
55+
outputFileName = new File("termux-float_" + (apkVersionTag ? apkVersionTag : "release") + ".apk")
4956
}
5057
}
5158
}
@@ -67,7 +74,14 @@ dependencies {
6774
}
6875

6976
task versionName {
70-
doLast {
71-
print android.defaultConfig.versionName
72-
}
77+
doLast {
78+
print android.defaultConfig.versionName
79+
}
80+
}
81+
82+
def validateVersionName(String versionName) {
83+
// https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
84+
// ^(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-]+)*))?$
85+
if (!java.util.regex.Pattern.matches("^(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-]+)*))?\$", versionName))
86+
throw new GradleException("The versionName '" + versionName + "' 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.")
7387
}

0 commit comments

Comments
 (0)