-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathentrypoint.sh
executable file
·115 lines (89 loc) · 3.89 KB
/
entrypoint.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -euo pipefail
INPUT_SEPARATOR="${INPUT_SEPARATOR//\%/%25}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//\./%2E}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//\\n/%0A}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//\\r/%0D}"
echo "::group::verify-changed-files"
echo "::debug::Separator: $INPUT_SEPARATOR"
git config --global core.quotepath "$INPUT_QUOTEPATH"
OS=$(uname -s)
if [[ -n $INPUT_PATH ]]; then
if [[ "$OS" == "NT"* ]] || [[ "$OS" == "MINGW"* ]] || [[ "$OS" == *"MSYS"* ]]; then
REPO_DIR="$GITHUB_WORKSPACE\\$INPUT_PATH"
else
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
fi
echo "Resolving repository path: $REPO_DIR"
if [[ ! -d "$REPO_DIR" ]]; then
echo "::error::Invalid repository path: $REPO_DIR"
echo "::endgroup::"
exit 1
fi
cd "$REPO_DIR"
fi
GIT_STATUS_EXTRA_ARGS="-u --porcelain"
if [[ "$INPUT_MATCH_GITIGNORE_FILES" == "true" ]]; then
GIT_STATUS_EXTRA_ARGS+=" --ignored"
fi
if [[ -n "$INPUT_FILES_PATTERN_FILE" ]]; then
TRACKED_FILES=$(git diff --diff-filter=ACMUXTR --name-only | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | perl -pe 's/([$\(\)`|&;])/\\$1/g' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
# Find untracked changes
# shellcheck disable=SC2086
UNTRACKED_OR_IGNORED_FILES=$(git status $GIT_STATUS_EXTRA_ARGS | awk '/\?\?|!!/ {print $2}' | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | perl -pe 's/([$\(\)`|&;])/\\$1/g' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
# Find unstaged deleted files
UNSTAGED_DELETED_FILES=$(git ls-files --deleted | { grep -x -E -f "$INPUT_FILES_PATTERN_FILE" || true; } | perl -pe 's/([$\(\)`|&;])/\\$1/g' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
else
TRACKED_FILES=$(git diff --diff-filter=ACMUXTR --name-only | perl -pe 's/([$\(\)`|&;])/\\$1/g' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
# Find untracked changes
# shellcheck disable=SC2086
UNTRACKED_OR_IGNORED_FILES=$(git status $GIT_STATUS_EXTRA_ARGS | awk '/\?\?|!!/ {print $2}' | perl -pe 's/([$\(\)`|&;])/\\$1/g' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
# Find unstaged deleted files
UNSTAGED_DELETED_FILES=$(git ls-files --deleted | perl -pe 's/([$\(\)`|&;])/\\$1/g' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
fi
echo "::debug::Tracked changed files: $TRACKED_FILES"
echo "::debug::Untracked/Ignored changed files: $UNTRACKED_OR_IGNORED_FILES"
echo "::debug::Unstaged changed files: $UNSTAGED_DELETED_FILES"
# Function to concatenate unique filenames with a specified separator
function concatenate_unique_filenames() {
local separator=$1
shift
local filenames=""
for files in "$@"; do
if [[ -n $files ]]; then
if [[ -n $filenames ]]; then
filenames+="$separator$files"
else
filenames="$files"
fi
fi
done
filenames=$(echo "$filenames" | tr "$separator" '\n' | sort -u | tr '\n' "$separator")
filenames=${filenames%"$separator"} # Remove trailing separator
echo "$filenames"
}
# Concatenate non-empty strings with a '|' separator and Remove duplicate entries
CHANGED_FILES=$(concatenate_unique_filenames "|" "$TRACKED_FILES" "$UNTRACKED_OR_IGNORED_FILES" "$UNSTAGED_DELETED_FILES")
if [[ -n "$CHANGED_FILES" ]]; then
echo "::debug::Changed files: $CHANGED_FILES"
echo "Found uncommitted changes"
CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
echo "files_changed=true" >> "$GITHUB_OUTPUT"
echo "changed_files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
if [[ "$INPUT_FAIL_IF_CHANGED" == "true" ]]; then
if [[ -n "$INPUT_FAIL_MSG" ]]; then
echo "::error::$INPUT_FAIL_MSG"
fi
exit 1
fi
else
echo "No changes found."
echo "files_changed=false" >> "$GITHUB_OUTPUT"
if [[ "$INPUT_FAIL_IF_UNCHANGED" == "true" ]]; then
if [[ -n "$INPUT_FAIL_MSG" ]]; then
echo "$INPUT_FAIL_MSG"
fi
exit 1
fi
fi
echo "::endgroup::"