Sync docs from master to gh-pages

This commit is contained in:
buildmaster
2019-04-29 14:36:30 +00:00
parent a87f39e151
commit 2823d49b3d
2 changed files with 198 additions and 0 deletions

View File

@@ -100,6 +100,7 @@ $(addBlockSwitches);
</ul>
</li>
<li><a href="#_reusing_the_documentation">Reusing the documentation</a></li>
<li><a href="#_updating_the_guides">Updating the guides</a></li>
</ul>
</div>
</div>
@@ -540,6 +541,54 @@ The order of plugin declaration is important!
</div>
</div>
</div>
<div class="sect1">
<h2 id="_updating_the_guides"><a class="link" href="#_updating_the_guides">Updating the guides</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>We assume that your project contains guides under the <code>guides</code> folder.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code>.
└── guides
├── gs-guide1
├── gs-guide2
└── gs-guide3</code></pre>
</div>
</div>
<div class="paragraph">
<p>This means that the project contains 3 guides that would
correspond to the following guides in Spring Guides org.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://github.com/spring-guides/gs-guide1" class="bare">https://github.com/spring-guides/gs-guide1</a></p>
</li>
<li>
<p><a href="https://github.com/spring-guides/gs-guide2" class="bare">https://github.com/spring-guides/gs-guide2</a></p>
</li>
<li>
<p><a href="https://github.com/spring-guides/gs-guide3" class="bare">https://github.com/spring-guides/gs-guide3</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If you deploy your project with the <code>-Pguides</code> profile like this</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code>$ ./mvnw clean deploy -Pguides</code></pre>
</div>
</div>
<div class="paragraph">
<p>what will happen is that for GA project versions, we will clone <code>gs-guide1</code>, <code>gs-guide2</code> and <code>gs-guide3</code> and update their contents with the ones being under your <code>guides</code> project.</p>
</div>
<div class="paragraph">
<p>You can skip this by either not adding the <code>guides</code> profile, or passing the <code>-DskipGuides</code> system property when the profile is turned on.</p>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/tocbot/tocbot.min.js"></script>
<script type="text/javascript" src="js/toc.js"></script>

149
update-guides.sh Normal file
View File

@@ -0,0 +1,149 @@
#!/bin/bash
set -e
GIT_BIN="${GIT_BIN:-git}"
echo "Project version is [${PROJECT_VERSION}]"
if [[ "${PROJECT_VERSION}" != *"RELEASE"* ]];then
echo "Will not update guides, since the version is not a RELEASE one"
exit 0
fi
# The script should be executed from the root folder
[[ -z "${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
fi
GUIDES_FOLDER="${ROOT_FOLDER}/guides"
SPRING_GUIDES_REPO_ROOT="${SPRING_GUIDES_REPO_ROOT:-git@github.com:spring-guides}"
echo "The Spring Guides repo root is [${SPRING_GUIDES_REPO_ROOT}]"
if [[ ! -d "${GUIDES_FOLDER}" ]]; then
echo "No [guides] folder is present. Won't do anything"
exit 0
fi
function iterate_over_guides() {
for dir in "${GUIDES_FOLDER}"/*/ # list directories in the form "/tmp/dirname/"
do
local dir="${dir%*/}" # remove the trailing "/"
local folderName="${dir##*/}" # print everything after the final "/"
if [[ "${folderName}" == "target" ]]; then
echo "Skipping [${folderName}]"
continue
fi
local guideRepo="${SPRING_GUIDES_REPO_ROOT}/${folderName}"
local clonedGuideFolderParent="${ROOT_FOLDER}/target"
local clonedGuideFolder="${clonedGuideFolderParent}/${folderName}"
echo "Will clone [${guideRepo}] project [${folderName}] to target"
mkdir -p "${clonedGuideFolder}"
rm -rf "${clonedGuideFolder}"
"${GIT_BIN}" clone "${guideRepo}" "${clonedGuideFolder}"
pushd "${clonedGuideFolder}"
echo "Will start the commit process for [${folderName}]"
add_oauth_token_to_remote_url
remove_all_files
copy_new_guide "${GUIDES_FOLDER}/${folderName}" "${clonedGuideFolderParent}"
commit_and_push_new_guide_contents
echo "Successfully copied and pushed new guides for [${guideRepo}]"
popd
done
}
function commit_and_push_new_guide_contents() {
"${GIT_BIN}" add .
"${GIT_BIN}" commit -m "Updating guides"
"${GIT_BIN}" push origin master
}
function copy_new_guide() {
local guideFolder="${1}"
local clonedGuideFolder="${2}"
echo "Will copy new guide files from [${guideFolder}/] to [${clonedGuideFolder}]"
cp -r "${guideFolder}/" "${clonedGuideFolder}/"
echo "Copied new guide files"
}
function remove_all_files() {
echo "Removing all non git files in [$( pwd )]"
"${GIT_BIN}" rm -rf "$( pwd )/"
"${GIT_BIN}" clean -fxd
echo "All files removed"
}
# Adds the oauth token if present to the remote url
function add_oauth_token_to_remote_url() {
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_BIN}" remote set-url --push origin "${withToken}"
else
echo "No OAuth token found"
"${GIT_BIN}" remote set-url --push origin "$( "${GIT_BIN}" config remote.origin.url | sed -e 's/^git:/https:/' )"
fi
}
# Prints the usage
function print_usage() {
cat <<EOF
The idea of this script is to keep the Spring guides up to date by taking the
contents of guides from the project's repository and pushing them to Spring guides
repository.
This script iterates over the contents of the [guides] folder. Each its subfolder
corresponds to a repository under the Spring Guides repository (i.e. the https://github.com/spring-guides organization).
Upon the iteration a corresponding guide repository gets cloned and updated with the latest content from the project repository. A commit and push then takes place.
USAGE:
You can use the following options:
-h|--help - display this message
EOF
}
# ==========================================
# ____ ____ _____ _____ _____ _______
# / ____|/ ____| __ \|_ _| __ \__ __|
# | (___ | | | |__) | | | | |__) | | |
# \___ \| | | _ / | | | ___/ | |
# ____) | |____| | \ \ _| |_| | | |
# |_____/ \_____|_| \_\_____|_| |_|
#
# ==========================================
if [[ "${SOURCE_FUNCTIONS}" == "true" ]]; then
echo "Will just source functions. Will not run any commands"
else
while [[ $# -gt 0 ]]
do
key="$1"
case "${key}" in
-h|--help)
print_usage
exit 0
;;
*)
echo "Invalid option: [$1]"
print_usage
exit 1
;;
esac
shift # past argument or value
done
iterate_over_guides
fi