Skip to content

Instantly share code, notes, and snippets.

@Potherca Potherca/README.md
Last active Aug 11, 2019

Embed
What would you like to do?
Scripts to check for (and execute) updates to the `plantuml-stdlib` codebase

The PlantUML Standard Library makes it possible to use popular icons in PlantUML with zero effort.

The plantuml-stdlib code as based on other projects.

As there were changes in some of those repos that were not (yet) in plantuml-stdlib, I decided to open some merge-requests to update things.

Because I don't like to do thnings manually that could be automated, I spend some time creating two BASH scripts:

The first script checks if there are updates for the libraries in the plantuml-stdlib codebase. The second updates all the libraries in the plantuml-stdlib codebase.

check-sources-for-update.sh

To use this script, make sure there is an up-to-date version of the plantuml-stdlib git repository locally.

Then point the script to the plantuml-stdlib code base:

bash ./check-sources-for-update.sh /path/to/plantuml-stdlib/

This will then output whether each project has an update available or not.

screenshot-check-sources-for-update

update_sources.sh

To use this script, make sure there is an up-to-date version of the plantuml-stdlib git repository locally.

The sources.config file is also needed.

Next point the script to the plantuml-stdlib code base:

bash ./update_sources.sh /path/to/plantuml-stdlib/ /path/to/repos/ /path/to/sources.config

This will then checkout or update all the other project git repositories and copy all the relevant files from those projects into the plantuml-stdlib code base. It does this based on information from the config file.

screenshot-update_sources

The changes in plantuml-stdlib can then be seen using git status, added using git add. comitted with git commit, etc.

