From c2b63ac952d03c7b58061d24ee03f2ded703cbf4 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Mon, 12 May 2025 19:00:41 +0200 Subject: [PATCH 1/3] Update workflow to verify diff in patches based on hash of their contents --- .../publishReactNativeAndroidArtifacts.yml | 55 ++++++++----------- patches/react-native+0.77.1+025.patch | 2 +- scripts/compute-patches-hash.sh | 15 +++++ 3 files changed, 39 insertions(+), 33 deletions(-) create mode 100755 scripts/compute-patches-hash.sh diff --git a/.github/workflows/publishReactNativeAndroidArtifacts.yml b/.github/workflows/publishReactNativeAndroidArtifacts.yml index d3d0c1c0de41..2f237d6198a8 100644 --- a/.github/workflows/publishReactNativeAndroidArtifacts.yml +++ b/.github/workflows/publishReactNativeAndroidArtifacts.yml @@ -25,16 +25,17 @@ jobs: ref: ${{ github.event.before }} token: ${{ secrets.OS_BOTIFY_TOKEN }} - - name: Get previous App commit hash - id: getOldAppHash - run: echo "HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - - name: Get previous Mobile-Expensify commit hash - if: ${{ matrix.is_hybrid }} - id: getOldMobileExpensifyHash - run: echo "HASH=$(git rev-parse :Mobile-Expensify)" >> "$GITHUB_OUTPUT" + - name: Get previous patches hash + id: getOldPatchesHash + run: | + if [[ "${{ matrix.is_hybrid }}" == "true" ]]; then + echo "HASH=$(./scripts/compute-patches-hash.sh patches Mobile-Expensify/patches)" >> "$GITHUB_OUTPUT" + else + echo "HASH=$(./scripts/compute-patches-hash.sh patches)" >> "$GITHUB_OUTPUT" + fi - name: Get previous react-native version + id: getOldVersion run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT" @@ -44,14 +45,14 @@ jobs: git checkout ${{ github.event.after }} git submodule update - - name: Get new App commit hash - id: getNewAppHash - run: echo "HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - - name: Get new Mobile-Expensify commit hash - if: ${{ matrix.is_hybrid }} - id: getNewMobileExpensifyHash - run: echo "HASH=$(git rev-parse :Mobile-Expensify)" >> "$GITHUB_OUTPUT" + - name: Get new patches hash + id: getNewPatchesHash + run: | + if [[ "${{ matrix.is_hybrid }}" == "true" ]]; then + echo "HASH=$(./scripts/compute-patches-hash.sh patches Mobile-Expensify/patches)" >> "$GITHUB_OUTPUT" + else + echo "HASH=$(./scripts/compute-patches-hash.sh patches)" >> "$GITHUB_OUTPUT" + fi - name: Get new react-native version id: getNewVersion @@ -69,22 +70,12 @@ jobs: - name: Check if patches changed id: didPatchesChange run: | - if ! git diff --exit-code --name-only ${{ steps.getOldAppHash.outputs.HASH }}..${{ steps.getNewAppHash.outputs.HASH }} -- patches/react-native+*.patch patches/@react-native+*.patch; then - echo "::notice::Detected changes in patches (Standalone NewDot)" - echo "DID_PATCHES_CHANGE=true" >> "$GITHUB_OUTPUT" - exit 0 + readonly DID_PATCHES_CHANGE=${{ steps.getOldPatchesHash.outputs.HASH != steps.getNewPatchesHash.outputs.HASH && 'true' || 'false' }} + echo "DID_PATCHES_CHANGE=$DID_PATCHES_CHANGE" >> "$GITHUB_OUTPUT" + if [[ "$DID_PATCHES_CHANGE" == 'true' ]]; then + echo "::notice::Detected changes in patches (${{ steps.getOldPatchesHash.outputs.HASH }} -> ${{ steps.getNewPatchesHash.outputs.HASH }})" fi - if [[ '${{ matrix.is_hybrid }}' == 'true' ]]; then - if ! git -C Mobile-Expensify diff --exit-code --name-only ${{ steps.getOldMobileExpensifyHash.outputs.HASH }}..${{ steps.getNewMobileExpensifyHash.outputs.HASH }} -- patches/react-native+*.patch patches/@react-native+*.patch; then - echo "::notice::Detected changes in patches (HybridApp)" - echo "DID_PATCHES_CHANGE=true" >> "$GITHUB_OUTPUT" - exit 0 - fi - fi - - echo "DID_PATCHES_CHANGE=false" >> "$GITHUB_OUTPUT" - - name: Check if we should build and publish the package id: shouldPublish run: | @@ -128,7 +119,7 @@ jobs: run: | echo "Starting artifacts build for ${{ matrix.is_hybrid && 'HybridApp' || 'NewDot Standalone' }}" echo "Version: ${{ env.PATCHED_VERSION }}" - echo "Commit hash: ${{ env.COMMIT_HASH }}" + echo "Patches hash: ${{ env.PATCHES_HASH }}" export ORG_GRADLE_PROJECT_reactNativeArchitectures="armeabi-v7a,arm64-v8a,x86,x86_64" ./gradlew buildReactNativeArtifacts -x lint -x test -x check ./gradlew publishReactNativeArtifacts @@ -137,7 +128,7 @@ jobs: GH_PUBLISH_TOKEN: ${{ github.token }} IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} PATCHED_VERSION: ${{ steps.getNewPatchedVersion.outputs.NEW_PATCHED_VERSION }} - COMMIT_HASH: ${{ github.event.after }} + PATCHES_HASH: ${{ steps.getNewPatchesHash.outputs.HASH }} - name: Announce failed workflow in Slack if: ${{ failure() }} diff --git a/patches/react-native+0.77.1+025.patch b/patches/react-native+0.77.1+025.patch index 6c60d05cf029..fb645f0c446e 100644 --- a/patches/react-native+0.77.1+025.patch +++ b/patches/react-native+0.77.1+025.patch @@ -45,7 +45,7 @@ index 32287a7..5607be3 100644 url = "https://github.com/facebook/react-native" + properties = [ -+ "commitHash": System.getenv("COMMIT_HASH"), ++ "patchesHash": System.getenv("PATCHES_HASH"), + ] + developers { diff --git a/scripts/compute-patches-hash.sh b/scripts/compute-patches-hash.sh new file mode 100755 index 000000000000..3e2975d25c41 --- /dev/null +++ b/scripts/compute-patches-hash.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +readonly SCRIPT_DIR +source "$SCRIPT_DIR/shellUtils.sh" + +if [ $# -eq 0 ]; then + error "Please provide at least one path as an argument" + exit 1 +fi + +PATCH_DIRS=("$@") +readonly PATCH_DIRS + +find "${PATCH_DIRS[@]}" -type f \( -name "react-native+*.patch" -o -name "@react-native+*.patch" \) -exec sha256sum {} + | sort | sha256sum | awk '{print $1}' From ad52b75afe030c47fcd15b6e3a5f1542e1abdc85 Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Tue, 13 May 2025 14:59:37 +0200 Subject: [PATCH 2/3] Do not include filepath during hash computation --- scripts/compute-patches-hash.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compute-patches-hash.sh b/scripts/compute-patches-hash.sh index 3e2975d25c41..18c08ae3273c 100755 --- a/scripts/compute-patches-hash.sh +++ b/scripts/compute-patches-hash.sh @@ -12,4 +12,4 @@ fi PATCH_DIRS=("$@") readonly PATCH_DIRS -find "${PATCH_DIRS[@]}" -type f \( -name "react-native+*.patch" -o -name "@react-native+*.patch" \) -exec sha256sum {} + | sort | sha256sum | awk '{print $1}' +find "${PATCH_DIRS[@]}" -type f \( -name "react-native+*.patch" -o -name "@react-native+*.patch" \) -exec sha256sum {} + | awk '{print $1}' | sort | sha256sum | awk '{print $1}' From 076def093ee96dc2f71f616f6f9df9df4276346c Mon Sep 17 00:00:00 2001 From: Mateusz Rajski Date: Wed, 14 May 2025 17:02:23 +0200 Subject: [PATCH 3/3] Ensure that changing name of a patch results in different hash --- scripts/compute-patches-hash.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/compute-patches-hash.sh b/scripts/compute-patches-hash.sh index 18c08ae3273c..b87e178a728b 100755 --- a/scripts/compute-patches-hash.sh +++ b/scripts/compute-patches-hash.sh @@ -12,4 +12,5 @@ fi PATCH_DIRS=("$@") readonly PATCH_DIRS -find "${PATCH_DIRS[@]}" -type f \( -name "react-native+*.patch" -o -name "@react-native+*.patch" \) -exec sha256sum {} + | awk '{print $1}' | sort | sha256sum | awk '{print $1}' +# Find all patches, compute their hash, put filename before hash, sort, compute hash of hashes +find "${PATCH_DIRS[@]}" -type f \( -name "react-native+*.patch" -o -name "@react-native+*.patch" \) -exec sha256sum {} \; | awk '{split($2, pathParts, "/"); print pathParts[length(pathParts)], $1 }' | sort | sha256sum | awk '{print $1}'