Skip to content

Instantly share code, notes, and snippets.

@dhensby
Last active July 23, 2018 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhensby/1d5de50a0579029a3c674e31b6aad876 to your computer and use it in GitHub Desktop.
Save dhensby/1d5de50a0579029a3c674e31b6aad876 to your computer and use it in GitHub Desktop.
Create release branch from specific tag
#!/usr/bin/env bash
echo `pwd`
LEGACY_CORE=('cms' 'reports' 'siteconfig' 'framework' 'installer')
LEGACY_TAG="4.2.0-beta1"
LEGACY_BRANCH="4.2.0"
RECIPES=('recipe-cms' 'recipe-core')
NEW_CORE=('assets' 'admin' 'asset-admin' 'campaign-admin' 'errorpage' 'versioned')
NEW_TAG="1.2.0-beta1"
NEW_BRANCH="1.2.0"
GRAPHQL=('graphql')
GRAPHQL_TAG="2.0.0-beta1"
GRAPHQL_BRANCH="2.0.0"
CONFIG=('config')
CONFIG_TAG="1.0.5-beta1"
CONFIG_BRANCH="1.0.5"
ALLOWED_MODULES=()
COMPARE_URL=false
function skipmodule() {
if [ "${#ALLOWED_MODULES[@]}" -eq 0 ]; then
return 1;
else
for module in "${ALLOWED_MODULES[@]}"; do
if [[ "${module}" == "$1" ]]; then
return 1;
fi
done
fi
return 0
}
function usage() {
echo "$1 [modules] [--help] [--compare-url]"
echo "Where modules is a list of modules to make release branches for eg:"
echo "$1 config cms framework"
echo "options: --compare-url Outputs a URL for viewing comparison of patch branch with minor branch"
}
for arg in "$@"; do
if [[ ! "${arg}" =~ ^- ]]; then
ALLOWED_MODULES+=("${arg}")
elif [[ "${arg}" == '--help' ]]; then
usage "$0"
read -p "Continue"
exit
elif [[ "${arg}" == '--compare-url' ]]; then
COMPARE_URL=true
fi
done
for i in "${LEGACY_CORE[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Checkout $i:$LEGACY_TAG and branch $LEGACY_BRANCH"
if [ ! -d "$i" ]; then
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
fi
cd "$i"
git fetch --all
git rev-parse --verify "$LEGACY_BRANCH"
if [ $? -ne 0 ]; then
git checkout -b "$LEGACY_BRANCH" "$LEGACY_TAG"
git push origin "$LEGACY_BRANCH"
else
echo "Branch $LEGACY_BRANCH exists, skipping"
fi
if [ "${COMPARE_URL}" ]; then
echo "https://github.com/silverstripe/silverstripe-$i/compare/$LEGACY_BRANCH...${LEGACY_BRANCH:0:-2}"
fi
cd ..
done
for i in "${RECIPES[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Checkout $i:$LEGACY_TAG and branch $LEGACY_BRANCH"
if [ ! -d "$i" ]; then
git clone "https://github.com/silverstripe/$i" "$i"
fi
cd "$i"
git fetch --all
git rev-parse --verify "$LEGACY_BRANCH"
if [ $? -ne 0 ]; then
git checkout -b "$LEGACY_BRANCH" "$LEGACY_TAG"
git push origin "$LEGACY_BRANCH"
else
echo "Branch $LEGACY_BRANCH exists, skipping"
fi
if [ "${COMPARE_URL}" ]; then
echo "https://github.com/silverstripe/$i/compare/$LEGACY_BRANCH...${LEGACY_BRANCH:0:-2}"
fi
cd ..
done
for i in "${NEW_CORE[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Checkout $i:$NEW_TAG and branch $NEW_BRANCH"
if [ ! -d "$i" ]; then
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
fi
cd "$i"
git fetch --all
git rev-parse --verify "$NEW_BRANCH"
if [ $? -ne 0 ]; then
git checkout -b "$NEW_BRANCH" "$NEW_TAG"
git push origin "$NEW_BRANCH"
else
echo "Branch $NEW_BRANCH exists, skipping"
fi
if [ "${COMPARE_URL}" ]; then
echo "https://github.com/silverstripe/silverstripe-$i/compare/$NEW_BRANCH...${NEW_BRANCH:0:-2}"
fi
cd ..
done
for i in "${GRAPHQL[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Checkout $i:$GRAPHQL_TAG and branch $GRAPHQL_BRANCH"
if [ ! -d "$i" ]; then
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
fi
cd "$i"
git fetch --all
git rev-parse --verify "$GRAPHQL_BRANCH"
if [ $? -ne 0 ]; then
git checkout -b "$GRAPHQL_BRANCH" "$GRAPHQL_TAG"
git push origin "$GRAPHQL_BRANCH"
else
echo "Branch $GRAPHQL_BRANCH exists, skipping"
fi
if [ "${COMPARE_URL}" ]; then
echo "https://github.com/silverstripe/silverstripe-$i/compare/$GRAPHQL_BRANCH...${GRAPHQL_BRANCH:0:-2}"
fi
cd ..
done
for i in "${CONFIG[@]}"; do
if skipmodule "$i"; then
continue
fi
echo "Checkout $i:$CONFIG_TAG and branch $CONFIG_BRANCH"
if [ ! -d "$i" ]; then
git clone "https://github.com/silverstripe/silverstripe-$i" "$i"
fi
cd "$i"
git fetch --all
git rev-parse --verify "$CONFIG_BRANCH"
if [ $? -ne 0 ]; then
git checkout -b "$CONFIG_BRANCH" "$CONFIG_TAG"
git push origin "$CONFIG_BRANCH"
else
echo "Branch $CONFIG_BRANCH exists, skipping"
fi
if [ "${COMPARE_URL}" ]; then
echo "https://github.com/silverstripe/silverstripe-$i/compare/$CONFIG_BRANCH...${CONFIG_BRANCH:0:-2}"
fi
cd ..
done
read -p "Press enter to quit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment