mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 21:57:17 +00:00
128 lines
3.8 KiB
Bash
128 lines
3.8 KiB
Bash
# Requires context:
|
|
# - BASEIMAGE_PATH: absolute path of baseimage repo
|
|
# - BASEIMAGE_REPO: basename of baseimage repo
|
|
|
|
BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}"
|
|
|
|
libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
|
source "${libhack_dir}/common.sh"
|
|
|
|
|
|
baseimage::build_as_latest() {
|
|
pushd "${BASEIMAGE_PATH}"
|
|
baseimage::build
|
|
baseimage::tag_as_latest
|
|
popd
|
|
}
|
|
|
|
baseimage::build() {
|
|
pushd "${BASEIMAGE_PATH}"
|
|
docker build -t "${BASEIMAGE_NAME}:$(releasename)" \
|
|
.
|
|
popd
|
|
}
|
|
|
|
baseimage::build_if_exists() {
|
|
if [[ -d "$BASEIMAGE_PATH" ]]; then
|
|
baseimage::build_as_latest
|
|
fi
|
|
}
|
|
|
|
baseimage::tag_as_latest() {
|
|
docker tag "${BASEIMAGE_NAME}:$(releasename)" "${BASEIMAGE_NAME}:latest"
|
|
}
|
|
|
|
baseimage::release() {
|
|
pushd "${BASEIMAGE_PATH}"
|
|
check_drone_releasename
|
|
|
|
local tag
|
|
tag="$(releasename)"
|
|
read -p "Tag and push new TFW version \"${tag}\"? [y/N]" -r && echo
|
|
if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]]; then
|
|
prompt_for_tag_description # This command sets $description
|
|
tag="${tag}" description="${description}" force_push_tag
|
|
fi
|
|
popd
|
|
}
|
|
|
|
baseimage::builddocs() {
|
|
mount_point="/mnt/docs"
|
|
|
|
docker run --rm \
|
|
-ti \
|
|
-v "${BASEIMAGE_PATH}"/docs:"${mount_point}" \
|
|
"${BASEIMAGE_NAME}" \
|
|
/bin/bash -c \
|
|
"cd ${mount_point}
|
|
pip3 install sphinx
|
|
make html
|
|
exit" \
|
|
&> /dev/null
|
|
|
|
if [ "$?" == "0" ]; then
|
|
echo "Built baseimage docs at ${BASEIMAGE_PATH}/docs/build/html!"
|
|
else
|
|
echo "Building baseimage docs failed!"
|
|
fi
|
|
}
|
|
|
|
baseimage::latest_upstream_tag() {
|
|
echo -n "$(git ls-remote --tags ${remotebase}/${BASEIMAGE_REPO}.git |
|
|
cut -f2 |
|
|
grep -oP '(?<=refs/tags/)\w+-\d{8}$' |
|
|
sort -t '-' -k2 |
|
|
tail -n 1)"
|
|
}
|
|
|
|
releasename() {
|
|
local version
|
|
local date
|
|
version="$(cat VERSION | head -n 1)"
|
|
date="$(date +%Y%m%d)"
|
|
printf "${version}-${date}"
|
|
}
|
|
|
|
check_drone_releasename() {
|
|
local drone_releasename
|
|
local actual_releasename
|
|
drone_releasename="$(grep -oP '(?<=branch:\srefs/tags/).+(?=-.+)' .drone.yml)"
|
|
actual_releasename="$(releasename | grep -oP ".+(?=-\d{8})")"
|
|
if [ "${drone_releasename}" != "${actual_releasename}" ]; then
|
|
echo "Release name '${drone_releasename}' in .drone.yml does not match \
|
|
actual release name '${actual_releasename}' in VERSION."
|
|
echo "Please make them match before releasing!"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
prompt_for_tag_description() {
|
|
local editor
|
|
local tempfile
|
|
editor="$(git config --global core.editor)"
|
|
tempfile="$(mktemp)"
|
|
|
|
printf "\n\n" >> "${tempfile}"
|
|
echo "# Please enter the description for this release." >> "${tempfile}"
|
|
echo "# Lines starting with '#' will be ignored." >> "${tempfile}"
|
|
echo "# An empty description aborts the release." >> "${tempfile}"
|
|
|
|
${editor} "${tempfile}"
|
|
sed -i -e 's/#.*$//' -e '/^$/d' "${tempfile}"
|
|
sed -i 's/\n/ /g' "${tempfile}"
|
|
if [[ ! -s "${tempfile}" ]]; then
|
|
echo "Aborting release due to empty description."
|
|
exit 1
|
|
fi
|
|
|
|
description="$(tr '\n' ' ' < "${tempfile}")"
|
|
rm "${tempfile}"
|
|
}
|
|
|
|
force_push_tag() {
|
|
git tag -d "${tag}" > /dev/null 2>&1 || :
|
|
git push --delete origin "${tag}" > /dev/null 2>&1 || :
|
|
git tag -s -m "${description}" "${tag}"
|
|
git push origin "${tag}"
|
|
}
|