helpers2.1: change source patches location + raise an error instead of a warning when a patch fails to apply on CI

Co-authored-by: Félix Piédallu <felix@piedallu.me>
This commit is contained in:
Alexandre Aubin 2024-06-30 17:46:52 +02:00
parent 3f973669fc
commit a48bfa67de

View file

@ -8,11 +8,7 @@
# | arg: --keep= - Space-separated list of files/folders that will be backup/restored in $dest_dir, such as a config file you don't want to overwrite. For example 'conf.json secrets.json logs' (no trailing `/` for folders) # | arg: --keep= - Space-separated list of files/folders that will be backup/restored in $dest_dir, such as a config file you don't want to overwrite. For example 'conf.json secrets.json logs' (no trailing `/` for folders)
# | arg: --full_replace= - Remove previous sources before installing new sources (can be 1 or 0, default to 0) # | arg: --full_replace= - Remove previous sources before installing new sources (can be 1 or 0, default to 0)
# #
# ##### New 'sources' resources # This helper will read infos from the 'sources' resources in the `manifest.toml` of the app
#
# (See also the resources documentation which may be more complete?)
#
# This helper will read infos from the 'sources' resources in the manifest.toml of the app
# and expect a structure like: # and expect a structure like:
# #
# ```toml # ```toml
@ -22,7 +18,9 @@
# sha256 = "0123456789abcdef" # The sha256 sum of the asset obtained from the URL # sha256 = "0123456789abcdef" # The sha256 sum of the asset obtained from the URL
# ``` # ```
# #
# ##### Optional flags # (See also the resources documentation which may be more complete?)
#
# ##### Optional flags in the 'sources' resource
# #
# ```text # ```text
# format = "tar.gz"/xz/bz2 # automatically guessed from the extension of the URL, but can be set explicitly. Will use `tar` to extract # format = "tar.gz"/xz/bz2 # automatically guessed from the extension of the URL, but can be set explicitly. Will use `tar` to extract
@ -60,7 +58,8 @@
# - Uncompress the archive to `$dest_dir`. # - Uncompress the archive to `$dest_dir`.
# - If `in_subdir` is true, the first level directory of the archive will be removed. # - If `in_subdir` is true, the first level directory of the archive will be removed.
# - If `in_subdir` is a numeric value, the N first level directories will be removed. # - If `in_subdir` is a numeric value, the N first level directories will be removed.
# - Patches named `patches/${src_id}-*.patch` will be applied to `$dest_dir` # - Patches named `patches/${src_id}/*.patch` will be applied to `$dest_dir`
# - Apply sane default permissions (see _ynh_apply_default_permissions)
ynh_setup_source() { ynh_setup_source() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace) local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace)
@ -222,17 +221,20 @@ ynh_setup_source() {
fi fi
# Apply patches # Apply patches
if [ -d "$YNH_APP_BASEDIR/patches/" ]; then local patches_folder=$(realpath "$YNH_APP_BASEDIR/patches/$source_id")
local patches_folder=$(realpath $YNH_APP_BASEDIR/patches/) if [ -d "$patches_folder" ]; then
# Check if any file matching the pattern exists, cf https://stackoverflow.com/a/34195247 pushd "$dest_dir"
if compgen -G "$patches_folder/${source_id}-*.patch" >/dev/null; then for patchfile in "$patches_folder/"*.patch; do
pushd "$dest_dir" echo "Applying $patchfile"
for p in $patches_folder/${source_id}-*.patch; do if ! patch --strip=1 < "$patchfile"; then
echo $p if ynh_in_ci_tests; then
patch --strip=1 <$p || ynh_print_warn "Packagers /!\\ patch $p failed to apply" ynh_die "Patch $patchfile failed to apply!"
done else
popd ynh_print_warn "Warn your packagers /!\\ Patch $patchfile failed to apply"
fi fi
fi
done
popd
fi fi
# Keep files to be backup/restored at the end of the helper # Keep files to be backup/restored at the end of the helper