Skip to content

Commit

Permalink
Merge pull request #2554 from wordpress-mobile/try/update-release-aut…
Browse files Browse the repository at this point in the history
…omation-script

Update release automation script to create WPiOS and WPAndroid PRs
  • Loading branch information
cameronvoell authored Aug 18, 2020
2 parents 8e2e07b + ab2dded commit 0bc13d8
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 120 deletions.
190 changes: 144 additions & 46 deletions bin/release_automation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ source bin/release_prechecks.sh
source bin/release_utils.sh

# Check that Github CLI is installed
command -v gh >/dev/null || { echo "Error: The Github CLI must be installed."; exit 1; }
command -v gh >/dev/null || abort "Error: The Github CLI must be installed."

# Check that jq is installed
command -v jq >/dev/null || abort "Error: jq must be installed."

# Check that Aztec versions are set to release versions
aztec_version_problems="$(check_android_and_ios_aztec_versions)"
if [[ ! -z "$aztec_version_problems" ]]; then
printf "\nThere appear to be problems with the Aztec versions:\n$aztec_version_problems\n"
warn "There appear to be problems with the Aztec versions:\n$aztec_version_problems"
confirm_to_proceed "Do you want to proceed with the release despite the ^above^ problem(s) with the Aztec version?"
else
echo "Confirmed that Aztec Libraries are set to release versions. Proceeding..."
ohai "Confirmed that Aztec Libraries are set to release versions. Proceeding..."
fi

## Check current branch is develop, main, or release/* branch
Expand All @@ -34,19 +37,19 @@ if [[ ! "$CURRENT_BRANCH" =~ "^develop$|^main$|^release/.*" ]]; then
fi

# Confirm branch is clean
[[ -z "$(git status --porcelain)" ]] || { git status; printf "\nUncommitted changes found. Aborting release script...\n"; exit 1; }
[[ -z "$(git status --porcelain)" ]] || { git status; abort "Uncommitted changes found. Aborting release script..."; }

# Ask for new version number
CURRENT_VERSION_NUMBER=$(./node_modules/.bin/json -f package.json version)
CURRENT_VERSION_NUMBER=$(jq '.version' package.json --raw-output)
echo "Current Version Number:$CURRENT_VERSION_NUMBER"
read -p "Enter the new version number: " VERSION_NUMBER
if [[ -z "$VERSION_NUMBER" ]]; then
echo "Version number cannot be empty."
exit 1
abort "Version number cannot be empty."
fi

# Insure javascript dependencies are up-to-date
npm ci || { echo "Error: 'npm ci' failed"; echo 1; }
# Ensure javascript dependencies are up-to-date
ohai "Run 'npm ci' to ensure javascript dependencies are up-to-date"
execute "npm" "ci"


# If there are any open PRs with a milestone matching the release version number, notify the user and ask them if they want to proceed
Expand All @@ -58,73 +61,76 @@ fi

# Create Git branch
RELEASE_BRANCH="release/$VERSION_NUMBER"
git switch -c "$RELEASE_BRANCH" || { echo "Error: could not create '$RELEASE_BRANCH' branch."; exit 1; }
ohai "Create Git branch '$RELEASE_BRANCH' in gutenberg-mobile."
execute "git" "switch" "-c" "$RELEASE_BRANCH"

# Create Git branch in Gutenberg
GB_RELEASE_BRANCH="rnmobile/release_$VERSION_NUMBER"
ohai "Create Git branch '$GB_RELEASE_BRANCH' in gutenberg."
cd gutenberg
git switch -c "$GB_RELEASE_BRANCH" || { echo "Error: could not create '$GB_RELEASE_BRANCH' branch."; exit 1; }
execute "git" "switch" "-c" "$GB_RELEASE_BRANCH"
cd ..

# Set version numbers
for file in 'package.json' 'package-lock.json' 'gutenberg/packages/react-native-editor/package.json'; do
npx json -I -f "$file" -e "this.version='$VERSION_NUMBER'" || { echo "Error: could not update version in ${file}"; exit 1; }
ohai "Set version numbers in package.json files"
for file in 'package.json' 'package-lock.json' 'gutenberg/packages/react-native-aztec/package.json' 'gutenberg/packages/react-native-bridge/package.json' 'gutenberg/packages/react-native-editor/package.json'; do
TEMP_FILE=$(mktemp)
execute "jq" ".version = \"$VERSION_NUMBER\"" "$file" > "$TEMP_FILE"
execute "mv" "$TEMP_FILE" "$file"
done

