Skip to content

Commit 1f34cfd

Browse files
Use version text file (#234)
1 parent 50daaa5 commit 1f34cfd

File tree

6 files changed

+76
-24
lines changed

6 files changed

+76
-24
lines changed

AndroidSDK/res/values/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
<resources>
33

44
<string name="app_name">Android SDK</string>
5-
<string name="sdk_version">4.1.1</string>
65

7-
</resources>
6+
</resources>

AndroidSDKCore/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ android {
1313

1414
defaultConfig {
1515
consumerProguardFiles CONSUMER_PROGUARD_FILES
16+
17+
def packageIdentifier = System.getenv('LEANPLUM_PACKAGE_IDENTIFIER') ?: 's'
18+
buildConfigField 'String', 'LEANPLUM_PACKAGE_IDENTIFIER', '\"' + packageIdentifier + '\"'
19+
20+
def sdkVersion = file('sdk-version.txt').text
21+
buildConfigField 'String', 'SDK_VERSION', '\"' + sdkVersion + '\"'
22+
23+
def buildNumber = System.getenv('BUILD_NUMBER') ?: '0'
24+
buildConfigField 'String', 'BUILD_NUMBER', '\"' + buildNumber + '\"'
1625
}
1726
buildTypes {
1827
release {
1928
proguardFiles PROGUARD_FILES
2029
}
21-
buildTypes.each {
22-
def packageIdentifier = '\"' + (System.getenv("LEANPLUM_PACKAGE_IDENTIFIER") ?: "s") +
23-
'\"'
24-
it.buildConfigField 'String', 'LEANPLUM_PACKAGE_IDENTIFIER', packageIdentifier
25-
}
2630
}
2731
}
2832

AndroidSDKCore/sdk-version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.1.1

AndroidSDKCore/src/main/java/com/leanplum/internal/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Constants {
3636
public static int SOCKET_PORT = 80;
3737
public static int NETWORK_TIMEOUT_SECONDS = 10;
3838
public static int NETWORK_TIMEOUT_SECONDS_FOR_DOWNLOADS = 10;
39-
public static String LEANPLUM_VERSION = "4.1.1";
39+
public static String LEANPLUM_VERSION = BuildConfig.SDK_VERSION + '.' + BuildConfig.BUILD_NUMBER;
4040
public static String CLIENT = "android";
4141

4242
static final String LEANPLUM_PACKAGE_IDENTIFIER = BuildConfig.LEANPLUM_PACKAGE_IDENTIFIER;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2018, Leanplum, Inc. All rights reserved.
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package com.leanplum.internal;
23+
24+
import com.leanplum.__setup.AbstractTest;
25+
import org.junit.Test;
26+
27+
import static org.junit.Assert.assertEquals;
28+
29+
/**
30+
* Tests settings that are built from gradle.
31+
*/
32+
public class BuildConfigTest extends AbstractTest {
33+
/**
34+
* Test that a valid version is checked in.
35+
*/
36+
@Test
37+
public void testVersion() {
38+
String[] parts = Constants.LEANPLUM_VERSION.split("\\.");
39+
40+
assertEquals(4, parts.length);
41+
// Ensure we can parse and do not go down in major version.
42+
int major = Integer.parseInt(parts[0]);
43+
assert(major >= 4);
44+
45+
// Ensure minor and patch versions are parseable.
46+
int minor = Integer.parseInt(parts[1]);
47+
assert(minor >= 0);
48+
int patch = Integer.parseInt(parts[2]);
49+
assert(patch >= 0);
50+
51+
// Ensure build number propagates.
52+
int build = Integer.parseInt(parts[3]);
53+
assert(build >= 0);
54+
}
55+
}

Tools/create-release.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
#!/usr/bin/env python2.7
22

33
import semver
4-
import xml.etree.ElementTree as ET
54
import sys
65

7-
ANDROID_STRINGS_XML = "AndroidSDK/res/values/strings.xml"
6+
SDK_VERSION_FILE = "AndroidSDKCore/sdk-version.txt"
87

9-
def get_current_version(root):
10-
for element in root.iter("string"):
11-
if element.attrib.get("name") == "sdk_version":
12-
return element.text
8+
def get_current_version():
9+
with open(SDK_VERSION_FILE, 'r') as f:
10+
return f.read()
1311

14-
def update_version(root, xml, version):
15-
for element in root.iter("string"):
16-
if element.attrib.get("name") == "sdk_version":
17-
element.text = str(version)
18-
xml.write(ANDROID_STRINGS_XML, encoding='utf-8', xml_declaration=True)
12+
def update_version(version):
13+
with open(SDK_VERSION_FILE, 'w') as f:
14+
f.write(version)
1915

20-
"""Type: Major/Minor/Patch"""
2116

2217
"""
2318
1. Read in values.xml
@@ -26,10 +21,8 @@ def update_version(root, xml, version):
2621
"""
2722
def main():
2823
release_type = sys.argv[1]
29-
xml = ET.parse(ANDROID_STRINGS_XML)
30-
root = xml.getroot()
3124

32-
current_version = get_current_version(root)
25+
current_version = get_current_version()
3326

3427
if release_type == "patch":
3528
release_version = semver.bump_patch(current_version)
@@ -40,7 +33,7 @@ def main():
4033
else:
4134
raise Exception("Please pick one patch/minor/major")
4235

43-
update_version(root, xml, release_version)
36+
update_version(release_version)
4437
sys.stdout.write(release_version)
4538

4639
if __name__ == "__main__":

0 commit comments

Comments
 (0)