Files
flipper/scripts/prepare-release.sh
Michel Weststrate 8f2dd977b7 unify internal and external release into one flow
Summary:
This diff makes updating the internal and external release part of the same flow. The will be changed to:

1. The chronos job is kicked to start a new release
2. That job kicks of `./prepare-release.sh` (see D20304039) which
   1. bumps the version of all packages
   2. generates the changelog
   3. generates a release diff + test instructions for that
   4. generates a diff with snapshot version updates
   5. submit those commits
3. when this is job is completed, the relevant release commits can be checked out and tested.
4. If these job is landed, this will kick off the OSS builds through `release.sh` (as-is). But, this will also generate a diff that updates the flipper pin to the verify same commit (new).

Next steps:
* [ ] update wiki

Code pointers (irrelevant for review):
- Chronos Job entry https://our.intern.facebook.com/intern/diffusion/WWW/browse/master/flib/intern/sandcastle/commands/SandcastleFlipperAutoReleaseCommand.php?lines=85
- Sonar build step: https://our.intern.facebook.com/intern/diffusion/WWW/browse/master/flib/intern/sandcastle/sonar/SandcastleSonarBuildStep.php?lines=84
- Release commit observer: https://our.intern.facebook.com/intern/diffusion/WWW/browse/master/flib/intern/entity/opensource/github/observers/EntOpensourceGitHubCommitBuilderObserver.php?lines=17-48

Reviewed By: passy

Differential Revision: D20283664

fbshipit-source-id: 129ea862bda4721d707f1b6fdd862a937c0ed6d5
2020-03-10 02:48:14 -07:00

134 lines
5.0 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -e
darwin=false
case "$(uname)" in
Darwin*) darwin=true ;;
esac
if ! jq --version > /dev/null; then
if $darwin; then
echo -e "jq is not installed! Should the script install it for you? (y/n) \\c"
read -r REPLY
if [ "$REPLY" = "y" ]; then
brew install jq
else
exit 1
fi
else
echo >&2 "jq is not installed. Please install it using your platform's package manager (apt-get, yum, pacman, etc.)."
exit 1
fi
fi
echo "Checking for any uncommitted changes..."
CHANGES=$(hg st)
echo "$CHANGES"
if [ ! -z "$CHANGES" ];
then
echo "There are uncommitted changes, either commit or revert them."
exit 1
fi
echo "✨ Making a new release..."
REVISION="$1"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SONAR_DIR="$DIR/../"
FLIPPERKIT_PODSPEC_PATH="$SONAR_DIR/FlipperKit.podspec"
FLIPPER_PODSPEC_PATH="$SONAR_DIR/Flipper.podspec"
TUTORIAL_PODFILE_PATH="$SONAR_DIR/iOS/Tutorial/Podfile"
SONAR_GETTING_STARTED_DOC="$SONAR_DIR/docs/getting-started.md"
SPECS_DIR="$SONAR_DIR/Specs/"
FLIPPERKIT_VERSION_TAG='flipperkit_version'
OLD_VERSION_POD_ARG=$(< "$FLIPPER_PODSPEC_PATH" grep "$FLIPPERKIT_VERSION_TAG =" )
OLD_VERSION="${OLD_VERSION_POD_ARG##* }"
# if we got called with a rev argument, we got triggered from our automatic sandcastle job
if [ "$REVISION" != "" ];
then
# In future, bump majors instead of minors?
echo "Automatically bumping version to next minor in package.json"
npm -C "$SONAR_DIR" version minor
VERSION=$(jq -r '.version' "$SONAR_DIR"/package.json)
else
echo "The currently released version is $OLD_VERSION. What should the version of the next release be?"
read -r VERSION
fi
echo "Preparing release $VERSION..."
# Update react-native-flipper to the very same version
npm -C "$SONAR_DIR"react-native/react-native-flipper version "$VERSION"
# This could be one expression with GNU sed, but I guess we want to support the BSD crap, too.
SNAPSHOT_MINOR_VERSION=$(echo "$VERSION" | sed -Ee 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\3 + 1/' | bc)
SNAPSHOT_VERSION="$(echo "$VERSION" | sed -Ee 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1.\2./')""$SNAPSHOT_MINOR_VERSION""-SNAPSHOT"
echo "Updating version $VERSION in podspecs, podfiles and in getting started docs..."
# Update Podspec files and podfiles with correct version
echo "Updating $FLIPPERKIT_PODSPEC_PATH"
if $darwin; then
sed -i '' "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$FLIPPERKIT_PODSPEC_PATH"
echo "Updating $FLIPPER_PODSPEC_PATH"
sed -i '' "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$FLIPPER_PODSPEC_PATH"
echo "Updating $SONAR_GETTING_STARTED_DOC"
sed -i '' "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$SONAR_GETTING_STARTED_DOC"
echo "Updating $TUTORIAL_PODFILE_PATH"
sed -i '' "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$TUTORIAL_PODFILE_PATH"
else
sed -i "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$FLIPPERKIT_PODSPEC_PATH"
echo "Updating $FLIPPER_PODSPEC_PATH"
sed -i "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$FLIPPER_PODSPEC_PATH"
echo "Updating $SONAR_GETTING_STARTED_DOC"
sed -i "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$SONAR_GETTING_STARTED_DOC"
echo "Updating $TUTORIAL_PODFILE_PATH"
sed -i "s/${FLIPPERKIT_VERSION_TAG} = ${OLD_VERSION}/${FLIPPERKIT_VERSION_TAG} = '${VERSION}'/" "$TUTORIAL_PODFILE_PATH"
fi
echo "Bumping version number for android related files..."
# Update Android related files
"$SONAR_DIR"/scripts/bump.sh "$VERSION"
# Generate changelog
./generate-changelog.js
# Create commit
echo "Committing the files..."
hg addremove
hg commit -m "$(echo -e "Flipper Release: v${VERSION}\n\n\
Summary:\nReleasing version $VERSION\n\n\
Test Plan:\n\
* Wait until this build is green\n\
* Find the release id as explained here: https://our.internmc.facebook.com/intern/wiki/Flipper_Internals/Oncall_Runbook/#testing-the-release-vers and run:
* \`env FLIPPERVERSION=XXXX /Applications/Flipper.app/Contents/MacOS/Flipper\`\n\
* ...or, alternatively, run \`yarn build --mac && dist/mac/Flipper.app/Contents/MacOS/Flipper\`\n\
* Perform exploratory tests\n\n\
Reviewers: flipper\n\n\
Tags: accept2ship"
)"
# Create snapshot commit
RELEASE_REV="$(hg log -r . --template "{node}\\n")"
echo "Release commit made as $RELEASE_REV, creating new snapshot version $SNAPSHOT_VERSION..."
"$SONAR_DIR"/scripts/bump.sh --snapshot "$SNAPSHOT_VERSION"
hg commit -m "$(echo -e "Flipper Snapshot Bump: v${SNAPSHOT_VERSION}\n\n\
Summary:\nReleasing snapshot version $SNAPSHOT_VERSION\n\n\
Test Plan:\nN/A\n\n\
Reviewers: flipper\n\n\
Tags: accept2ship"
)"
# Submit diffs
echo "Submitting diffs for review..."
jf submit -n -r.^::.