Added automated guides updating; fixes gh-131
This commit is contained in:
@@ -82,4 +82,33 @@ approach of generating documentation just add these plugins to your `docs` modul
|
||||
<3> This plugin is required to parse the Asciidoctor documentation
|
||||
<4> This plugin is required to copy resources into proper final destinations and to generate main README.adoc and to assert that no files use unresolved links
|
||||
|
||||
IMPORTANT: The order of plugin declaration is important!
|
||||
IMPORTANT: The order of plugin declaration is important!
|
||||
|
||||
== Updating the guides
|
||||
|
||||
We assume that your project contains guides under the `guides` folder.
|
||||
|
||||
```
|
||||
.
|
||||
└── guides
|
||||
├── gs-guide1
|
||||
├── gs-guide2
|
||||
└── gs-guide3
|
||||
```
|
||||
|
||||
This means that the project contains 3 guides that would
|
||||
correspond to the following guides in Spring Guides org.
|
||||
|
||||
- https://github.com/spring-guides/gs-guide1
|
||||
- https://github.com/spring-guides/gs-guide2
|
||||
- https://github.com/spring-guides/gs-guide3
|
||||
|
||||
If you deploy your project with the `-Pguides` profile like this
|
||||
|
||||
```
|
||||
$ ./mvnw clean deploy -Pguides
|
||||
```
|
||||
|
||||
what will happen is that for GA project versions, we will clone `gs-guide1`, `gs-guide2` and `gs-guide3` and update their contents with the ones being under your `guides` project.
|
||||
|
||||
You can skip this by either not adding the `guides` profile, or passing the `-DskipGuides` system property when the profile is turned on.
|
||||
149
docs/src/main/asciidoc/update-guides.sh
Executable file
149
docs/src/main/asciidoc/update-guides.sh
Executable 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
|
||||
|
||||
Reference in New Issue
Block a user