-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·75 lines (58 loc) · 1.88 KB
/
entrypoint.sh
File metadata and controls
executable file
·75 lines (58 loc) · 1.88 KB
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
#!/usr/bin/env bash
set -e
set -o pipefail
# Input checks
if [[ -z "$INPUT_PATTERN" ]]; then
echo "::error ::Missing mandatory 'pattern' input."
exit 1
fi
if [[ -n "$INPUT_VALUES" ]] && [[ -n "$INPUT_PIPE" ]]; then
echo "::error ::The 'values' input must be mutually exclusive with the 'pipe' input."
exit 1
fi
# Build base command
if [[ -n "$INPUT_VALUES" ]] || [[ -n "$INPUT_PIPE" ]]; then
# Filter the given input values
cmd="python3 '$GITHUB_ACTION_PATH/glob/globmatch.py'"
else
# Operate on the file system
cmd="python3 '$GITHUB_ACTION_PATH/glob/glob.py'"
fi
patterns=$(printf '%s\n' "$INPUT_PATTERN" | "$GITHUB_ACTION_PATH/shellquote.sh" ' ')
cmd+=" $patterns"
if [[ "$RUNNER_OS" == "Windows" ]]; then
# Remove carriage return from Python output
cmd+=" | sed $'s/\r$//'"
fi
# Execute directly
if [[ "$INPUT_RETURN_PIPE" != "true" ]]; then
if [[ -n "$INPUT_PIPE" ]]; then
cmd="$INPUT_PIPE | $cmd"
else
cmd="echo \"$INPUT_VALUES\" | $cmd"
fi
matches=$(eval "$cmd")
eof=$(openssl rand -hex 16)
echo "matches<<$eof" >> $GITHUB_OUTPUT
echo "$matches" >> $GITHUB_OUTPUT
echo "$eof" >> $GITHUB_OUTPUT
exit 0
fi
# Build output "pipe" command
if [[ -n "$INPUT_VALUES" ]] || [[ -n "$INPUT_PIPE" ]]; then
if [[ -n "$INPUT_PIPE" ]]; then
input="$INPUT_PIPE"
else
# Transform newline separated values into a shell-quoted string
input=$(printf '%s\n' "$INPUT_VALUES" | "$GITHUB_ACTION_PATH/shellquote.sh" '$'"'"'\\n'"'"'')
input="echo $input"
fi
cmd="$input | $cmd"
fi
if [[ -z "$INPUT_VALUES" ]]; then
# Make sure the pipe output preserves the current working directory if we are either operating
# on the life file system or if a pipe input is used.
working_directory="$(pwd -P)"
cmd="(cd '$working_directory' && $cmd)"
fi
echo "pipe=$cmd" >> "$GITHUB_OUTPUT"