Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
moved formula build into a separate script and made build-bottles cal…
…l build-formula
  • Loading branch information
bwagner5 committed May 15, 2020
1 parent aba72f0 commit 726c03b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 43 deletions.
79 changes: 36 additions & 43 deletions build-bottles.sh
@@ -1,53 +1,46 @@
#!/bin/bash
set -euo errexit
#!/usr/bin/env bash
set -euo pipefail

# Get path of this script so that paths are relative to it.
# This allows it to be executed from anywhere on the file system.
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
BUILD_DIR="$SCRIPTPATH/build"
BUILD_DIR="${SCRIPTPATH}/build"
# Create temp dir at root to hold files during this execution
rm -rf $BUILD_DIR
mkdir -p $BUILD_DIR
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}

# Setting up build environment
FAILED_BUILDS=()

echo "⏳ Setting up the build environment"
brew tap aws/tap # adding aws tap so that we can install bottles
brew install rename || : # Gnu rename to find and replace words in file name.
brew install jq || :

for bottle_file in Formula/*.rb; do
BOTTLE=$(basename $bottle_file .rb)
brew uninstall -f $BOTTLE
brew install --build-bottle $BOTTLE

BOTTLE_CONFIG=$(jq -r '.' $SCRIPTPATH/bottle-configs/$BOTTLE.json)
BOTTLE_ASSET_VERSION="$(echo $BOTTLE_CONFIG | jq -r '.version')"
echo "[$BOTTLE]: Version -> $BOTTLE_ASSET_VERSION"
BOTTLE_ASSET_URL="$(echo $BOTTLE_CONFIG | jq -r '.bottle.root_url')"
echo "[$BOTTLE]: Root URL -> $BOTTLE_ASSET_URL"
BIN_NAME=$(echo $BOTTLE_CONFIG | jq -r '.bin')
echo "[$BOTTLE]: Bottle Binary -> $BIN_NAME"

cd $BUILD_DIR
brew bottle --no-rebuild --json --root-url=$BOTTLE_ASSET_URL $BOTTLE
cd $SCRIPTPATH

# Renaming aws-sam-cli--0.37.0.sierra.bottle.tar.gz to aws-sam-cli-0.37.0.sierra.bottle.tar.gz
rename 's/--/-/' $BUILD_DIR/*.tar.gz # replacing `--` with `-`

echo "[$BOTTLE]: Brew bottles are built. Validating them now."
RELEASE_FILE="$(ls $BUILD_DIR/$BOTTLE-*.bottle.tar.gz)"
echo "[$BOTTLE]: Release file -> $RELEASE_FILE"

brew uninstall -f $BOTTLE
echo "[$BOTTLE]: Installing release file"
brew install $RELEASE_FILE

BUILT_BOTTLE_VERSION="$($BIN_NAME --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')"
if [[ "$BOTTLE_ASSET_VERSION" == "$BUILT_BOTTLE_VERSION" ]]
then
echo "✅ [$BOTTLE]: Verified that the new $BOTTLE version $BUILT_BOTTLE_VERSION is the same as what is expected $BOTTLE_ASSET_VERSION 🎉🥂✅"
else
echo "❌ [$BOTTLE]: Version check failed. Expected: $BOTTLE_ASSET_VERSION, Received: $BUILT_BOTTLE_VERSION"
exit 1
fi
done
for formula_file in Formula/*.rb; do
[ ! -e "$formula_file" ] && continue
BOTTLE=$(basename ${formula_file} .rb)
${SCRIPTPATH}/build-formula.sh -s -f "${formula_file}" || :
for f in ${BUILD_DIR}/${BOTTLE}*.bottle.tar.gz; do
[ ! -e "$f" ] && FAILED_BUILDS+=(${formula_file})
break
done
done

printf "\n"
echo "========================================================================="
if [[ ${#FAILED_BUILDS[@]} -gt 0 ]]; then
echo "Failure Summary:"
for failed_formula in "${FAILED_BUILDS[@]}"; do
echo "${failed_formula} failed to build"
done
else
echo "✅ Successfully built all formulas"
fi

printf "\n"
echo "Success Summary:"
for succeeded_formula in ${BUILD_DIR}/*.bottle.tar.gz; do
[ ! -e "$succeeded_formula" ] && continue
echo "$(basename ${succeeded_formula} .bottle.tar.gz) was successfully built"
done
echo "========================================================================="
90 changes: 90 additions & 0 deletions build-formula.sh
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
set -euo pipefail

# Get path of this script so that paths are relative to it.
# This allows it to be executed from anywhere on the file system.
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
BUILD_DIR="$SCRIPTPATH/build"
# Create temp dir at root to hold files during this execution
mkdir -p $BUILD_DIR

USAGE=$(cat << 'EOM'
Usage: build-formula.sh -f formula_file
Builds the formula into a bottle and places it into the build dir.
Example: build-formula.sh -f Formula/aws-sam-cli.rb
Optional:
-h Print this usage help
EOM
)

SKIP_SETUP="false"

# Process our input arguments
while getopts "f:s" opt; do
case ${opt} in
f ) # Full Formula File Path
FORMULA_FILE="${OPTARG}"
;;
s ) # Skip setup
SKIP_SETUP="true"
;;
\? )
echoerr "$USAGE" 1>&2
exit
;;
esac
done

BOTTLE=$(basename ${FORMULA_FILE} .rb)

function fail_msg() {
echo "❌ Failed to build ${FORMULA_FILE}"
rm -f ${BUILD_DIR}/$BOTTLE*.bottle.tar.gz
rm -f ${BUILD_DIR}/$BOTTLE*.bottle.json
exit 2
}

trap fail_msg err int term kill

if [[ "${SKIP_SETUP}" = "false" ]]; then
echo "⏳ Setting up the build environment"
brew tap aws/tap # adding aws tap so that we can install bottles
brew install rename || : # Gnu rename to find and replace words in file name.
brew install jq || :
fi

echo "🎬 Starting formula build for ${FORMULA_FILE}"
brew uninstall -f ${BOTTLE}
brew install --build-bottle ${BOTTLE}

BOTTLE_CONFIG=$(jq -r '.' ${SCRIPTPATH}/bottle-configs/${BOTTLE}.json)
BOTTLE_ASSET_VERSION="$(echo ${BOTTLE_CONFIG} | jq -r '.version')"
echo "[${BOTTLE}]: Version -> ${BOTTLE_ASSET_VERSION}"
BOTTLE_ASSET_URL="$(echo ${BOTTLE_CONFIG} | jq -r '.bottle.root_url')"
echo "[${BOTTLE}]: Root URL -> ${BOTTLE_ASSET_URL}"
BIN_NAME=$(echo ${BOTTLE_CONFIG} | jq -r '.bin')
echo "[${BOTTLE}]: Bottle Binary -> ${BIN_NAME}"

# Need to cd since brew bottle doesn't have an option to
cd "${BUILD_DIR}"
brew bottle --no-rebuild --json --root-url="${BOTTLE_ASSET_URL}" "${BOTTLE}"
cd ${SCRIPTPATH}

# Renaming aws-sam-cli--0.37.0.sierra.bottle.tar.gz to aws-sam-cli-0.37.0.sierra.bottle.tar.gz
rename 's/--/-/' ${BUILD_DIR}/*.tar.gz # replacing `--` with `-`

echo "[${BOTTLE}]: Brew bottles are built. Validating them now."
RELEASE_FILE="$(ls ${BUILD_DIR}/${BOTTLE}-*.bottle.tar.gz)"
echo "[${BOTTLE}]: Release file -> ${RELEASE_FILE}"

brew uninstall -f ${BOTTLE}
echo "[${BOTTLE}]: Installing release file"
brew install ${RELEASE_FILE}

BUILT_BOTTLE_VERSION="$(${BIN_NAME} --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')"
if [[ "${BOTTLE_ASSET_VERSION}" != "${BUILT_BOTTLE_VERSION}" ]]; then
echo "❌ [${BOTTLE}]: Version check failed. Expected: ${BOTTLE_ASSET_VERSION}, Received: ${BUILT_BOTTLE_VERSION}"
exit 1
fi

echo "✅ [${BOTTLE}]: Verified that the new ${BOTTLE} version ${BUILT_BOTTLE_VERSION} is the same as what is expected ${BOTTLE_ASSET_VERSION} 🎉🥂✅"

0 comments on commit 726c03b

Please sign in to comment.