Skip to content

Commit af8b7c1

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 as 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-widget_<current_version>+<last_commit_hash>-github-debug_<arch>.apk`, like `termux-widget_v0.1.0+xxxxxxxx-github-debug_arm64-v8a.apk` and for github releases it will be `termux-widget_<release_version>-github-debug_<arch>.apk`, like `termux-widget_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_WIDGET_` scoped environmental variables and `RELEASE_TAG` variable will not be used anymore since it may conflict with possibly other variables used by users. - `TERMUX_WIDGET_APP_VERSION_NAME` will be used as `versionName` if its set. - `TERMUX_WIDGET_APK_VERSION_TAG` will be used as `termux-widget_<TERMUX_WIDGET_APK_VERSION_TAG>.apk` if its set.
1 parent 8e41be4 commit af8b7c1

File tree

3 files changed

+59
-32
lines changed

3 files changed

+59
-32
lines changed

.github/workflows/attach_debug_apks_to_release.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@ on:
66
- published
77

88
jobs:
9-
build:
9+
attach-apks:
1010
runs-on: ubuntu-latest
1111
env:
1212
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1313
steps:
14-
- name: Set tag
15-
id: vars
16-
run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//}
1714
- name: Clone repository
1815
uses: actions/checkout@v2
1916
with:
2017
ref: ${{ env.GITHUB_REF }}
18+
- name: Set vars
19+
run: |
20+
RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}"
21+
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
22+
echo "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."
23+
exit 1
24+
fi
25+
echo "TERMUX_WIDGET_RELEASE_TAG=$RELEASE_VERSION_NAME" >> $GITHUB_ENV
26+
echo "TERMUX_WIDGET_APK_VERSION_TAG=$RELEASE_VERSION_NAME+github-debug" >> $GITHUB_ENV # Used by app/build.gradle
27+
- name: Echo release
28+
run: echo "Attaching debug APK to '${{ env.TERMUX_WIDGET_RELEASE_TAG }}' release"
2129
- name: Build
22-
env:
23-
RELEASE_TAG: ${{ steps.vars.outputs.tag }}
2430
run: ./gradlew assembleDebug
25-
- name: Attach debug APKs to release
26-
env:
27-
RELEASE_TAG: ${{ steps.vars.outputs.tag }}
31+
- name: Attach APKs to release
2832
run: >-
2933
hub release edit
3034
-m ""
31-
-a ./app/build/outputs/apk/debug/termux-widget-$RELEASE_TAG-debug.apk
32-
$RELEASE_TAG
35+
-a "./app/build/outputs/apk/debug/termux-widget_${{ env.TERMUX_WIDGET_APK_VERSION_TAG }}.apk"
36+
"${{ env.TERMUX_WIDGET_RELEASE_TAG }}"

.github/workflows/debug_build.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
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-widget
18-
path: |
19-
./app/build/outputs/apk/debug/termux-widget-debug.apk
20-
./app/build/outputs/apk/debug/output-metadata.json
9+
- name: Clone repository
10+
uses: actions/checkout@v2
11+
- name: Set vars
12+
run: |
13+
# Set NEW_VERSION_NAME to "<CURRENT_VERSION_NAME>+<last_commit_hash>"
14+
CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$'
15+
CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")"
16+
NEW_VERSION_NAME="$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}"
17+
echo "TERMUX_WIDGET_APP_VERSION_NAME=$NEW_VERSION_NAME" >> $GITHUB_ENV # Used by app/build.gradle
18+
echo "TERMUX_WIDGET_APK_VERSION_TAG=v$NEW_VERSION_NAME-github-debug" >> $GITHUB_ENV # Used by app/build.gradle
19+
- name: Echo version
20+
run: echo "Building APK for '$TERMUX_WIDGET_APP_VERSION_NAME'"
21+
- name: Build
22+
run: ./gradlew assembleDebug
23+
- name: Store generated APK file
24+
uses: actions/upload-artifact@v2
25+
with:
26+
name: termux-widget
27+
path: |
28+
./app/build/outputs/apk/debug/termux-widget_${{ env.TERMUX_WIDGET_APK_VERSION_TAG }}.apk
29+
./app/build/outputs/apk/debug/output-metadata.json

app/build.gradle

Lines changed: 23 additions & 9 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_WIDGET_APP_VERSION_NAME") ?: ""
6+
def apkVersionTag = System.getenv("TERMUX_WIDGET_APK_VERSION_TAG") ?: ""
7+
58
defaultConfig {
69
applicationId "com.termux.widget"
710
minSdkVersion project.properties.minSdkVersion.toInteger()
811
targetSdkVersion project.properties.targetSdkVersion.toInteger()
912
versionCode 12
10-
versionName "0.12"
13+
versionName "0.12.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,19 +50,14 @@ 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-widget" + (releaseTag ? "-" + releaseTag : "") + "-debug.apk")
53+
outputFileName = new File("termux-widget_" + (apkVersionTag ? apkVersionTag : "debug") + ".apk")
54+
} else if (variant.buildType.name == "release") {
55+
outputFileName = new File("termux-widget_" + (apkVersionTag ? apkVersionTag : "release") + ".apk")
4956
}
5057
}
5158
}
5259
}
5360

54-
task versionName {
55-
doLast {
56-
print android.defaultConfig.versionName
57-
}
58-
}
59-
6061
dependencies {
6162
// required for TermuxWidgetControlsProviderService
6263
implementation "org.reactivestreams:reactive-streams:1.0.3"
@@ -68,3 +69,16 @@ dependencies {
6869
// If updates are done, republish there and sync project with gradle files here
6970
//implementation 'com.termux:termux-shared:0.117'
7071
}
72+
73+
task versionName {
74+
doLast {
75+
print android.defaultConfig.versionName
76+
}
77+
}
78+
79+
def validateVersionName(String versionName) {
80+
// https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
81+
// ^(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-]+)*))?$
82+
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))
83+
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.")
84+
}

0 commit comments

Comments
 (0)