pyblocks/pbt.sh

115 lines
2.7 KiB
Bash
Executable File

#!/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.%N)
}
job_success() {
# [*] success! [target]:[job] finished in 241.2s :)
end=$(date +%s.%N)
time=$( echo "$end - $job_start" | bc -l )
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.%N)
time=$( echo "$end - $job_start" | bc -l )
echo -e "\e[1m\e[31m[*] FAIL! $1:$2 failed in $time seconds :(\e[0m"
}
job_skip() {
# [-] skipped - [target]:[job] skipped in 241.2s
end=$(date +%s.%N)
time=$( echo "$end - $job_start" | bc -l )
echo -e "\e[1m\e[34m[-] skipped - $1:$2 skipped after $time seconds\e[0m"
}
sub_clone() {
job_start "scratch-blocks" "clone"
if [ -d "$(pwd)/scratch-blocks" ]; then
echo "Clone dir already exists"
job_skip "scratch-blocks" "clone"
else
git clone https://github.com/scratchfoundation/scratch-blocks scratch-blocks
if [ "$?" != "0" ]; then
job_fail "scratch-blocks" "clone"
exit 1
fi
job_success "scratch-blocks" "clone"
fi
job_start "scratch-blocks" "checkout"
pbase=$(cat patches/blocks/PATCHBASE | tr -d '\n')
echo "Checking out scratch-blocks patchbase $pbase"
cd scratch-blocks || exit
git checkout "$pbase"
if [ "$?" != "0" ]; then
job_fail "scratch-blocks" "checkout"
exit 1
fi
cd .. || exit
job_success "scratch-blocks" "checkout"
}
sub_patch() {
sub_clone
job_start "scratch-blocks" "patch"
cd scratch-blocks || exit
git am --abort >/dev/null 2>&1
git am --3way "../patches/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