#!/usr/bin/env bash
set -o errexit -o errtrace -o nounset -o pipefail
# ==============================================================================
: readonly "${RESET_TEXT:=$(tput sgr0)}" # turn off all attributes
# ------------------------------------------------------------------------------
# Foreground colors
# ------------------------------------------------------------------------------
: readonly "${COLOR_BLUE:=$(tput setaf 4)}"
: readonly "${COLOR_GREEN:=$(tput setaf 2)}"
: readonly "${COLOR_RED:=$(tput setaf 1)}"
: readonly "${COLOR_WHITE:=$(tput setaf 7)}"
: readonly "${COLOR_YELLOW:=$(tput setaf 3)}"
# ------------------------------------------------------------------------------
# Text attributes
# ------------------------------------------------------------------------------
: readonly "${TEXT_BOLD:=$(tput bold)}" # turn on bold (extra bright) mode
: readonly "${TEXT_INVERSE:=$(tput rev)}" # turn on color inverse mode
# ------------------------------------------------------------------------------
# Text output channels
# ------------------------------------------------------------------------------
: "${ERROR_OUTPUT:=/dev/stderr}"
: "${NORMAL_OUTPUT:=/dev/stdout}"
: "${SILENCE_OUTPUT:=/dev/null}"
# ==============================================================================
: "${GIT:=git}"
check_sources_for_update() {
get_local_version() {
local sContent sLocalVersion
readonly sContent="${1?One parameter required: <content>}"
sLocalVersion=$(echo "${sContent}" | grep -oE '([0-9]+\.?){3}')
if echo "${sLocalVersion}" | grep --quiet '\.0[0-9]';then
# Remove unneeded leading zero
sLocalVersion="$(echo "${sLocalVersion}" | tr '.' "\n" | bc | tr "\n" '.')"
sLocalVersion="${sLocalVersion:0:-1}"
fi
echo "${sLocalVersion}"
}
get_version_from_remote_git() {
local sProject sRemoteVersion
readonly sProject="${1?One parameter required: <github-project>}"
readonly sRemoteVersion="$("${GIT}" ls-remote --tags "git://github.com/${sProject}.git" \
| cut -d'/' -f3 \
| grep -E '^v?[0-9.]+$' \
| grep -oE '[0-9.]+' \
| sort -V \
| tail -n1)" || true
echo "${sRemoteVersion}"
}
compare_versions() {
local sLocalVersion sRemoteVersion sResponse
readonly sLocalVersion="${1?Two parameters required: <local-version> <remote-version>}"
sRemoteVersion="${2?Two parameters required: <local-version> <remote-version>}"
if [[ "${sLocalVersion}" == "" ]] || [[ "${sRemoteVersion}" == "" ]];then
readonly sResponse="${COLOR_RED}No version infromation available${RESET_TEXT}"
else
if echo "${sRemoteVersion}" | grep --quiet -E '^[0-9]+\.[0-9]+$';then
# Pad "x.y" format to "x.y.z" format
sRemoteVersion="${sRemoteVersion}.0"
fi
if [[ "$(echo -e "${sRemoteVersion}\n${sLocalVersion}" | sort -V | tail -n 1)" == "${sLocalVersion}" ]];then
readonly sResponse="${COLOR_GREEN}Up To Date${RESET_TEXT}"
else
readonly sResponse="${COLOR_YELLOW}Newer version available ${TEXT_INVERSE} ${sRemoteVersion} ${RESET_TEXT}"
fi
fi
echo "${sResponse}"
}
get_project_name_from_github_url() {
local sContent sProject sUrl
readonly sContent="${1?One parameter required: <content>}"
readonly sUrl=$(echo "${sContent}" | grep -oE 'https?://.*')
readonly sProject="$(echo "${sUrl}" | rev | grep -oE '[^/]+/[^/]+' | rev)"
echo "${sProject}"
}
check_source_for_update() {
local sContent sLocalVersion sProject sRemoteVersion
readonly sContent="${1?One parameter required: <content>}"
readonly sLocalVersion="$(get_local_version "${sContent}")"
readonly sProject="$(get_project_name_from_github_url "${sContent}")"
echo -n "${RESET_TEXT} =====> ${TEXT_BOLD}${sProject}${RESET_TEXT} (${COLOR_BLUE}${sLocalVersion}${RESET_TEXT})"
readonly sRemoteVersion="$(get_version_from_remote_git "${sProject}")"
echo " $(compare_versions "${sLocalVersion}" "${sRemoteVersion}")"
}
run() {
local sSourcesFile sSourcePaths
sSourcePaths="${1?One parameter required: <sources-path>}"
for sSourcesFile in "${sSourcePaths}/"*'/INFO';do
check_source_for_update "$(cat "${sSourcesFile}")"
done;
# @TODO: Move this to an exit trap, so we don't fuck up the terminal when a user aborts
echo -n "${RESET_TEXT}"
}
run "${@}"
}
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f check_sources_for_update
else
check_sources_for_update "${@}"
exit $?
fi
aws /dist/
awslib /dist/
azure /dist/
C4 /
cloudinsight /sprites/
cloudogu /
office /office2014/
tupadr3 /
#!/usr/bin/env bash
set -o errexit -o errtrace -o nounset -o pipefail
update_sources() {
get_project_name_from_github_url() {
local sContent sProject sUrl
readonly sContent="${1?One parameter required: <content>}"
readonly sUrl=$(echo "${sContent}" | grep -oE 'https?://.*')
readonly sProject="$(echo "${sUrl}" | rev | grep -oE '[^/]+/[^/]+' | rev)"
echo "${sProject}"
}
update_source() {
local iLength sConfig sPath sProject sSourceFile sSourcePath sTargetFile sTargetPath
readonly sProject="${1?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
readonly sTargetPath="${2?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
readonly sSourcePath="${3?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
readonly sPath="${4?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
readonly sConfig="${5?Five parameters required: <project> <target-path> <source-path> <path> <config>}"
echo -e "\n =====> Updating ${sProject} (${sPath})"
if [[ ! -d "${sSourcePath}/${sPath}" ]];then
echo ' -----> Creating git clone'
git clone "git://github.com/${sProject}.git" "${sSourcePath}/${sPath}"
else
echo ' -----> Git clone exists, pull latest changes'
git --git-dir="${sSourcePath}/${sPath}/.git" --work-tree="${sSourcePath}/${sPath}" pull
fi
echo ' -----> Looking up config'
sSource="$(echo "${sConfig}" | grep "\b${sPath}\b" | tr -d ' ')" || true
if [[ "${sSource}" == '' ]];then
echo -e "\tNo config vailable. Skipping"
else
readonly iLength=$(( "${#sSourcePath} + ${#sSource}" + 1))
echo ' -----> Copying "*.puml" files'
find "${sSourcePath}/${sSource}" -name '*.puml' -print0 |
while read -r -d $'\0' sFilePath; do
sSourceFile="${sSourcePath}/${sSource}${sFilePath:${iLength}}"
sTargetFile="${sTargetPath}/${sPath}/${sFilePath:${iLength}}"
sTargetFolder="$(dirname "${sTargetFile}")"
if [[ ! -d "${sTargetFolder}" ]];then
mkdir -p "${sTargetFolder}"
fi
cp "${sSourceFile}" "${sTargetFile}"
done
fi
}
run() {
local sConfigFile sContent sFolder sPath sProject sSourcesFile sSourcePath sTargetPath
readonly sTargetPath="${1?Three parameters required: <target-path> <source-path> <config-file>}"
readonly sSourcePath="${2?Three parameters required: <target-path> <source-path> <config-file>}"
readonly sConfigFile="${3?Three parameters required: <target-path> <source-path> <config-file>}"
for sSourcesFile in "${sTargetPath}/"*'/INFO';do
sPath="$(dirname "${sSourcesFile}")"
sFolder="$(basename "${sPath}")"
sContent="$(cat "${sSourcesFile}")"
sProject="$(get_project_name_from_github_url "${sContent}")"
update_source \
"${sProject}" \
"$(realpath "${sTargetPath}")" \
"$(realpath "${sSourcePath}")" \
"${sFolder}" \
"$(cat "${sConfigFile}")"
done;
# Cleanup
rm -rf "${sTargetPath}/C4/samples/" "${sTargetPath}/tupadr3/examples/"
}
run "${@}"
}
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f update_sources
else
update_sources "${@}"
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.