Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Fail patch-package on errors or warnings #44589

Merged
merged 13 commits into from
Jul 1, 2024
25 changes: 25 additions & 0 deletions .github/workflows/verifyPatches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Verify patches

on:
pull_request:
types: [opened, synchronize]
branches: [main]
paths: ['patches', 'package.json', 'package-lock.json']

concurrency:
group: verify-patches-${{ format('{0}-{1}', github.ref, github.sha) || github.ref }}
cancel-in-progress: true

jobs:
verifyPatches:
runs-on: ubuntu-latest
name: Verify patches
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: ./.github/actions/composite/setupNode

- name: Verify patches
run: ./scripts/verifyPatches.sh
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed without changes. Created upstream PR, which was missing: Expensify/react-native-live-markdown#406

File renamed without changes.
Copy link
Contributor Author

@roryabraham roryabraham Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch version matched, it just ended in .patch.patch for some reason. Renamed it to just .patch and that worked.

File renamed without changes.
32 changes: 32 additions & 0 deletions scripts/verifyPatches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")
source "$SCRIPTS_DIR/shellUtils.sh"

# Run patch-package and capture its output and exit code
TEMP_OUTPUT="$(mktemp)"
npx patch-package --error-on-fail 2>&1 | tee "$TEMP_OUTPUT"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using tee so that you can see the original output in the workflow

EXIT_CODE=${PIPESTATUS[0]}
OUTPUT="$(cat "$TEMP_OUTPUT")"
rm -f "$TEMP_OUTPUT"

# Check if the output contains the warning message
echo "$OUTPUT" | grep -q "patch-package detected a patch file version mismatch"
WARNING_FOUND=$?

# 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
Loading