forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
applyPatches.sh
executable file
·49 lines (42 loc) · 1.56 KB
/
applyPatches.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
#!/bin/bash
# This script is a simple wrapper around patch-package that fails if any errors or warnings are detected.
# This is useful because patch-package does not fail on errors or warnings by default,
# which means that broken patches are easy to miss, and leads to developer frustration and wasted time.
SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
source "$SCRIPTS_DIR/shellUtils.sh"
# Wrapper to run patch-package.
function patchPackage {
OS="$(uname)"
if [[ "$OS" == "Darwin" || "$OS" == "Linux" ]]; then
npx patch-package --error-on-fail --color=always
else
error "Unsupported OS: $OS"
exit 1
fi
}
# Run patch-package and capture its output and exit code, while still displaying the original output to the terminal
TEMP_OUTPUT="$(mktemp)"
patchPackage 2>&1 | tee "$TEMP_OUTPUT"
EXIT_CODE=${PIPESTATUS[0]}
OUTPUT="$(cat "$TEMP_OUTPUT")"
rm -f "$TEMP_OUTPUT"
# Check if the output contains a warning message
echo "$OUTPUT" | grep -q "Warning:"
WARNING_FOUND=$?
printf "\n"
# Determine the final exit code
if [ "$EXIT_CODE" -eq 0 ]; then
if [ $WARNING_FOUND -eq 0 ]; then
# patch-package succeeded but warning was found
error "It looks like you upgraded a dependency without upgrading the patch. Please review the patch, determine if it's still needed, and port it to the new version of the dependency."
exit 1
else
# patch-package succeeded and no warning was found
success "patch-package succeeded without errors or warnings"
exit 0
fi
else
# patch-package failed
error "patch-package failed to apply a patch"
exit "$EXIT_CODE"
fi