Last active
November 1, 2018 13:15
-
-
Save mrkpatchaa/ed8af95c71b921cc994ffd7f5ba405dd to your computer and use it in GitHub Desktop.
React Native build number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android/app/build.gradle | |
import groovy.json.JsonSlurper | |
def getNpmVersion() { | |
def inputFile = new File("../package.json") | |
def packageJson = new JsonSlurper().parseText(inputFile.text) | |
return packageJson["version"] | |
} | |
/* calculated from git commits to give sequential integers */ | |
def getGitVersion() { | |
def process = "git rev-list master --first-parent --count".execute() | |
return process.text.toInteger() | |
} | |
...... | |
def userVer = getNpmVersion() | |
def googleVer = getGitVersion() | |
android { | |
... | |
defaultConfig { | |
..... | |
versionCode googleVer | |
versionName userVer | |
ndk { | |
abiFilters "armeabi-v7a", "x86" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// android/build.gradl | |
def getNpmVersionArray() { // major [0], minor [1], patch [2] | |
def (major, minor, patch) = getNpmVersion().tokenize('.') | |
return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[] | |
} | |
subprojects { | |
ext { | |
def npmVersion = getNpmVersionArray() | |
versionMajor = npmVersion[0] | |
versionMinor = npmVersion[1] | |
versionPatch = npmVersion[2] | |
} | |
} | |
// android/app/build.gradle | |
android { | |
... | |
defaultConfig { | |
... | |
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch | |
versionName "${versionMajor}.${versionMinor}.${versionPatch}" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"version": "./version-ios.sh" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash -e | |
PROJECT_DIR="ios/ReactNativeApp" | |
INFOPLIST_FILE="Info.plist" | |
INFOPLIST_DIR="${PROJECT_DIR}/${INFOPLIST_FILE}" | |
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') | |
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_DIR}") | |
BUILD_NUMBER=$(($BUILD_NUMBER + 1)) | |
# Update plist with new values | |
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${PACKAGE_VERSION#*v}" "${INFOPLIST_DIR}" | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${INFOPLIST_DIR}" | |
git add "${INFOPLIST_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment