pyblocks/pbt.sh

101 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/bash
job_start=0
job_start() {
# [*] job start - [target]:[job]
# bold
echo -e "\e[1m[*] job start - $1:$2\e[0m"
job_start=$(date +%s)
}
job_success() {
# [*] success! [target]:[job] finished in 241.2s :)
end=$(date +%s)
time=$(( end - job_start ))
echo -e "\e[1m\e[32m[*] success! $1:$2 finished in $time seconds :)\e[0m"
}
job_fail() {
# [x] FAIL! [target]:[job] failed in 241.2s :(
end=$(date +%s)
time=$(( end - job_start ))
echo -e "\e[1m\e[31m[*] FAIL! $1:$2 failed in $time seconds :(\e[0m"
}
sub_clone() {
job_start "scratch-blocks" "clone"
git submodule init
if [ "$?" != "0" ]; then
job_fail "scratch-blocks" "clone"
exit 1
fi
git submodule update
if [ "$?" != "0" ]; then
job_fail "scratch-blocks" "clone"
exit 1
fi
job_success "scratch-blocks" "clone"
}
sub_patch() {
sub_clone
job_start "scratch-blocks" "patch"
cd scratch-blocks || exit
git am --abort >/dev/null 2>&1
git am --3way "../patches/scratch-blocks/"*.patch
if [ "$?" != "0" ]; then
echo "One or more patches did not apply cleanly to scratch-blocks. Check above message and try again".
job_fail "scratch-blocks" "patch"
exit 1
fi
echo "[*] Patches applied cleanly to scratch-blocks"
job_success "scratch-blocks" "patch"
}
sub_compile() {
sub_patch
job_start "scratch-blocks" "compile"
NODE_OPTIONS=--openssl-legacy-provider npm i
if [ "$?" != "0" ]; then
job_fail "scratch-blocks" "compile"
exit 1
fi
job_success "scratch-blocks" "compile"
}
sub_help() {
echo "clone - clone upstream source code"
echo "patch - apply patches"
echo "compile - compile bundles"
echo "bundle - create prod bundles"
}
subcommand=$1
case $subcommand in
"" | "-h" | "--help" | "help")
sub_help
;;
*)
echo "[*] Running build command $subcommand"
shift
sub_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo " Run 'pbt.sh --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac