Skip to content

Commit 57d088c

Browse files
committed
support setting commit version when creating the runtime package. Support setting a pre-release version string to be part of the final runtime version
udpated travis build to pass the correct values to creaet runtime package task
1 parent 3c1a0b1 commit 57d088c

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ before_install:
3333
- export ANDROID_NDK_HOME=`pwd`/android-ndk-$NDK_VERSION
3434
- export PATH=${PATH}:${ANDROID_NDK_HOME}
3535
script:
36-
- "./gradlew createPackage -i -PpackageVersion=$PACKAGE_VERSION -PgitCommitVersion=$TRAVIS_COMMIT --stacktrace"
36+
- "./gradlew createPackage -i -PpreReleaseVersion=$PACKAGE_VERSION -PgitCommitVersion=$TRAVIS_COMMIT --stacktrace"
3737
- echo no | android create avd --force -n Arm21 -t android-21 -b armeabi-v7a -c 12M
3838
- emulator -avd Arm21 -no-skin -no-audio -no-window &
3939
- android-wait-for-emulator

build.gradle

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Usage:
33
* gradlew - Builds the NativeScript Android App Package using an application project template.
4+
gradlew -PgitCommitVersion - sets the commit version of the build
5+
gradlew -PpreReleaseVersion - sets the pre-release version of the build (as per semver spec "-alpha" value results in 1.0.0-alpha)
6+
47
*/
58

69
defaultTasks 'createPackage'
@@ -15,43 +18,30 @@ def distDir = "$rootDir/dist"
1518
def pVersion = "no package version was provided by build.gradle build"
1619
def arVersion = "no commit sha was provided by build.gradle build"
1720

21+
22+
1823
task checkEnvironmentVariables {
1924
if ("$System.env.JAVA_HOME" == "" || "$System.env.JAVA_HOME" == "null") {
2025
throw new GradleException("Set JAVA_HOME to point to the correct Jdk location\n");
2126
}
27+
2228
if ("$System.env.ANDROID_HOME" == "" || "$System.env.ANDROID_HOME" == "null") {
2329
throw new GradleException("Set ANDROID_HOME to point to the correct Android SDK location\n");
2430
}
25-
if ("$System.env.GIT_COMMIT" == "null") {
31+
32+
if ("$System.env.GIT_COMMIT" == "null" && !project.hasProperty("gitCommitVersion")) {
2633
logger.warn("Warning: The GIT_COMMIT is not set. This NativeScript Android Runtime will not be tagged with the git commit it is build from\n");
2734
}
35+
2836
if(project.hasProperty("devmode") == true && !project.hasProperty("metadataGenSrc") && !file("../android-metadata-generator").exists()) {
2937
throw new GradleException("../android-metadata-generator directory not found and no metadataGenSrc option specified. Clone the android-metadata-generator repo first.\n");
3038
}
39+
3140
if(project.hasProperty("metadataGen") && !file("../android-metadata-generator/dist/tns-android-metadata-generator-0.0.1.tgz").exists()) {
3241
throw new GradleException("android-metadata-generator build output not found and no metadataGen option specified. Build android-metadata-generator first.\n");
3342
}
3443
}
3544

36-
// task checkAndroidCommand(type:Exec) {
37-
// if(isWinOs) {
38-
// commandLine "cmd", "/c", "android", "-h"
39-
// }
40-
// else {
41-
// commandLine "android", "-h"
42-
// }
43-
44-
// ignoreExitValue = true
45-
46-
// doLast {
47-
// def successResult = isWinOs ? 0 : 1
48-
49-
// if (execResult.exitValue != successResult) {//1 is ok result for android tool
50-
// throw new GradleException("\n--> 'android' command not found. Set the PATH variable to include the path to Android SDK Tools directory.\n\nError: " + errorOutput + "\nexitValue: " + execResult.exitValue)
51-
// }
52-
// }
53-
// }
54-
5545
task cleanDistDir (type: Delete) << {
5646
delete distDir
5747
}
@@ -79,10 +69,22 @@ task getPackageVersion << {
7969
pVersion = packageJsonMap.version
8070

8171
println "The package version from package.json is '${pVersion}'"
72+
73+
if (project.hasProperty("preReleaseVersion")) {
74+
pVersion += "-" + preReleaseVersion
75+
}
76+
77+
println "The runtime version is '${pVersion}'"
8278
}
8379

8480
task getCommitVersion << {
85-
if("$System.env.GIT_COMMIT" != "null") {
81+
82+
if (project.hasProperty("gitCommitVersion")) {
83+
println "Using commit version property " + gitCommitVersion
84+
arVersion = gitCommitVersion
85+
}
86+
else if ("$System.env.GIT_COMMIT" != "null") {
87+
println "Using commit version environment variable " + $System.env.GIT_COMMIT
8688
String content = "$System.env.GIT_COMMIT"
8789
arVersion = content.trim()
8890
}

0 commit comments

Comments
 (0)