# Commit react-native-editor version update
# Commit react-native-aztec, react-native-bridge, react-native-editor version update
ohai "Commit react-native-aztec, react-native-bridge, react-native-editor version update version update"
cd gutenberg
git add 'packages/react-native-editor/package.json'
git commit -m "Release script: Update react-native-editor version to $VERSION_NUMBER" || { echo "Error: failed to commit changes"; exit 1; }
git add 'packages/react-native-aztec/package.json' 'packages/react-native-bridge/package.json' 'packages/react-native-editor/package.json'
execute "git" "commit" "-m" "Release script: Update react-native-editor version to $VERSION_NUMBER"
cd ..

# Commit gutenberg-mobile version updates
ohai "Commit gutenberg-mobile version updates"
git add 'package.json' 'package-lock.json'
git commit -m "Release script: Update gb mobile version to $VERSION_NUMBER" || { echo "Error: failed to commit changes"; exit 1; }

execute "git" "commit" "-m" "Release script: Update gb mobile version to $VERSION_NUMBER"

# Make sure podfile is updated
ohai "Make sure podfile is updated"
PRE_IOS_COMMAND="npm run core preios"
eval "$PRE_IOS_COMMAND"

# If preios results in changes, commit them
cd gutenberg
if [[ ! -z "$(git status --porcelain)" ]]; then
git commit -a -m "Release script: Update with changes from '$PRE_IOS_COMMAND'" || { echo "Error: failed to commit changes from '$PRE_IOS_COMMAND'"; exit 1; }
ohai "Commit changes from '$PRE_IOS_COMMAND'"
execute "git" "commit" "-a" "-m" "Release script: Update with changes from '$PRE_IOS_COMMAND'"
else
echo "There were no changes from '$PRE_IOS_COMMAND' to be committed."
ohai "There were no changes from '$PRE_IOS_COMMAND' to be committed."
fi
cd ..


# Update the bundles
npm run bundle || { printf "\nError: 'npm bundle' failed.\nIf there is an error stating something like \"Command 'bundle' unrecognized.\" above, perhaps try running 'rm -rf node_modules gutenberg/node_modules && npm install'.\n"; exit 1; }
ohai "Update the bundles"
npm run bundle || abort "Error: 'npm bundle' failed.\nIf there is an error stating something like \"Command 'bundle' unrecognized.\" above, perhaps try running 'rm -rf node_modules gutenberg/node_modules && npm ci'."

# Commit bundle changes along with any update to the gutenberg submodule (if necessary)
git commit -a -m "Release script: Update bundle for: $VERSION_NUMBER" || { echo "Error: failed to commit changes"; exit 1; }
ohai "Commit bundle changes along with any update to the gutenberg submodule (if necessary)"
execute "git" "commit" "-a" "-m" "Release script: Update bundle for: $VERSION_NUMBER"


#####
# Create PRs
#####

# Verify before creating PRs
echo "This script will now create a Gutenberg-Mobile PR for the $RELEASE_BRANCH branch and a Gutenberg PR for the $GB_RELEASE_BRANCH branch."
read -p "Would you like to proceed? (y/n) " -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
printf "\n\nProceeding to create a PR...\n"
else
printf "\n\nFinishing release script without creating a PR\n"
exit 1
fi

confirm_to_proceed "Do you want to proceed with creating a Gutenberg-Mobile PR for the $RELEASE_BRANCH branch and a Gutenberg PR for the $GB_RELEASE_BRANCH branch."
ohai "Proceeding to create PRs..."

#####
# Gutenberg-Mobile PR
#####

# Read GB-Mobile PR template
PR_TEMPLATE_PATH='.github/PULL_REQUEST_TEMPLATE/release_pull_request.md'
test -f "$PR_TEMPLATE_PATH" || { echo "Error: Could not find PR template at $PR_TEMPLATE_PATH"; exit 1; }
test -f "$PR_TEMPLATE_PATH" || abort "Error: Could not find PR template at $PR_TEMPLATE_PATH"
PR_TEMPLATE=$(cat "$PR_TEMPLATE_PATH")

