From e0a9bafde203c8638eeba76b61f19c4d6b837795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 19 Jun 2024 15:14:25 +0200 Subject: [PATCH] helpers.v2.1: Add ynh_in_ci_tests to check if the scripts are running in CI or not --- helpers/helpers.v2.1.d/backup | 4 ++-- helpers/helpers.v2.1.d/utils | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/helpers/helpers.v2.1.d/backup b/helpers/helpers.v2.1.d/backup index 42f7476b0..abb41e041 100644 --- a/helpers/helpers.v2.1.d/backup +++ b/helpers/helpers.v2.1.d/backup @@ -216,7 +216,7 @@ ynh_store_file_checksum() { ynh_app_setting_set --key=$checksum_setting_name --value=$(md5sum "$file" | cut --delimiter=' ' --fields=1) - if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + if ynh_in_ci_tests; then # Using a base64 is in fact more reversible than "replace / and space by _" ... So we can in fact obtain the original file path in an easy reliable way ... local file_path_base64=$(echo "$file" | base64 -w0) mkdir -p /var/cache/yunohost/appconfbackup/ @@ -253,7 +253,7 @@ ynh_backup_if_checksum_is_different() { cp --archive "$file" "$backup_file_checksum" # Backup the current file ynh_print_warn "File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file_checksum" echo "$backup_file_checksum" # Return the name of the backup file - if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + if ynh_in_ci_tests; then local file_path_base64=$(echo "$file" | base64 -w0) if test -e /var/cache/yunohost/appconfbackup/original_${file_path_base64} then diff --git a/helpers/helpers.v2.1.d/utils b/helpers/helpers.v2.1.d/utils index 3f985d227..e6eb2e88b 100644 --- a/helpers/helpers.v2.1.d/utils +++ b/helpers/helpers.v2.1.d/utils @@ -616,3 +616,14 @@ ynh_get_ram() { echo $ram } + +# Check if the scripts are being run by the package_check in CI +# +# usage: ynh_in_ci_tests +# +# Return 0 if in CI, 1 otherwise +# +# Requires YunoHost version 11.3 or higher. +ynh_in_ci_tests() { + [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ] +}