From 437fa0ba229cb4dcab1ddad6ffacb50636307eeb Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Wed, 11 Jun 2025 12:18:12 +0200 Subject: [PATCH 1/6] Make sure all scripts are actually changed by the PR --- install_scripts.sh | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/install_scripts.sh b/install_scripts.sh index c5a9a556c2..e5717249a2 100755 --- a/install_scripts.sh +++ b/install_scripts.sh @@ -8,6 +8,31 @@ display_help() { echo " -h | --help - display this usage information" } +file_changed_in_pr() { + local full_path="$1" + local base_branch="${2:-origin/2023.06-software.eessi.io}" # Default to origin/2023.06-software.eessi.io + + # Make sure file exists + [[ -f "$full_path" ]] || return 1 + + # Check if the file is in a Git repo + 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 diff range + ( + cd "$repo_root" || return 2 + git diff --name-only "$base_branch"...HEAD | grep -q "^$rel_path$" + ) && return 0 || return 1 +} + compare_and_copy() { if [ "$#" -ne 2 ]; then echo "Usage of function: compare_and_copy " @@ -18,8 +43,19 @@ 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" ;; + 2) echo "🚫 Not in a Git repo" ;; + *) echo "⚠️ Unknown error" ;; + esac + fi else echo "Files $1 and $2 are identical. No copy needed." fi From 5c6255753bfb322b0312d76b9ce0578aa1f869dc Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Wed, 11 Jun 2025 12:48:51 +0200 Subject: [PATCH 2/6] Make pr_diff file available --- EESSI-install-software.sh | 9 +++++---- install_scripts.sh | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) 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 e5717249a2..e1e1694663 100755 --- a/install_scripts.sh +++ b/install_scripts.sh @@ -15,7 +15,7 @@ file_changed_in_pr() { # Make sure file exists [[ -f "$full_path" ]] || return 1 - # Check if the file is in a Git repo + # 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 @@ -26,10 +26,14 @@ file_changed_in_pr() { local rel_path rel_path=$(realpath --relative-to="$repo_root" "$full_path") - # Check if the file changed in the diff range + # Check if the file changed in the PR diff file that we have ( cd "$repo_root" || return 2 - git diff --name-only "$base_branch"...HEAD | grep -q "^$rel_path$" + if [ -f "$PR_DIFF" ]; then # PR_DIFF should be set by the calling script + grep -q "b/$rel_path" "$pr_diff" # Add b/ to match diff patterns + else + return 3 + fi ) && return 0 || return 1 } @@ -51,8 +55,9 @@ compare_and_copy() { echo "File $source_file copied to $destination_file" else case $? in - 1) echo "❌ File has NOT changed" ;; - 2) echo "🚫 Not in a Git repo" ;; + 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 From 0d0ff5dba10bb34a4b2e77a9e1ddff47d815e369 Mon Sep 17 00:00:00 2001 From: ocaisa Date: Wed, 11 Jun 2025 13:03:13 +0200 Subject: [PATCH 3/6] Update install_scripts.sh --- install_scripts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_scripts.sh b/install_scripts.sh index e1e1694663..e90a276a8d 100755 --- a/install_scripts.sh +++ b/install_scripts.sh @@ -30,7 +30,7 @@ file_changed_in_pr() { ( cd "$repo_root" || return 2 if [ -f "$PR_DIFF" ]; then # PR_DIFF should be set by the calling script - grep -q "b/$rel_path" "$pr_diff" # Add b/ to match diff patterns + grep -q "b/$rel_path" "$PR_DIFF" # Add b/ to match diff patterns else return 3 fi From 330416fb90ecd670bc59ae89a820a83515705397 Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Wed, 11 Jun 2025 13:22:13 +0200 Subject: [PATCH 4/6] Modify eb_hooks.py to test new functionality --- eb_hooks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/eb_hooks.py b/eb_hooks.py index acbe6cab22..f206e8b076 100644 --- a/eb_hooks.py +++ b/eb_hooks.py @@ -1,3 +1,4 @@ +# TEMPORARY COMMENT TO CHECK PR # Hooks to customize how EasyBuild installs software in EESSI # see https://docs.easybuild.io/en/latest/Hooks.html import glob From 19999e31f29a4a884369c6bc1aeedba0423882da Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Wed, 11 Jun 2025 14:08:42 +0200 Subject: [PATCH 5/6] Revert eb_hooks.py change --- eb_hooks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eb_hooks.py b/eb_hooks.py index f206e8b076..acbe6cab22 100644 --- a/eb_hooks.py +++ b/eb_hooks.py @@ -1,4 +1,3 @@ -# TEMPORARY COMMENT TO CHECK PR # Hooks to customize how EasyBuild installs software in EESSI # see https://docs.easybuild.io/en/latest/Hooks.html import glob From 5e6ddc141b77f050d084b816290c576d304205fa Mon Sep 17 00:00:00 2001 From: ocaisa Date: Wed, 11 Jun 2025 15:32:54 +0200 Subject: [PATCH 6/6] Remove unused variable, make sure required envvar is set Co-authored-by: Kenneth Hoste --- install_scripts.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install_scripts.sh b/install_scripts.sh index e90a276a8d..f4863686fc 100755 --- a/install_scripts.sh +++ b/install_scripts.sh @@ -10,7 +10,6 @@ display_help() { file_changed_in_pr() { local full_path="$1" - local base_branch="${2:-origin/2023.06-software.eessi.io}" # Default to origin/2023.06-software.eessi.io # Make sure file exists [[ -f "$full_path" ]] || return 1 @@ -29,7 +28,8 @@ file_changed_in_pr() { # Check if the file changed in the PR diff file that we have ( cd "$repo_root" || return 2 - if [ -f "$PR_DIFF" ]; then # PR_DIFF should be set by the calling script + # $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