diff --git a/EESSI-install-software.sh b/EESSI-install-software.sh index a38a1c047a..60613fed6f 100755 --- a/EESSI-install-software.sh +++ b/EESSI-install-software.sh @@ -242,6 +242,11 @@ fi # order is important: these are needed to install a full CUDA SDK in host_injections # for now, this just reinstalls all scripts. Note the most elegant, but works +# the install_scripts.sh script relies on knowing the location of the PR diff +# assume there's only one diff file that corresponds to the PR patch file +pr_diff=$(ls [0-9]*.diff | head -1) +export PR_DIFF="$PWD/$pr_diff" + # Only run install_scripts.sh if not in dev.eessi.io for security if [[ -z ${EESSI_DEV_PROJECT} ]]; then ${TOPDIR}/install_scripts.sh --prefix ${EESSI_PREFIX} @@ -341,10 +346,6 @@ else echo_green ">> MODULEPATH set up: ${MODULEPATH}" fi -# assume there's only one diff file that corresponds to the PR patch file -pr_diff=$(ls [0-9]*.diff | head -1) - - # use PR patch file to determine in which easystack files stuff was added changed_easystacks=$(cat ${pr_diff} | grep '^+++' | cut -f2 -d' ' | sed 's@^[a-z]/@@g' | grep 'easystacks/.*yml$' | egrep -v 'known-issues|missing') if [ -z "${changed_easystacks}" ]; then diff --git a/install_scripts.sh b/install_scripts.sh index c5a9a556c2..f4863686fc 100755 --- a/install_scripts.sh +++ b/install_scripts.sh @@ -8,6 +8,35 @@ display_help() { echo " -h | --help - display this usage information" } +file_changed_in_pr() { + local full_path="$1" + + # Make sure file exists + [[ -f "$full_path" ]] || return 1 + + # Check if the file is in a Git repo (it should be) + local repo_root + repo_root=$(git -C "$(dirname "$full_path")" rev-parse --show-toplevel 2>/dev/null) + if [[ -z "$repo_root" ]]; then + return 2 # Not in a git repository + fi + + # Compute relative path to the repo root + local rel_path + rel_path=$(realpath --relative-to="$repo_root" "$full_path") + + # Check if the file changed in the PR diff file that we have + ( + cd "$repo_root" || return 2 + # $PR_DIFF should be set by the calling script + if [[ ! -z ${PR_DIFF} ]] && [[ -f "$PR_DIFF" ]]; then + grep -q "b/$rel_path" "$PR_DIFF" # Add b/ to match diff patterns + else + return 3 + fi + ) && return 0 || return 1 +} + compare_and_copy() { if [ "$#" -ne 2 ]; then echo "Usage of function: compare_and_copy " @@ -18,8 +47,20 @@ compare_and_copy() { destination_file="$2" if [ ! -f "$destination_file" ] || ! diff -q "$source_file" "$destination_file" ; then - cp "$source_file" "$destination_file" - echo "File $1 copied to $2" + echo "Files $source_file and $destination_file differ, checking if we should copy or not" + # We only copy if the file is part of the PR + if file_changed_in_pr "$source_file"; then + echo "File has changed in the PR" + cp "$source_file" "$destination_file" + echo "File $source_file copied to $destination_file" + else + case $? in + 1) echo "❌ File has NOT changed in PR" ;; + 2) echo "🚫 Not in Git repository" ;; + 3) echo "🚫 No PR diff file found" ;; + *) echo "⚠️ Unknown error" ;; + esac + fi else echo "Files $1 and $2 are identical. No copy needed." fi