Skip to content

Commit 6f10355

Browse files
authored
Merge pull request #1119 from ocaisa/only_modified_files_in_tarball
Only include files modified by the PR in tarball
2 parents e22f293 + 9abf4df commit 6f10355

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

EESSI-install-software.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ fi
242242
# order is important: these are needed to install a full CUDA SDK in host_injections
243243
# for now, this just reinstalls all scripts. Note the most elegant, but works
244244

245+
# the install_scripts.sh script relies on knowing the location of the PR diff
246+
# assume there's only one diff file that corresponds to the PR patch file
247+
pr_diff=$(ls [0-9]*.diff | head -1)
248+
export PR_DIFF="$PWD/$pr_diff"
249+
245250
# Only run install_scripts.sh if not in dev.eessi.io for security
246251
if [[ -z ${EESSI_DEV_PROJECT} ]]; then
247252
${TOPDIR}/install_scripts.sh --prefix ${EESSI_PREFIX}
@@ -341,10 +346,6 @@ else
341346
echo_green ">> MODULEPATH set up: ${MODULEPATH}"
342347
fi
343348

344-
# assume there's only one diff file that corresponds to the PR patch file
345-
pr_diff=$(ls [0-9]*.diff | head -1)
346-
347-
348349
# use PR patch file to determine in which easystack files stuff was added
349350
changed_easystacks=$(cat ${pr_diff} | grep '^+++' | cut -f2 -d' ' | sed 's@^[a-z]/@@g' | grep 'easystacks/.*yml$' | egrep -v 'known-issues|missing')
350351
if [ -z "${changed_easystacks}" ]; then

install_scripts.sh

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ display_help() {
88
echo " -h | --help - display this usage information"
99
}
1010

11+
file_changed_in_pr() {
12+
local full_path="$1"
13+
14+
# Make sure file exists
15+
[[ -f "$full_path" ]] || return 1
16+
17+
# Check if the file is in a Git repo (it should be)
18+
local repo_root
19+
repo_root=$(git -C "$(dirname "$full_path")" rev-parse --show-toplevel 2>/dev/null)
20+
if [[ -z "$repo_root" ]]; then
21+
return 2 # Not in a git repository
22+
fi
23+
24+
# Compute relative path to the repo root
25+
local rel_path
26+
rel_path=$(realpath --relative-to="$repo_root" "$full_path")
27+
28+
# Check if the file changed in the PR diff file that we have
29+
(
30+
cd "$repo_root" || return 2
31+
# $PR_DIFF should be set by the calling script
32+
if [[ ! -z ${PR_DIFF} ]] && [[ -f "$PR_DIFF" ]]; then
33+
grep -q "b/$rel_path" "$PR_DIFF" # Add b/ to match diff patterns
34+
else
35+
return 3
36+
fi
37+
) && return 0 || return 1
38+
}
39+
1140
compare_and_copy() {
1241
if [ "$#" -ne 2 ]; then
1342
echo "Usage of function: compare_and_copy <source_file> <destination_file>"
@@ -18,8 +47,20 @@ compare_and_copy() {
1847
destination_file="$2"
1948

2049
if [ ! -f "$destination_file" ] || ! diff -q "$source_file" "$destination_file" ; then
21-
cp "$source_file" "$destination_file"
22-
echo "File $1 copied to $2"
50+
echo "Files $source_file and $destination_file differ, checking if we should copy or not"
51+
# We only copy if the file is part of the PR
52+
if file_changed_in_pr "$source_file"; then
53+
echo "File has changed in the PR"
54+
cp "$source_file" "$destination_file"
55+
echo "File $source_file copied to $destination_file"
56+
else
57+
case $? in
58+
1) echo "❌ File has NOT changed in PR" ;;
59+
2) echo "🚫 Not in Git repository" ;;
60+
3) echo "🚫 No PR diff file found" ;;
61+
*) echo "⚠️ Unknown error" ;;
62+
esac
63+
fi
2364
else
2465
echo "Files $1 and $2 are identical. No copy needed."
2566
fi

0 commit comments

Comments
 (0)