# Replace version number in GB-Mobile PR template
Expand All @@ -133,15 +139,10 @@ PR_BODY=${PR_TEMPLATE//v1.XX.Y/$VERSION_NUMBER}
# Insure PR is created on proper remote
# see https://github.com/cli/cli/issues/800
BASE_REMOTE=$(get_remote_name 'wordpress-mobile/gutenberg-mobile')
git push -u "$BASE_REMOTE" HEAD || { echo "Unable to push to remote $BASE_REMOTE"; exit 1; }
execute "git" "push" "-u" "$BASE_REMOTE" "HEAD"

# Create Draft GB-Mobile Release PR in GitHub
GB_MOBILE_PR_URL=$(gh pr create --title "Release $VERSION_NUMBER" --body "$PR_BODY" --base main --label "release-process" --draft)
if [[ $? != 0 ]]; then
echo "Error: Failed to create Gutenberg-Mobile PR"
exit 1
fi

GB_MOBILE_PR_URL=$(execute "gh" "pr" "create" "--title" "Release $VERSION_NUMBER" "--body" "$PR_BODY" "--base" "main" "--label" "release-process" "--draft")

#####
# Gutenberg PR
Expand All @@ -150,7 +151,7 @@ fi
# Get Checklist from Gutenberg PR template
cd gutenberg
GUTENBERG_PR_TEMPLATE_PATH=".github/PULL_REQUEST_TEMPLATE.md"
test -f "$GUTENBERG_PR_TEMPLATE_PATH" || { echo "Error: Could not find PR template at $GUTENBERG_PR_TEMPLATE_PATH"; exit 1; }
test -f "$GUTENBERG_PR_TEMPLATE_PATH" || abort "Error: Could not find PR template at $GUTENBERG_PR_TEMPLATE_PATH"
# Get the checklist from the gutenberg PR template by removing everything before the '## Checklist:' line
CHECKLIST_FROM_GUTENBERG_PR_TEMPLATE=$(cat "$GUTENBERG_PR_TEMPLATE_PATH" | sed -e/'## Checklist:'/\{ -e:1 -en\;b1 -e\} -ed)

Expand All @@ -166,17 +167,114 @@ $CHECKLIST_FROM_GUTENBERG_PR_TEMPLATE"
# Insure PR is created on proper remote
# see https://github.com/cli/cli/issues/800
GB_BASE_REMOTE=$(get_remote_name 'WordPress/gutenberg')
git push -u "$GB_BASE_REMOTE" HEAD || { echo "Unable to push to remote: $GB_BASE_REMOTE"; exit 1; }
execute "git" "push" "-u" "$GB_BASE_REMOTE" "HEAD"

# Create Draft Gutenberg Release PR in GitHub
GUTENBERG_PR_URL=$(gh pr create --title "Mobile Release v$VERSION_NUMBER" --body "$GUTENBERG_PR_BODY" --base master --label 'Mobile App Android/iOS' --draft)
if [[ $? != 0 ]]; then
echo "Error: Failed to create Gutenberg PR"
exit 1
fi
GUTENBERG_PR_URL=$(execute "gh" "pr" "create" "--title" "Mobile Release v$VERSION_NUMBER" "--body" "$GUTENBERG_PR_BODY" "--base" "master" "--label" "Mobile App Android/iOS" "--draft")
cd ..

echo "PRs Created"
echo "==========="
printf "Gutenberg-Mobile $GB_MOBILE_PR_URL
Gutenberg $GUTENBERG_PR_URL\n" | column -t

confirm_to_proceed "Do you want to proceed with creating main apps (WPiOS and WPAndroid) PRs?"
ohai "Proceeding to create main apps PRs..."

GB_MOBILE_PR_REF=$(git rev-parse HEAD)

#####
# WPAndroid PR
#####

TEMP_WP_ANDROID_DIRECTORY=$(mktemp -d)
ohai "Clone WordPress-Android into '$TEMP_WP_ANDROID_DIRECTORY'"
execute "git" "clone" "--depth=1" "[email protected]:wordpress-mobile/WordPress-Android.git" "$TEMP_WP_ANDROID_DIRECTORY"

cd "$TEMP_WP_ANDROID_DIRECTORY"

execute "git" "submodule" "update" "--init" "--recursive" "--depth=1" "--recommend-shallow"

ohai "Create release branch in WordPress-Android"
execute "git" "switch" "-c" "gutenberg/integrate_release_$VERSION_NUMBER"

ohai "Update gutenberg-mobile ref"
cd libs/gutenberg-mobile
execute "git" "fetch" "--recurse-submodules=no" "origin" "$GB_MOBILE_PR_REF"
execute "git" "checkout" "$GB_MOBILE_PR_REF"
cd ../..

execute "git" "add" "libs/gutenberg-mobile"
execute "git" "commit" "-m" "Release script: Update gutenberg-mobile ref"

ohai "Update strings"
execute "python" "tools/merge_strings_xml.py"
execute "git" "add" "WordPress/src/main/res/values/strings.xml"
execute "git" "commit" "-m" "Release script: Update strings"

# Insure PR is created on proper remote
# see https://github.com/cli/cli/issues/800
WP_ANDROID_BASE_REMOTE=$(get_remote_name 'wordpress-mobile/WordPress-android')
execute "git" "push" "-u" "$WP_ANDROID_BASE_REMOTE" "HEAD"

WP_ANDROID_PR_BODY="## Description
This PR incorporates the $VERSION_NUMBER release of gutenberg-mobile.
For more information about this release and testing instructions, please see the related Gutenberg-Mobile PR: $GB_MOBILE_PR_URL
Release Submission Checklist
- [ ] I have considered if this change warrants user-facing release notes and have added them to `RELEASE-NOTES.txt` if necessary."

# Create Draft WPAndroid Release PR in GitHub
ohai "Create Draft WPAndroid Release PR in GitHub"
WP_ANDROID_PR_URL=$(execute "gh" "pr" "create" "--title" "Integrate gutenberg-mobile release $VERSION_NUMBER" "--body" "$WP_ANDROID_PR_BODY" "--base" "develop" "--label" "gutenberg-mobile" "--draft")

ohai "WPAndroid PR Created: $WP_ANDROID_PR_URL"


#####
# WPiOS PR
#####

TEMP_WP_IOS_DIRECTORY=$(mktemp -d)
ohai "Clone WordPress-iOS into '$TEMP_WP_IOS_DIRECTORY'"
execute "git" "clone" "--depth=1" "[email protected]:wordpress-mobile/WordPress-iOS.git" "$TEMP_WP_IOS_DIRECTORY"

cd "$TEMP_WP_IOS_DIRECTORY"

ohai "Create release branch in WordPress-iOS"
execute "git" "switch" "-c" "gutenberg/integrate_release_$VERSION_NUMBER"

ohai "Update gutenberg-mobile ref"
test -f "Podfile" || abort "Error: Could not find Podfile"
sed -i'.orig' -E "s/gutenberg :commit => '(.*)'/gutenberg :commit => '$GB_MOBILE_PR_REF'/" Podfile || abort "Error: Failed updating gutenberg ref in Podfile"
execute "rake" "dependencies"


execute "git" "add" "Podfile" "Podfile.lock"
execute "git" "commit" "-m" "Release script: Update gutenberg-mobile ref"

# Insure PR is created on proper remote
# see https://github.com/cli/cli/issues/800
WP_IOS_BASE_REMOTE=$(get_remote_name 'wordpress-mobile/WordPress-iOS')
execute "git" "push" "-u" "$WP_IOS_BASE_REMOTE" "HEAD"

WP_IOS_PR_BODY="## Description
This PR incorporates the $VERSION_NUMBER release of gutenberg-mobile.
For more information about this release and testing instructions, please see the related Gutenberg-Mobile PR: $GB_MOBILE_PR_URL
Release Submission Checklist
- [ ] I have considered if this change warrants user-facing release notes and have added them to `RELEASE-NOTES.txt` if necessary."

# Create Draft WPiOS Release PR in GitHub
ohai "Create Draft WPiOS Release PR in GitHub"
WP_IOS_PR_URL=$(execute "gh" "pr" "create" "--title" "Integrate gutenberg-mobile release $VERSION_NUMBER" "--body" "$WP_IOS_PR_BODY" "--base" "develop" "--label" "Gutenberg integration" "--draft")

ohai "WPiOS PR Created: $WP_IOS_PR_URL"

echo "Main apps PRs created"
echo "==========="
printf "WPAndroid $WP_ANDROID_PR_URL
WPiOS $WP_IOS_PR_URL\n" | column -t

21 changes: 3 additions & 18 deletions bin/release_prechecks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,14 @@
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$SCRIPT_PATH/.."

#####
# Confirm to Proceed Prompt
#####

# Accepts a single argument: a yes/no question (ending with a ? most likely) to ask the user
function confirm_to_proceed() {
read -p "$1 (y/n) " -n 1
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
printf "Aborting release...\n"
exit 1
fi
}

#####
# PR Milestone check
#####

function check_num_milestone_prs() {
MILESTONE_NAME="$1"
curl -s -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/wordpress-mobile/gutenberg-mobile/milestones" \
| npx json -c "this.title === '$MILESTONE_NAME'" -a open_issues
MILESTONE_NAME="$1"
curl -s "https://api.github.com/repos/wordpress-mobile/gutenberg-mobile/milestones" \
| jq ".[] | select(.title == \"$MILESTONE_NAME\") | .open_issues"
}

function check_if_version_has_pending_prs_for_milestone() {
Expand Down
Loading

0 comments on commit 0bc13d8

Please sign in to comment.