Added bats and tests for gh-pages
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
#!/bin/bash -x
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: (cd <project root>; ghpages.sh -v <version> -b -c)
|
||||
|
||||
set -e
|
||||
|
||||
export GIT_BIN ROOT_FOLDER COMMIT_CHANGES MAVEN_PATH MAVEN_EXEC REPO_NAME SPRING_CLOUD_STATIC_REPO
|
||||
export CURRENT_BRANCH PREVIOUS_BRANCH
|
||||
|
||||
GIT_BIN="${GIT_BIN:-git}"
|
||||
|
||||
# The script should be executed from the root folder
|
||||
ROOT_FOLDER="$( pwd )"
|
||||
echo "Current folder is ${ROOT_FOLDER}"
|
||||
|
||||
# Set default props like MAVEN_PATH, ROOT_FOLDER etc.
|
||||
function set_default_props() {
|
||||
# The script should be executed from the root folder
|
||||
ROOT_FOLDER=`pwd`
|
||||
echo "Current folder is ${ROOT_FOLDER}"
|
||||
|
||||
if [[ ! -e "${ROOT_FOLDER}/.git" ]]; then
|
||||
echo "You're not in the root folder of the project!"
|
||||
exit 1
|
||||
@@ -24,8 +29,8 @@ function set_default_props() {
|
||||
MAVEN_EXEC="${MAVEN_PATH}mvn"
|
||||
fi
|
||||
echo "Path to Maven is [${MAVEN_EXEC}]"
|
||||
if [ -z $REPO_NAME ]; then
|
||||
REPO_NAME=$(git remote -v | grep origin | head -1 | sed -e 's!.*/!!' -e 's/ .*//' -e 's/\.git.*//')
|
||||
if [ -z "${REPO_NAME}" ]; then
|
||||
REPO_NAME="$("${GIT_BIN}" remote -v | grep origin | head -1 | sed -e 's!.*/!!' -e 's/ .*//' -e 's/\.git.*//')"
|
||||
fi
|
||||
echo "Repo name is [${REPO_NAME}]"
|
||||
SPRING_CLOUD_STATIC_REPO=${SPRING_CLOUD_STATIC_REPO:-git@github.com:spring-cloud/spring-cloud-static.git}
|
||||
@@ -34,22 +39,23 @@ function set_default_props() {
|
||||
|
||||
# Adds the oauth token if present to the remote url
|
||||
function add_oauth_token_to_remote_url() {
|
||||
remote=`git config remote.origin.url | sed -e 's/^git:/https:/'`
|
||||
local remote
|
||||
remote="$( "${GIT_BIN}" config remote.origin.url | sed -e 's/^git:/https:/' )"
|
||||
echo "Current remote [${remote}]"
|
||||
if [[ "${RELEASER_GIT_OAUTH_TOKEN}" != "" && ${remote} != *"@"* ]]; then
|
||||
echo "OAuth token found. Will reuse it to push the code"
|
||||
withToken=${remote/https:\/\//https://${RELEASER_GIT_OAUTH_TOKEN}@}
|
||||
git remote set-url --push origin "${withToken}"
|
||||
"${GIT_BIN}" remote set-url --push origin "${withToken}"
|
||||
else
|
||||
echo "No OAuth token found"
|
||||
git remote set-url --push origin `git config remote.origin.url | sed -e 's/^git:/https:/'`
|
||||
"${GIT_BIN}" remote set-url --push origin "$( "${GIT_BIN}" config remote.origin.url | sed -e 's/^git:/https:/' )"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if gh-pages exists and docs have been built
|
||||
function check_if_anything_to_sync() {
|
||||
add_oauth_token_to_remote_url
|
||||
if ! (git remote set-branches --add origin gh-pages && git fetch -q) && [[ "${RELEASE_TRAIN}" != "yes" ]] ; then
|
||||
if ! ("${GIT_BIN}" remote set-branches --add origin gh-pages && "${GIT_BIN}" fetch -q) && [[ "${RELEASE_TRAIN}" != "yes" ]] ; then
|
||||
echo "No gh-pages, so not syncing"
|
||||
exit 0
|
||||
fi
|
||||
@@ -66,19 +72,20 @@ function retrieve_current_branch() {
|
||||
# If there is a branch already passed will reuse it - otherwise will try to find it
|
||||
CURRENT_BRANCH=${BRANCH}
|
||||
if [[ -z "${CURRENT_BRANCH}" ]] ; then
|
||||
CURRENT_BRANCH=$(git symbolic-ref -q HEAD)
|
||||
CURRENT_BRANCH=$("${GIT_BIN}" symbolic-ref -q HEAD)
|
||||
CURRENT_BRANCH=${CURRENT_BRANCH##refs/heads/}
|
||||
CURRENT_BRANCH=${CURRENT_BRANCH:-HEAD}
|
||||
fi
|
||||
echo "Current branch is [${CURRENT_BRANCH}]"
|
||||
git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script"
|
||||
PREVIOUS_BRANCH=${CURRENT_BRANCH}
|
||||
"${GIT_BIN}" checkout "${CURRENT_BRANCH}" || echo "Failed to check the branch... continuing with the script"
|
||||
PREVIOUS_BRANCH="${CURRENT_BRANCH}"
|
||||
echo "Previous branch was [${PREVIOUS_BRANCH}]"
|
||||
}
|
||||
|
||||
# Switches to the provided value of the release version. We always prefix it with `v`
|
||||
function switch_to_tag() {
|
||||
if [[ "${RELEASE_TRAIN}" != "yes" ]] ; then
|
||||
git checkout v${VERSION}
|
||||
"${GIT_BIN}" checkout v"${VERSION}"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -91,6 +98,7 @@ function build_docs_if_applicable() {
|
||||
|
||||
# Get the name of the `docs.main` property
|
||||
# Get whitelisted branches - assumes that a `docs` module is available under `docs` profile
|
||||
# shellcheck disable=SC2016
|
||||
function retrieve_doc_properties() {
|
||||
MAIN_ADOC_VALUE=$("${MAVEN_EXEC}" -q \
|
||||
-Dexec.executable="echo" \
|
||||
@@ -113,47 +121,52 @@ function retrieve_doc_properties() {
|
||||
|
||||
# Stash any outstanding changes
|
||||
function stash_changes() {
|
||||
git diff-index --quiet HEAD && dirty=$? || (echo "Failed to check if the current repo is dirty. Assuming that it is." && dirty="1")
|
||||
if [ "$dirty" != "0" ]; then git stash; fi
|
||||
local success="false"
|
||||
"${GIT_BIN}" diff-index --quiet HEAD && dirty=$? && success="true"
|
||||
if [[ "${success}" == "false" ]]; then
|
||||
echo "Failed to check if the current repo is dirty. Assuming that it is." && dirty="1"
|
||||
fi
|
||||
echo "The repo is dirty [${dirty}]"
|
||||
if [ "$dirty" != "0" ]; then "${GIT_BIN}" stash; fi
|
||||
}
|
||||
|
||||
# Switch to gh-pages branch to sync it with current branch
|
||||
function add_docs_from_target() {
|
||||
local DESTINATION_REPO_FOLDER
|
||||
if [[ -z "${DESTINATION}" && -z "${CLONE}" ]] ; then
|
||||
DESTINATION_REPO_FOLDER=${ROOT_FOLDER}
|
||||
DESTINATION_REPO_FOLDER="${ROOT_FOLDER}"
|
||||
elif [[ "${CLONE}" == "yes" ]]; then
|
||||
mkdir -p ${ROOT_FOLDER}/target
|
||||
local clonedStatic=${ROOT_FOLDER}/target/spring-cloud-static
|
||||
mkdir -p "${ROOT_FOLDER}"/target
|
||||
local clonedStatic="${ROOT_FOLDER}"/target/spring-cloud-static
|
||||
if [[ ! -e "${clonedStatic}/.git" ]]; then
|
||||
echo "Cloning Spring Cloud Static to target"
|
||||
git clone ${SPRING_CLOUD_STATIC_REPO} ${clonedStatic} && cd ${clonedStatic} && git checkout gh-pages
|
||||
"${GIT_BIN}" clone "${SPRING_CLOUD_STATIC_REPO}" "${clonedStatic}" && cd "${clonedStatic}" && "${GIT_BIN}" checkout gh-pages
|
||||
else
|
||||
echo "Spring Cloud Static already cloned - will pull changes"
|
||||
cd ${clonedStatic} && git checkout gh-pages && git pull origin gh-pages
|
||||
cd "${clonedStatic}" && "${GIT_BIN}" checkout gh-pages && "${GIT_BIN}" pull origin gh-pages
|
||||
fi
|
||||
if [[ -z "${RELEASE_TRAIN}" ]] ; then
|
||||
DESTINATION_REPO_FOLDER=${clonedStatic}/${REPO_NAME}
|
||||
DESTINATION_REPO_FOLDER="${clonedStatic}/${REPO_NAME}"
|
||||
else
|
||||
DESTINATION_REPO_FOLDER=${clonedStatic}
|
||||
DESTINATION_REPO_FOLDER="${clonedStatic}"
|
||||
fi
|
||||
mkdir -p ${DESTINATION_REPO_FOLDER}
|
||||
mkdir -p "${DESTINATION_REPO_FOLDER}"
|
||||
else
|
||||
if [[ ! -e "${DESTINATION}/.git" ]]; then
|
||||
echo "[${DESTINATION}] is not a git repository"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "${RELEASE_TRAIN}" ]] ; then
|
||||
DESTINATION_REPO_FOLDER=${DESTINATION}/${REPO_NAME}
|
||||
DESTINATION_REPO_FOLDER="${DESTINATION}/${REPO_NAME}"
|
||||
else
|
||||
DESTINATION_REPO_FOLDER=${DESTINATION}
|
||||
DESTINATION_REPO_FOLDER="${DESTINATION}"
|
||||
fi
|
||||
mkdir -p ${DESTINATION_REPO_FOLDER}
|
||||
mkdir -p "${DESTINATION_REPO_FOLDER}"
|
||||
echo "Destination was provided [${DESTINATION}]"
|
||||
fi
|
||||
cd ${DESTINATION_REPO_FOLDER}
|
||||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
cd "${DESTINATION_REPO_FOLDER}"
|
||||
"${GIT_BIN}" checkout gh-pages
|
||||
"${GIT_BIN}" pull origin gh-pages
|
||||
|
||||
# Add git branches
|
||||
###################################################################
|
||||
@@ -172,32 +185,33 @@ function copy_docs_for_current_version() {
|
||||
echo -e "Current branch is master - will copy the current docs only to the root folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
if ! "${GIT_BIN}" ls-files -i -o --exclude-standard --directory | grep -q ^"${file}"$; then
|
||||
# Not ignored...
|
||||
cp -rf $f ${ROOT_FOLDER}/
|
||||
cp -rf "${f}" "${ROOT_FOLDER}"/
|
||||
fi
|
||||
done
|
||||
git add -A ${ROOT_FOLDER}
|
||||
"${GIT_BIN}" add -A "${ROOT_FOLDER}"
|
||||
COMMIT_CHANGES="yes"
|
||||
else
|
||||
echo -e "Current branch is [${CURRENT_BRANCH}]"
|
||||
# https://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin
|
||||
if [[ ",${WHITELISTED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then
|
||||
mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||
mkdir -p "${ROOT_FOLDER}/${CURRENT_BRANCH}"
|
||||
echo -e "Branch [${CURRENT_BRANCH}] is whitelisted! Will copy the current docs to the [${CURRENT_BRANCH}] folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
file="${f#docs/target/generated-docs/*}"
|
||||
if ! "${GIT_BIN}" ls-files -i -o --exclude-standard --directory | grep -q ^"${file}"$; then
|
||||
echo "The file [${file}] shouldn't be ignored"
|
||||
# Not ignored...
|
||||
# We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html
|
||||
if [[ "${file}" == "${MAIN_ADOC_VALUE}.html" ]] ; then
|
||||
# We don't want to copy the spring-cloud-sleuth.html
|
||||
# we want it to be converted to index.html
|
||||
cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html
|
||||
git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html
|
||||
cp -rf "${f}" "${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html"
|
||||
"${GIT_BIN}" add -A "${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html"
|
||||
else
|
||||
cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||
git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/$file || echo "Failed to add the file [$file]"
|
||||
cp -rf "${f}" "${ROOT_FOLDER}/${CURRENT_BRANCH}"
|
||||
"${GIT_BIN}" add -A "${ROOT_FOLDER}/${CURRENT_BRANCH}/${file}" || echo "Failed to add the file [${file}]"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@@ -211,12 +225,12 @@ function copy_docs_for_current_version() {
|
||||
|
||||
# Copies the docs by using the explicitly provided version
|
||||
function copy_docs_for_provided_version() {
|
||||
local FOLDER=${DESTINATION_REPO_FOLDER}/${VERSION}
|
||||
mkdir -p ${FOLDER}
|
||||
local FOLDER="${DESTINATION_REPO_FOLDER}/${VERSION}"
|
||||
mkdir -p "${FOLDER}"
|
||||
echo -e "Current tag is [v${VERSION}] Will copy the current docs to the [${FOLDER}] folder"
|
||||
for f in ${ROOT_FOLDER}/docs/target/generated-docs/*; do
|
||||
file=${f#${ROOT_FOLDER}/docs/target/generated-docs/*}
|
||||
copy_docs_for_branch ${file} ${FOLDER}
|
||||
for f in "${ROOT_FOLDER}"/docs/target/generated-docs/*; do
|
||||
file="${f#${ROOT_FOLDER}/docs/target/generated-docs/*}"
|
||||
copy_docs_for_branch "${file}" "${FOLDER}"
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
CURRENT_BRANCH="v${VERSION}"
|
||||
@@ -227,26 +241,27 @@ function copy_docs_for_provided_version() {
|
||||
# $1 - file from target
|
||||
# $2 - destination to which copy the files
|
||||
function copy_docs_for_branch() {
|
||||
local file=$1
|
||||
local destination=$2
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^${file}$; then
|
||||
local file="$1"
|
||||
local destination="$2"
|
||||
echo "Copying file [${file}] to destination [${destination}]"
|
||||
if ! "${GIT_BIN}" ls-files -i -o --exclude-standard --directory | grep -q ^"${file}"$; then
|
||||
# Not ignored...
|
||||
# We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html
|
||||
if [[ ("${file}" == "${MAIN_ADOC_VALUE}.html") || ("${file}" == "${REPO_NAME}.html") ]] ; then
|
||||
# We don't want to copy the spring-cloud-sleuth.html
|
||||
# we want it to be converted to index.html
|
||||
cp -rf $f ${destination}/index.html
|
||||
cp -rf "${f}" "${destination}"/index.html
|
||||
else
|
||||
cp -rf $f ${destination}
|
||||
cp -rf "${f}" "${destination}"
|
||||
fi
|
||||
git add -A ${destination}
|
||||
"${GIT_BIN}" add -A "${destination}"
|
||||
fi
|
||||
}
|
||||
|
||||
function commit_changes_if_applicable() {
|
||||
if [[ "${COMMIT_CHANGES}" == "yes" ]] ; then
|
||||
COMMIT_SUCCESSFUL="no"
|
||||
git commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes"
|
||||
"${GIT_BIN}" commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes"
|
||||
|
||||
# Uncomment the following push if you want to auto push to
|
||||
# the gh-pages branch whenever you commit to master locally.
|
||||
@@ -254,7 +269,7 @@ function commit_changes_if_applicable() {
|
||||
###################################################################
|
||||
if [[ "${COMMIT_SUCCESSFUL}" == "yes" ]] ; then
|
||||
add_oauth_token_to_remote_url
|
||||
git push origin gh-pages
|
||||
"${GIT_BIN}" push origin gh-pages
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -262,10 +277,10 @@ function commit_changes_if_applicable() {
|
||||
# Switch back to the previous branch and exit block
|
||||
function checkout_previous_branch() {
|
||||
# If -version was provided we need to come back to root project
|
||||
cd ${ROOT_FOLDER}
|
||||
git checkout ${PREVIOUS_BRANCH} || echo "Failed to check the branch... continuing with the script"
|
||||
if [ "$dirty" != "0" ]; then git stash pop; fi
|
||||
exit 0
|
||||
cd "${ROOT_FOLDER}"
|
||||
"${GIT_BIN}" checkout "${PREVIOUS_BRANCH}" || echo "Failed to check the branch... continuing with the script"
|
||||
if [ "$dirty" != "0" ]; then "${GIT_BIN}" stash pop; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Assert if properties have been properly passed
|
||||
@@ -322,53 +337,58 @@ EOF
|
||||
#
|
||||
# ==========================================
|
||||
|
||||
while [[ $# > 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case ${key} in
|
||||
-v|--version)
|
||||
VERSION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-r|--releasetrain)
|
||||
RELEASE_TRAIN="yes"
|
||||
;;
|
||||
-d|--destination)
|
||||
DESTINATION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-b|--build)
|
||||
BUILD="yes"
|
||||
;;
|
||||
-c|--clone)
|
||||
CLONE="yes"
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: [$1]"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
assert_properties
|
||||
set_default_props
|
||||
check_if_anything_to_sync
|
||||
retrieve_current_branch
|
||||
if echo $VERSION | egrep -q 'SNAPSHOT' || [[ -z "${VERSION}" ]]; then
|
||||
CLONE=""
|
||||
VERSION=""
|
||||
echo "You've provided a version variable but it's a snapshot one. Due to this will not clone spring-cloud-static and publish docs over there"
|
||||
if [[ "${SOURCE_FUNCTIONS}" == "true" ]]; then
|
||||
echo "Will just source functions. Will not run any commands"
|
||||
else
|
||||
switch_to_tag
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case "${key}" in
|
||||
-v|--version)
|
||||
VERSION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-r|--releasetrain)
|
||||
RELEASE_TRAIN="yes"
|
||||
;;
|
||||
-d|--destination)
|
||||
DESTINATION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-b|--build)
|
||||
BUILD="yes"
|
||||
;;
|
||||
-c|--clone)
|
||||
CLONE="yes"
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: [$1]"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
assert_properties
|
||||
set_default_props
|
||||
check_if_anything_to_sync
|
||||
retrieve_current_branch
|
||||
if echo "${VERSION}" | grep -q -E 'SNAPSHOT' || [[ -z "${VERSION}" ]]; then
|
||||
CLONE=""
|
||||
VERSION=""
|
||||
echo "You've provided a version variable but it's a snapshot one. Due to this will not clone spring-cloud-static and publish docs over there"
|
||||
else
|
||||
switch_to_tag
|
||||
fi
|
||||
build_docs_if_applicable
|
||||
retrieve_doc_properties
|
||||
stash_changes
|
||||
add_docs_from_target
|
||||
checkout_previous_branch
|
||||
fi
|
||||
build_docs_if_applicable
|
||||
retrieve_doc_properties
|
||||
stash_changes
|
||||
add_docs_from_target
|
||||
checkout_previous_branch
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Either clones or pulls the repo for given project
|
||||
# Params:
|
||||
# $1 organization e.g. spring-cloud
|
||||
# $2 repo name e.g. spring-cloud-sleuth
|
||||
function clone_or_pull() {
|
||||
if [ "$#" -ne 2 ]
|
||||
then
|
||||
echo "You haven't provided 2 args... \$1 organization e.g. spring-cloud; \$2 repo name e.g. spring-cloud-sleuth"
|
||||
exit 1
|
||||
fi
|
||||
if [[ "${JUST_PUSH}" == "yes" ]] ; then
|
||||
echo "Skipping cloning since the option to just push was provided"
|
||||
exit 0
|
||||
fi
|
||||
local ORGANIZATION=$1
|
||||
local REPO_NAME=$2
|
||||
local LOCALREPO_VC_DIR=${REPO_NAME}/.git
|
||||
if [ ! -d ${LOCALREPO_VC_DIR} ]
|
||||
then
|
||||
echo "Repo [${REPO_NAME}] doesn't exist - will clone it!"
|
||||
git clone git@github.com:${ORGANIZATION}/${REPO_NAME}.git
|
||||
else
|
||||
echo "Repo [${REPO_NAME}] exists - will pull the changes"
|
||||
cd ${REPO_NAME} && git pull || echo "Not pulling since repo is up to date"
|
||||
cd ${ROOT_FOLDER}
|
||||
fi
|
||||
}
|
||||
|
||||
# For the given branch updates the docs/src/main/asciidoc/ghpages.sh
|
||||
# with the one from spring-cloud-build. Then commits and pushes the change
|
||||
# Params:
|
||||
# $1 repo name e.g. spring-cloud-sleuth
|
||||
# $2 branch name
|
||||
function update_ghpages_script() {
|
||||
if [ "$#" -ne 2 ]
|
||||
then
|
||||
echo "You haven't provided 2 args... \$1 repo name e.g. spring-cloud-sleuth; \$2 branch name e.g. master"
|
||||
exit 1
|
||||
fi
|
||||
local REPO_NAME=$1
|
||||
local BRANCH_NAME=$2
|
||||
echo "Updating ghpages script for [${REPO_NAME}] and branch [${BRANCH_NAME}]"
|
||||
cd ${REPO_NAME}
|
||||
echo "Checking out [${BRANCH_NAME}]"
|
||||
git checkout ${BRANCH_NAME}
|
||||
echo "Resetting the repo and pulling before commiting"
|
||||
git reset --hard origin/${BRANCH_NAME} && git pull origin ${BRANCH_NAME}
|
||||
# If the user wants to just push we will not copy / add / commit files
|
||||
if [[ "${JUST_PUSH}" != "yes" ]] ; then
|
||||
echo "Copying [${GHPAGES_DOWNLOAD_PATH}] to [${GHPAGES_IN_REPO_PATH}]"
|
||||
cp -rf ${GHPAGES_DOWNLOAD_PATH} ${GHPAGES_IN_REPO_PATH}
|
||||
echo "Adding and committing [${GHPAGES_IN_REPO_PATH}] with message [${COMMIT_MESSAGE}]"
|
||||
git add ${GHPAGES_IN_REPO_PATH}
|
||||
git commit -m "${COMMIT_MESSAGE}" || echo "Proceeding to the next repo"
|
||||
fi
|
||||
if [[ "${AUTO_PUSH}" == "yes" ]] ; then
|
||||
echo "Pushing the branch [${BRANCH_NAME}]"
|
||||
wait_if_manual_proceed
|
||||
git push origin ${BRANCH_NAME}
|
||||
fi
|
||||
cd ${ROOT_FOLDER}
|
||||
}
|
||||
|
||||
# Downloads ghpages.sh
|
||||
function download_ghpages() {
|
||||
rm -rf ${GHPAGES_DOWNLOAD_PATH}
|
||||
echo "Downloading ghpages.sh from [${GHPAGES_URL}] to [${GHPAGES_DOWNLOAD_PATH}]"
|
||||
curl ${GHPAGES_URL} -o ${GHPAGES_DOWNLOAD_PATH}
|
||||
chmod +x ${GHPAGES_DOWNLOAD_PATH}
|
||||
}
|
||||
|
||||
# Either clones or pulls the repo for given project and then updates gh-pages for the given project
|
||||
# Params:
|
||||
# $1 organization e.g. spring-cloud
|
||||
# $2 repo name e.g. spring-cloud-sleuth
|
||||
# $3 branch name e.g. master
|
||||
function clone_and_update_ghpages() {
|
||||
if [ "$#" -ne 3 ]
|
||||
then
|
||||
echo "You haven't provided 3 args... \$1 organization e.g. spring-cloud; \$2 repo name e.g. spring-cloud-sleuth; \$3 branch name e.g. master"
|
||||
exit 1
|
||||
fi
|
||||
local ORGANIZATION=$1
|
||||
local REPO_NAME=$2
|
||||
local BRANCH_NAME=$3
|
||||
local VAR
|
||||
echo -e "\n\nWill clone the repo and update scripts for org [${ORGANIZATION}], repo [${REPO_NAME}] and branch [${BRANCH_NAME}]\n\n"
|
||||
clone_or_pull ${ORGANIZATION} ${REPO_NAME}
|
||||
update_ghpages_script ${REPO_NAME} ${BRANCH_NAME}
|
||||
echo "Proceeding to next project"
|
||||
wait_if_manual_proceed
|
||||
}
|
||||
|
||||
function wait_if_manual_proceed() {
|
||||
if [[ "${AUTO_PROCEED}" != "yes" ]] ; then
|
||||
echo -n "Press [ENTER] to continue..."
|
||||
read VAR
|
||||
fi
|
||||
}
|
||||
|
||||
# Prints the provided parameters
|
||||
function print_parameters() {
|
||||
cat <<EOF
|
||||
Running the script with the following parameters
|
||||
GHPAGES_URL=${GHPAGES_URL}
|
||||
GHPAGES_DOWNLOAD_PATH=${GHPAGES_DOWNLOAD_PATH}
|
||||
COMMIT_MESSAGE=${COMMIT_MESSAGE}
|
||||
GHPAGES_IN_REPO_PATH=${GHPAGES_IN_REPO_PATH}
|
||||
AUTO_PROCEED=${AUTO_PROCEED}
|
||||
AUTO_PUSH=${AUTO_PUSH}
|
||||
JUST_PUSH=${JUST_PUSH}
|
||||
ROOT_FOLDER=${ROOT_FOLDER}
|
||||
EOF
|
||||
}
|
||||
|
||||
# Prints the usage
|
||||
function print_usage() {
|
||||
cat <<EOF
|
||||
The idea of this script is to batch update all ghpages scripts for all projects that we have in Spring Cloud.
|
||||
If you don't provide any options by default the script will copy the latest ghpages.sh, commit it for each repo
|
||||
and then push it to the appropriate branch.
|
||||
|
||||
USAGE:
|
||||
|
||||
You can use the following options:
|
||||
|
||||
-p|--nopush - the script will not push the changes
|
||||
-m|--manualproceed - if you want to do a manual proceed after every step
|
||||
-x|--justpush - if you want to go to every single repo and just push the changes
|
||||
-h|--help - present this help message
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# ____ ____ _____ _____ _____ _______
|
||||
# / ____|/ ____| __ \|_ _| __ \__ __|
|
||||
# | (___ | | | |__) | | | | |__) | | |
|
||||
# \___ \| | | _ / | | | ___/ | |
|
||||
# ____) | |____| | \ \ _| |_| | | |
|
||||
# |_____/ \_____|_| \_\_____|_| |_|
|
||||
#
|
||||
# ==========================================
|
||||
|
||||
while [[ $# > 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case ${key} in
|
||||
-p|--nopush)
|
||||
AUTO_PUSH="no"
|
||||
;;
|
||||
-m|--manualproceed)
|
||||
AUTO_PROCEED="no"
|
||||
;;
|
||||
-x|--justpush)
|
||||
JUST_PUSH="yes"
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: [$1]"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
export GHPAGES_URL=${GHPAGES_URL:-https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/ghpages.sh}
|
||||
export GHPAGES_DOWNLOAD_PATH=${GHPAGES_DOWNLOAD_PATH:-/tmp/ghpages.sh}
|
||||
export COMMIT_MESSAGE=${COMMIT_MESSAGE:-Updating ghpages for all projects}
|
||||
export GHPAGES_IN_REPO_PATH=${GHPAGES_IN_REPO_PATH:-docs/src/main/asciidoc/ghpages.sh}
|
||||
export AUTO_PROCEED=${AUTO_PROCEED:-yes}
|
||||
export AUTO_PUSH=${AUTO_PUSH:-yes}
|
||||
export JUST_PUSH=${JUST_PUSH:-no}
|
||||
export ROOT_FOLDER=`pwd`
|
||||
|
||||
|
||||
print_parameters
|
||||
download_ghpages
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-aws master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-aws 1.0.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-aws 1.2.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-bus master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-cli 1.0.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-cli 1.1.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-cli master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-cloudfoundry master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-cluster master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-commons master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-config master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-config 1.1.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-consul 1.0.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-consul master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-contract master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-netflix 1.0.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-netflix 1.1.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-netflix master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-security master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-sleuth 1.0.x
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-sleuth master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-starters Brixton
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-starters master
|
||||
clone_and_update_ghpages spring-cloud-incubator spring-cloud-vault-config master
|
||||
clone_and_update_ghpages spring-cloud spring-cloud-zookeeper master
|
||||
Reference in New Issue
Block a user