Skip to content

Instantly share code, notes, and snippets.

@satya164
Last active December 21, 2015 10:44
Show Gist options
  • Save satya164/d6b27001160d23581c75 to your computer and use it in GitHub Desktop.
Save satya164/d6b27001160d23581c75 to your computer and use it in GitHub Desktop.
Release script for React Native (WIP)
#! /bin/bash
RELEASE="$1"
JAVA_VERSION="1.8"
RED="\033[0;31m"
GREEN="\033[0;32m"
BLUE="\033[0;34m"
ENDCOLOR="\033[0m"
error() {
echo -e $RED"$@"$ENDCOLOR
exit 1
}
success() {
echo -e $GREEN"$@"$ENDCOLOR
}
info() {
echo -e $BLUE"$@"$ENDCOLOR
}
[[ -z $RELEASE ]] && show_error "No release version specified"
git branch | grep -o ${RELEASE}-stable && show_error "Branch already exists"
java -version 2>&1 | grep ${JAVA_VERSION} || show_error "Java version must be 1.7.x"
git pull || show_error "Couldn't pull from remote repository"
git checkout -b ${RELEASE}-stable || show_error "Couldn't create branch"
show_success "Created release branch: ${RELEASE}-stable"
sed -ie s/^VERSION_NAME=[0-9\.]*-SNAPSHOT/VERSION_NAME=${RELEASE}.0-SNAPSHOT/g "ReactAndroid/gradle.Properties" || show_error "Couldn't update version for Gradle"
./gradlew :ReactAndroid:installArchives || show_error "Couldn't generate artifacts"
artifacts_list=( -javadoc.jar -sources.jar .aar .pom )
artifacts_dir="ls -al ~/.m2/repository/com/facebook/react/react-native/${RELEASE}.0/"
for i in "${artifacts_list[@]}"; do
artifact_file="${artifacts_dir}/react-native-${RELEASE}.0${i}"
[[ -f "${artifact_file}" ]] || show_error "Couldn't find file: ${artifact_file}"
[[ -f "${artifact_file}.asc" ]] || show_error "Couldn't find file: ${artifact_file}.asc"
done
show_success "Generated artifacts for Maven"
sed -ie -E "s/(\"version\":[[:space:]]*\").+(\")/\"version\": \"${RELEASE}.0-rc\"/g" "package.json" || show_error "Couldn't update version for NPM"
sed -ie -E "s/(s.version[[:space:]]{13}=[[:space:]].+)/s.version = \"${RELEASE}.0-rc\"/g" "React.podspec" || show_error "Couldn't update version for Cocoapods"
sed -ie -E "s/\"com\.facebook\.react:react-native:.+\"/\"com.facebook.react:react-native:${RELEASE}.+\"/g" "local-cli/generator-android/templates/src/app/build.gradle" || show_error "Couldn't update version in build.gradle"
show_success "Updated version numbers"
npm_registry="http://localhost:4873/"
npm set registry "${npm_registry}" && [[ $(npm config list | grep registry) == "registry = \"${npm_registry}\"" ]] || show_error "Couldn't set registry to ${npm_registry}"
show_info "NPM registry set. Run 'sinopia' in a new Terminal"
show_info " - Make sure it prints 'http address - ${npm_registry}'"
show_info " - Make sure ${npm_registry} shows no old versions"
show_info ""
show_info "Press any key to continue"
read -n 1
npm publish || show_error "Couldn't publish package to NPM (${npm_registry})"
show_success "Published package to NPM (${npm_registry})"
project_name="RNTestProject"
cd /tmp/
rm -rf "$project_name"
react-native init "$project_name"
grep "\"react-native\": \"^${RELEASE}.0\"" "${project_name}/package.json" || show_error "Incorrect version number in ${project_name}/package.json"
grep "com.facebook.react:react-native:${RELEASE}.+" "${project_name}/android/app/build.gradle" || show_error "Incorrect version number in ${project_name}/android/app/build.gradle"
show_success "New sample project generated at /tmp/${project_name}"
show_info "You need to test the following in both Android and iOS"
show_info " - Verify that packager opens in new Window"
show_info " - Verify that you see the 'Welcome to React Native' screen"
show_info " - Verify 'Reaload JS' works"
show_info " - Test Chrome debugger by adding breakpoints"
show_info ""
show_info "Press any key to open the project in XCode"
read -n 1
open "/tmp/${project_name}/ios/${project_name}.xcodeproj"
show_info "Press any key to run the sample in Android emulator/device"
read -n 1
cd "${project_name}" && react-native run-android
# TODO: Revert the Javadoc change in ReactAndroid/release.gradle
show_info "Press any key to view the diff"
read -n 1
git diff
show_info "Press any key to commit and push the changes to GitHub"
read -n 1
git commit -am "[${RELEASE}-rc] Bump version numbers"
# git push origin ${RELEASE}-stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment