Skip to content

Commit e9dbaac

Browse files
authored
Merge pull request Expensify#61862 from software-mansion-labs/improve-patch-diff-with-content-hash
Update artifacts workflow to verify diff in patches based on hash of their contents
2 parents d5c6a83 + 076def0 commit e9dbaac

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

.github/workflows/publishReactNativeAndroidArtifacts.yml

+23-32
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ jobs:
2525
ref: ${{ github.event.before }}
2626
token: ${{ secrets.OS_BOTIFY_TOKEN }}
2727

28-
- name: Get previous App commit hash
29-
id: getOldAppHash
30-
run: echo "HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
31-
32-
- name: Get previous Mobile-Expensify commit hash
33-
if: ${{ matrix.is_hybrid }}
34-
id: getOldMobileExpensifyHash
35-
run: echo "HASH=$(git rev-parse :Mobile-Expensify)" >> "$GITHUB_OUTPUT"
28+
- name: Get previous patches hash
29+
id: getOldPatchesHash
30+
run: |
31+
if [[ "${{ matrix.is_hybrid }}" == "true" ]]; then
32+
echo "HASH=$(./scripts/compute-patches-hash.sh patches Mobile-Expensify/patches)" >> "$GITHUB_OUTPUT"
33+
else
34+
echo "HASH=$(./scripts/compute-patches-hash.sh patches)" >> "$GITHUB_OUTPUT"
35+
fi
3636
3737
- name: Get previous react-native version
38+
3839
id: getOldVersion
3940
run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT"
4041

@@ -44,14 +45,14 @@ jobs:
4445
git checkout ${{ github.event.after }}
4546
git submodule update
4647
47-
- name: Get new App commit hash
48-
id: getNewAppHash
49-
run: echo "HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
50-
51-
- name: Get new Mobile-Expensify commit hash
52-
if: ${{ matrix.is_hybrid }}
53-
id: getNewMobileExpensifyHash
54-
run: echo "HASH=$(git rev-parse :Mobile-Expensify)" >> "$GITHUB_OUTPUT"
48+
- name: Get new patches hash
49+
id: getNewPatchesHash
50+
run: |
51+
if [[ "${{ matrix.is_hybrid }}" == "true" ]]; then
52+
echo "HASH=$(./scripts/compute-patches-hash.sh patches Mobile-Expensify/patches)" >> "$GITHUB_OUTPUT"
53+
else
54+
echo "HASH=$(./scripts/compute-patches-hash.sh patches)" >> "$GITHUB_OUTPUT"
55+
fi
5556
5657
- name: Get new react-native version
5758
id: getNewVersion
@@ -69,22 +70,12 @@ jobs:
6970
- name: Check if patches changed
7071
id: didPatchesChange
7172
run: |
72-
if ! git diff --exit-code --name-only ${{ steps.getOldAppHash.outputs.HASH }}..${{ steps.getNewAppHash.outputs.HASH }} -- patches/react-native+*.patch patches/@react-native+*.patch; then
73-
echo "::notice::Detected changes in patches (Standalone NewDot)"
74-
echo "DID_PATCHES_CHANGE=true" >> "$GITHUB_OUTPUT"
75-
exit 0
73+
readonly DID_PATCHES_CHANGE=${{ steps.getOldPatchesHash.outputs.HASH != steps.getNewPatchesHash.outputs.HASH && 'true' || 'false' }}
74+
echo "DID_PATCHES_CHANGE=$DID_PATCHES_CHANGE" >> "$GITHUB_OUTPUT"
75+
if [[ "$DID_PATCHES_CHANGE" == 'true' ]]; then
76+
echo "::notice::Detected changes in patches (${{ steps.getOldPatchesHash.outputs.HASH }} -> ${{ steps.getNewPatchesHash.outputs.HASH }})"
7677
fi
7778
78-
if [[ '${{ matrix.is_hybrid }}' == 'true' ]]; then
79-
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
80-
echo "::notice::Detected changes in patches (HybridApp)"
81-
echo "DID_PATCHES_CHANGE=true" >> "$GITHUB_OUTPUT"
82-
exit 0
83-
fi
84-
fi
85-
86-
echo "DID_PATCHES_CHANGE=false" >> "$GITHUB_OUTPUT"
87-
8879
- name: Check if we should build and publish the package
8980
id: shouldPublish
9081
run: |
@@ -128,7 +119,7 @@ jobs:
128119
run: |
129120
echo "Starting artifacts build for ${{ matrix.is_hybrid && 'HybridApp' || 'NewDot Standalone' }}"
130121
echo "Version: ${{ env.PATCHED_VERSION }}"
131-
echo "Commit hash: ${{ env.COMMIT_HASH }}"
122+
echo "Patches hash: ${{ env.PATCHES_HASH }}"
132123
export ORG_GRADLE_PROJECT_reactNativeArchitectures="armeabi-v7a,arm64-v8a,x86,x86_64"
133124
./gradlew buildReactNativeArtifacts -x lint -x test -x check
134125
./gradlew publishReactNativeArtifacts
@@ -137,7 +128,7 @@ jobs:
137128
GH_PUBLISH_TOKEN: ${{ github.token }}
138129
IS_HYBRID_BUILD: ${{ matrix.is_hybrid }}
139130
PATCHED_VERSION: ${{ steps.getNewPatchedVersion.outputs.NEW_PATCHED_VERSION }}
140-
COMMIT_HASH: ${{ github.event.after }}
131+
PATCHES_HASH: ${{ steps.getNewPatchesHash.outputs.HASH }}
141132

142133
- name: Announce failed workflow in Slack
143134
if: ${{ failure() }}

patches/react-native+0.77.1+025.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ index 32287a7..5607be3 100644
4545
url = "https://github.com/facebook/react-native"
4646

4747
+ properties = [
48-
+ "commitHash": System.getenv("COMMIT_HASH"),
48+
+ "patchesHash": System.getenv("PATCHES_HASH"),
4949
+ ]
5050
+
5151
developers {

scripts/compute-patches-hash.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
4+
readonly SCRIPT_DIR
5+
source "$SCRIPT_DIR/shellUtils.sh"
6+
7+
if [ $# -eq 0 ]; then
8+
error "Please provide at least one path as an argument"
9+
exit 1
10+
fi
11+
12+
PATCH_DIRS=("$@")
13+
readonly PATCH_DIRS
14+
15+
# Find all patches, compute their hash, put filename before hash, sort, compute hash of hashes
16+
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}'

0 commit comments

Comments
 (0)