feat: implement a very flexible runner for "pre" and "post" scripts

This new functionality now makes it possible to execute scripts at the start or end of the build process, while also being super simple to expand to add further script stages in the future.

It also supports effortless reuse of scripts for multiple stages, since the scripts are now executed with the "current stage" as their 1st argument, to allow them to easily determine which stage they're running in.
This commit is contained in:
Arcitec
2023-05-10 06:54:34 +02:00
committed by Eino Rauhala
parent f596f4c496
commit 55ff6363be
3 changed files with 31 additions and 13 deletions

View File

@@ -32,16 +32,20 @@ if [[ ${#repos[@]} -gt 0 ]]; then
echo "---"
fi
# Run scripts.
get_yaml_array buildscripts '.scripts[]'
if [[ ${#buildscripts[@]} -gt 0 ]]; then
echo "-- Running scripts defined in recipe.yml --"
for script in "${buildscripts[@]}"; do
echo "Running: ${script}"
/tmp/scripts/"$script"
done
echo "---"
fi
# Run "pre" scripts.
run_scripts() {
script_mode="$1"
get_yaml_array buildscripts ".scripts.${script_mode}[]"
if [[ ${#buildscripts[@]} -gt 0 ]]; then
echo "-- Running [${script_mode}] scripts defined in recipe.yml --"
for script in "${buildscripts[@]}"; do
echo "Running [${script_mode}]: ${script}"
/tmp/scripts/"$script" "${script_mode}"
done
echo "---"
fi
}
run_scripts "pre"
# Remove RPMs.
get_yaml_array remove_rpms '.rpm.remove[]'
@@ -77,3 +81,6 @@ if [[ ${#flatpaks[@]} -gt 0 ]]; then
done
echo "---"
fi
# Run "post" scripts.
run_scripts "post"