-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-against-manifest.sh
executable file
·69 lines (54 loc) · 2.19 KB
/
check-against-manifest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
PATH_DIR="${GITHUB_WORKSPACE}/${PATH_DIR}"
manifest_file="${GIT_MANIFEST}"
rsync_file="${RSYNC_MANIFEST}"
echo "--------------------------------------------------"
cd "${PATH_DIR}" || exit 1;
echo "Removing leading +/- from manifest file"
sed -i -E "s/^[+-] //" "$manifest_file"
echo "Removing leading 'deleting' from rsync file"
sed -i -E "s/^deleting //" "$rsync_file"
echo "Removing directories from rsync file"
sed -i -E "/\/$/d" "$rsync_file"
# if SSH_IGNORE_LIST is not empty
if [ -n "$SSH_IGNORE_LIST" ]; then
# Process gitignore rules if they are not empty
echo "Applying new Gitignore rules:"
echo "${SSH_IGNORE_LIST}"
# Popuplate new gitignore file with contents of $SSH_IGNORE_LIST
mv .gitignore .gitignore.bak
echo "$SSH_IGNORE_LIST" > .gitignore
# Create a temporary file to store the updated file paths
temp_file=$(mktemp)
# Remove lines matching gitignore patterns from file_paths.txt
while IFS= read -r file_path; do
if ! git check-ignore -q --no-index "$file_path"; then
echo "$file_path" >> "$temp_file"
else
echo "Removed line from GIT manifest: $file_path"
fi
done < "$manifest_file"
# Overwrite the original file_paths.txt with the temporary file
mv "$temp_file" "$manifest_file"
# Revert .gitignore to original state
mv -f .gitignore.bak .gitignore
fi
# Sort and remove empty lines from the files
sorted_file1=$(grep -v '^$' "$manifest_file" | sort)
sorted_file2=$(grep -v '^$' "$rsync_file" | sort)
# Compare the sorted files using diff
diff_output=$(diff -u <(echo "$sorted_file1") <(echo "$sorted_file2"))
echo "--------------------------------------------------"
# Check if there are any differences
if [ -n "$diff_output" ]; then
echo "::error title=Manifest and Rsync list DO NOT MATCH :: Please check the following diff. Lines starting with + are in the rsync list but not in the manifest. Lines starting with - are in the manifest but not in the rsync list."
echo "--------------------------------------------------"
echo "::group::DIFF OUTPUT"
echo "$diff_output"
echo "::endgroup::"
exit 1
else
echo "Manifest and Rsync list match."
echo "--------------------------------------------------"
exit 0
fi