-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentrypoint.sh
executable file
·99 lines (84 loc) · 2.39 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
#!/bin/bash
# Exit codes
SUCCESS=0
INVALID_ARGUMENT_ERROR=1
EXIT_WITH_FAST_FAIL=2
INPUT_SOLUTION=$1
INPUT_FAIL_ON_REFORMAT_NEEDED=$2
INPUT_JB_CLEANUP_CODE_ARG=$3
echo ""
echo "--- --- ---"
echo "Alright GitHub Action Cleanup Code Command-Line Tool"
echo "Your setup:"
echo "- Solution: [${INPUT_SOLUTION}]"
echo "- Fail on re-format needed: [${INPUT_FAIL_ON_REFORMAT_NEEDED}]"
echo "- ReSharper CLI CleanupCode arguments: [${INPUT_JB_CLEANUP_CODE_ARG}]"
echo "--- --- ---"
echo ""
echo ""
echo "--- --- ---"
echo "Current working directory stuff:"
ls -F --color=auto --show-control-chars -a
echo "--- --- ---"
echo ""
if [ "${INPUT_FAIL_ON_REFORMAT_NEEDED}" != "yes" ] && [ "${INPUT_FAIL_ON_REFORMAT_NEEDED}" != "no" ]; then
echo ""
echo "--- --- ---"
echo "INVALID ARGUMENT OF '-f' equals '${INPUT_FAIL_ON_REFORMAT_NEEDED}'"
echo "Set 'yes' or 'no' or omit to use default equals 'no'"
echo "--- --- ---"
echo ""
exit ${INVALID_ARGUMENT_ERROR}
fi
#
# Parse arguments and put them into an array to call command
# I'm at a loss for words to describe how I managed to nail this function
# Once again I understand why all Ops always looks stressed out
#
ARG_DELIMITER="--"
S=${INPUT_JB_CLEANUP_CODE_ARG}${ARG_DELIMITER}
COMMAND_ARG_ARRAY=()
while [[ $S ]]; do
ITEM="${S%%"$ARG_DELIMITER"*}"
if [ -n "${ITEM}" ]; then
if [ "${ITEM:0-1}" == " " ]; then
ITEM="${ITEM::-1}"
fi
COMMAND_ARG_ARRAY+=("--${ITEM}")
fi
S=${S#*"$ARG_DELIMITER"}
done
echo ""
echo "--- --- ---"
echo "Restore .NET tool (the JetBrains.ReSharper.GlobalTools)"
echo "--- --- ---"
echo ""
dotnet tool restore
echo ""
echo "--- --- ---"
echo "Let's get started, keep calm and wait, it may take few moments"
for arg in "${COMMAND_ARG_ARRAY[@]}"; do
echo "Command argument: [${arg}]"
done
echo "--- --- ---"
echo ""
dotnet jb cleanupcode "${COMMAND_ARG_ARRAY[@]}" "${INPUT_SOLUTION}"
REFORMATTED_FILES=$(git diff --name-only)
if [ -z "${REFORMATTED_FILES}" ]; then
echo ""
echo "--- --- ---"
echo "No files re-formatted, everything is clean, congratulation!"
echo "--- --- ---"
echo ""
exit ${SUCCESS}
fi
if [ "${INPUT_FAIL_ON_REFORMAT_NEEDED}" = "yes" ]; then
echo ""
echo "--- --- ---"
echo "Exit with re-formatted code needed fail status, down below is the diff of the re-formatted code that needs to be committed"
echo "--- --- ---"
echo ""
git diff
exit ${EXIT_WITH_FAST_FAIL}
fi
exit ${SUCCESS}