-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44589 from Expensify/Rory-VerifyPatches
[No QA] Fail patch-package on errors or warnings
- Loading branch information
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/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" | ||
|
||
# Run patch-package and capture its output and exit code, while still displaying the original output to the terminal | ||
# (we use `script -q /dev/null` to preserve colorization in the output) | ||
TEMP_OUTPUT="$(mktemp)" | ||
script -q /dev/null npx patch-package --error-on-fail 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters