Created
March 21, 2023 14:50
-
-
Save tomoakley/28b512e2d4557517ee6bc76f15fb8c5c to your computer and use it in GitHub Desktop.
CodePush version picker
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
#! /bin/bash | |
set -e | |
while getopts ":i:a:c:p:h" opt; do | |
case $opt in | |
i) IOS="$OPTARG" | |
;; | |
a) ANDROID="$OPTARG" | |
;; | |
c) TARGET_COMMIT_HASH="$OPTARG" | |
;; | |
p) ACTIVE_COMMIT_HASH="$OPTARG" | |
;; | |
h) printf "CodePush production deployment script: promote a release from stage to prod.\n Options: \n -i: iOS label - label of stage build to promote. Get from AppCenter. \n -a: Android label - label of stage build to promote from Android environment. Get from AppCenter. \n -h: Help - show this menu."; exit | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
notify_slack() { | |
CHANGELOG=$(git log --pretty="- %s%n" $ACTIVE_COMMIT_HASH..$TARGET_COMMIT_HASH | awk '/^- feat|^- fix|^- data|^- perf/') | |
GITHUB_LINK="https://github.com/path/to/repo/compare/$ACTIVE_COMMIT_HASH...$TARGET_COMMIT_HASH" | |
TEXT_BODY="New CodePush release: iOS: ${IOS}, Android: ${ANDROID} by $(whoami)" | |
if [[ ! -z "$ACTIVE_COMMIT_HASH" && ! -z "$TARGET_COMMIT_HASH" ]]; then | |
TEXT_BODY="$TEXT_BODY. Changelog:\n$CHANGELOG\n<$GITHUB_LINK|View changes on GitHub>" | |
fi | |
curl -X POST --data "{\"text\": \"$TEXT_BODY\", \"channel\": \"#channel-name\"}" --header 'Content-Type: application/json' https://hooks.slack.com/services/path/to/webhook | |
} | |
npx appcenter codepush promote -a AppCenter-org-name/iOS-App --label ${IOS} -s stage -d prod | |
npx appcenter codepush promote -a AppCenter-org-name/Android-App --label ${ANDROID} -s stage -d prod | |
notify_slack |
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
import sys | |
from signal import signal, SIGINT | |
import json | |
import subprocess | |
import pick | |
def handler(signal_received, frame): | |
print('SIGINT or CTRL-C detected. Exiting gracefully') | |
sys.exit(0) | |
def get_label(option): | |
return f"{option.get('android')} | {option.get('ios')} | {option.get('notes')}" | |
def deploy(ios, android, notes, current_prod_commit): | |
new_prod_commit = notes.split(' ')[0] | |
p = subprocess.Popen( | |
["./scripts/deploy.sh", '-i', ios, '-a', android, '-c', new_prod_commit, '-p', current_prod_commit], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
while True: | |
out = p.stdout.read(1).decode(sys.stdout.encoding) | |
if out == '' and p.poll() != None: | |
break | |
if out != '': | |
sys.stdout.write(out) | |
sys.stdout.flush() | |
title = ' Android | iOS | Notes' | |
if __name__ == '__main__': | |
signal(SIGINT, handler) | |
VERSION_INFO = sys.argv[1] | |
PROD_COMMIT = sys.argv[2] | |
versions = json.loads(VERSION_INFO) | |
selected = pick.pick(versions, title, indicator='*', options_map_func=get_label) | |
deploy(selected[0]['ios'], selected[0]['android'], selected[0]['notes'], PROD_COMMIT) |
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
#!/bin/bash | |
set -e | |
REQUIREMENTS="jq pip3 python3" | |
for i in $REQUIREMENTS; do | |
hash "$i" 2>/dev/null || { echo "$0": "I require "$i" but it\'s not installed."; exit 1; } | |
done | |
pip3 install pick==1.6.0 - quiet | |
VERSION=$(jq -r ".version" package.json | sed -r "s/([0–9]\.[0–9][0–9]\.)([0–9])/\1x/") | |
echo "Getting iOS stage deployments..." | |
IOS=$(yarn deploymentHistory:ios stage --output json | jq -r --arg VERSION "$VERSION" '.[] | select(.[2] == $VERSION) | { label: .[0], notes: .[4] }' | jq -s '.[-10:] | reverse | .') | |
echo "Getting Android stage deployments..." | |
ANDROID=$(yarn deploymentHistory:android stage --output json | jq -r --arg VERSION "$VERSION" '.[] | select(.[2] == $VERSION) | { label: .[0], notes: .[4] }' | jq -s '.[-10:] | reverse | .') | |
echo "Getting current production release details..." | |
LATEST_PROD_RELEASE=$(yarn deploymentHistory:ios prod --output json | jq -r --arg VERSION "$VERSION" '.[] | select(.[2] == $VERSION) | { label: .[0], notes: .[4] | split("\n") | .[1] }' | jq -s '.[-1:] | reverse | .[0].notes' | awk '{print $1;}') | |
VERSION_INFO=$(echo "${IOS} ${ANDROID}" | jq -s '.[0][] as $ios | (.[1][] | select($ios.notes == .notes)) as $android | { "ios": $ios.label, android: $android.label, notes: $ios.notes | split("\n") | .[1] }' | jq -s '.') | |
python3 "./scripts/picker.py" "$VERSION_INFO" "${LATEST_PROD_RELEASE:1}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment