tasks/release-patch-versions.sh
#!/bin/bash
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

# ******************************************************************************
# This releases an update to the `react-scripts` package.
# Don't use `npm publish` for it.
# Read the release instructions:
# https://github.com/facebookincubator/create-react-app/blob/master/CONTRIBUTING.md#cutting-a-release
# ******************************************************************************

# Start in tasks/ even if run from root directory
cd "$(dirname "$0")"

# Exit the script on any command with non 0 return code
# We assume that all the commands in the pipeline set their return code
# properly and that we do not need to validate that the output is correct
set -e

# Echo every command being executed
set -x

# Go to root
cd ..
root_path=$PWD
trigger_commit_message="[Publish patch versions]"

# Release after trigger only
if [[ "$(git log -1 --pretty=tformat:%B)" != *"$trigger_commit_message"* ]]; then
  echo "Commit message does not contain \"$trigger_commit_message\", not releasing anything";
  exit 0;
fi;

if [ -n "$(git status --porcelain)" ]; then
  echo "Your git status is not clean. Aborting.";
  exit 1;
fi

cd "$root_path"

# Install Yarn so that the test can use it to install packages.
export PATH="$HOME/.yarn/bin:$PATH"
yarn -v || curl -o- -L https://yarnpkg.com/install.sh | bash

# Install all dependencies
yarn install

# Go!
./node_modules/.bin/lerna publish --yes --cd-version patch "$@"
