|
| 1 | +name: Publish React Native Android Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - package.json |
| 9 | + - patches/react-native+*.patch |
| 10 | + - patches/@react-native+*.patch |
| 11 | + - Mobile-Expensify |
| 12 | + |
| 13 | +jobs: |
| 14 | + publish: |
| 15 | + runs-on: ${{ github.repository_owner == 'Expensify' && 'ubuntu-latest-xl' || 'ubuntu-latest' }} |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + is_hybrid: [true, false] |
| 19 | + steps: |
| 20 | + # v4 |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 |
| 23 | + with: |
| 24 | + submodules: ${{ matrix.is_hybrid }} |
| 25 | + ref: ${{ github.event.before }} |
| 26 | + token: ${{ secrets.OS_BOTIFY_TOKEN }} |
| 27 | + |
| 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 == 'true' }} |
| 34 | + id: getOldMobileExpensifyHash |
| 35 | + run: echo "HASH=$(git rev-parse :Mobile-Expensify)" >> "$GITHUB_OUTPUT" |
| 36 | + |
| 37 | + - name: Get previous react-native version |
| 38 | + id: getOldVersion |
| 39 | + run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT" |
| 40 | + |
| 41 | + - name: Checkout new ref |
| 42 | + run: | |
| 43 | + git fetch origin ${{ github.event.after }} --depth=1 |
| 44 | + git checkout ${{ github.event.after }} |
| 45 | + git submodule update |
| 46 | +
|
| 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 == 'true' }} |
| 53 | + id: getNewMobileExpensifyHash |
| 54 | + run: echo "HASH=$(git rev-parse :Mobile-Expensify)" >> "$GITHUB_OUTPUT" |
| 55 | + |
| 56 | + - name: Get new react-native version |
| 57 | + id: getNewVersion |
| 58 | + run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT" |
| 59 | + |
| 60 | + - name: Check if version changed |
| 61 | + id: didVersionChange |
| 62 | + run: | |
| 63 | + readonly DID_VERSION_CHANGE=${{ steps.getOldVersion.outputs.VERSION != steps.getNewVersion.outputs.VERSION && 'true' || 'false' }} |
| 64 | + echo "DID_VERSION_CHANGE=$DID_VERSION_CHANGE" >> "$GITHUB_OUTPUT" |
| 65 | + if [[ "$DID_VERSION_CHANGE" == 'true' ]]; then |
| 66 | + echo "::notice::Detected react-native version bump (${{ steps.getOldVersion.outputs.VERSION }} -> ${{ steps.getNewVersion.outputs.VERSION }})" |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Check if patches changed |
| 70 | + id: didPatchesChange |
| 71 | + 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" |
| 74 | + echo "DID_PATCHES_CHANGE=true" >> "$GITHUB_OUTPUT" |
| 75 | + exit 0 |
| 76 | + fi |
| 77 | +
|
| 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" |
| 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 | +
|
| 88 | + - name: Check if we should build and publish the package |
| 89 | + id: shouldPublish |
| 90 | + run: | |
| 91 | + if [[ '${{ steps.didVersionChange.outputs.DID_VERSION_CHANGE }}' == 'true' || '${{ steps.didPatchesChange.outputs.DID_PATCHES_CHANGE }}' == 'true' ]]; then |
| 92 | + echo "SHOULD_PUBLISH=true" >> "$GITHUB_OUTPUT" |
| 93 | + else |
| 94 | + echo "::notice::No relevant changes, skipping publishing a new React Native build" |
| 95 | + echo "SHOULD_PUBLISH=false" >> "$GITHUB_OUTPUT" |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Setup Node |
| 99 | + if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }} |
| 100 | + uses: ./.github/actions/composite/setupNode |
| 101 | + with: |
| 102 | + IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} |
| 103 | + |
| 104 | + # v4 |
| 105 | + - name: Setup Java |
| 106 | + if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }} |
| 107 | + uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 |
| 108 | + with: |
| 109 | + distribution: oracle |
| 110 | + java-version: 17 |
| 111 | + |
| 112 | + # v4 |
| 113 | + - name: Setup Gradle |
| 114 | + if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }} |
| 115 | + uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 |
| 116 | + |
| 117 | + - name: Determine new patched RN version |
| 118 | + if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }} |
| 119 | + id: getNewPatchedVersion |
| 120 | + run: echo "NEW_PATCHED_VERSION=$(./.github/scripts/getNewPatchedRNVersion.sh)" >> "$GITHUB_OUTPUT" |
| 121 | + env: |
| 122 | + GITHUB_TOKEN: ${{ github.token }} |
| 123 | + IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} |
| 124 | + |
| 125 | + - name: Build and publish RN artifacts |
| 126 | + if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }} |
| 127 | + working-directory: ${{ matrix.is_hybrid == 'true' && 'Mobile-Expensify/Android' || 'android' }} |
| 128 | + run: | |
| 129 | + echo "Starting artifacts build for ${{ matrix.is_hybrid == 'true' && 'HybridApp' || 'NewDot Standalone' }}" |
| 130 | + echo "Version: ${{ env.PATCHED_VERSION }}" |
| 131 | + echo "Commit hash: ${{ env.COMMIT_HASH }}" |
| 132 | + export ORG_GRADLE_PROJECT_reactNativeArchitectures="armeabi-v7a,arm64-v8a,x86,x86_64" |
| 133 | + ./gradlew buildReactNativeArtifacts -x lint -x test -x check |
| 134 | + ./gradlew publishReactNativeArtifacts |
| 135 | + env: |
| 136 | + GH_PUBLISH_ACTOR: ${{ github.actor }} |
| 137 | + GH_PUBLISH_TOKEN: ${{ github.token }} |
| 138 | + IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} |
| 139 | + PATCHED_VERSION: ${{ steps.getNewPatchedVersion.outputs.NEW_PATCHED_VERSION }} |
| 140 | + COMMIT_HASH: ${{ github.event.after }} |
| 141 | + |
| 142 | + - name: Announce failed workflow in Slack |
| 143 | + if: ${{ failure() }} |
| 144 | + uses: ./.github/actions/composite/announceFailedWorkflowInSlack |
| 145 | + with: |
| 146 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 147 | + CHANNEL: '#expensify-open-source' |
0 commit comments