2023-05-23 18:50:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
job_start=0
|
|
|
|
|
|
|
|
job_start() {
|
|
|
|
# [*] job start - [target]:[job]
|
|
|
|
# bold
|
|
|
|
echo -e "\e[1m[*] job start - $1:$2\e[0m"
|
2023-05-24 02:02:12 +00:00
|
|
|
job_start=$(date +%s.%N)
|
2023-05-23 18:50:30 +00:00
|
|
|
}
|
|
|
|
job_success() {
|
|
|
|
# [*] success! [target]:[job] finished in 241.2s :)
|
2023-05-24 02:02:12 +00:00
|
|
|
end=$(date +%s.%N)
|
|
|
|
time=$( echo "$end - $job_start" | bc -l )
|
2023-05-23 18:50:30 +00:00
|
|
|
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 :(
|
2023-05-24 02:02:12 +00:00
|
|
|
end=$(date +%s.%N)
|
|
|
|
time=$( echo "$end - $job_start" | bc -l )
|
2023-05-23 18:50:30 +00:00
|
|
|
echo -e "\e[1m\e[31m[*] FAIL! $1:$2 failed in $time seconds :(\e[0m"
|
|
|
|
}
|
2023-05-24 02:02:12 +00:00
|
|
|
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"
|
|
|
|
}
|
2023-05-23 18:50:30 +00:00
|
|
|
|
|
|
|
sub_clone() {
|
|
|
|
job_start "scratch-blocks" "clone"
|
2023-05-24 02:02:12 +00:00
|
|
|
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"
|
2023-05-23 18:50:30 +00:00
|
|
|
fi
|
2023-05-24 02:02:12 +00:00
|
|
|
job_start "scratch-blocks" "checkout"
|
2023-05-24 12:23:20 +00:00
|
|
|
pbase=$(cat patches/blocks/PATCHBASE | tr -d '\n')
|
2023-05-24 02:02:12 +00:00
|
|
|
echo "Checking out scratch-blocks patchbase $pbase"
|
|
|
|
cd scratch-blocks || exit
|
|
|
|
git checkout "$pbase"
|
2023-05-23 18:50:30 +00:00
|
|
|
if [ "$?" != "0" ]; then
|
2023-05-24 02:02:12 +00:00
|
|
|
job_fail "scratch-blocks" "checkout"
|
2023-05-23 18:50:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-05-24 02:02:12 +00:00
|
|
|
cd .. || exit
|
|
|
|
job_success "scratch-blocks" "checkout"
|
2023-05-23 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub_patch() {
|
|
|
|
sub_clone
|
|
|
|
|
|
|
|
job_start "scratch-blocks" "patch"
|
|
|
|
|
|
|
|
cd scratch-blocks || exit
|
|
|
|
|
|
|
|
git am --abort >/dev/null 2>&1
|
|
|
|
|
2023-05-24 12:23:20 +00:00
|
|
|
git am --3way "../patches/blocks/"*.patch
|
2023-05-23 18:50:30 +00:00
|
|
|
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
|