Merge pull request #63769 from Expensify/maddylewis-patch-7 #82
This file contains hidden or 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
name: Publish React Native Android Artifacts | |
on: | |
workflow_dispatch: | |
inputs: | |
build_standalone: | |
description: 'Build Standalone artifacts' | |
required: false | |
type: boolean | |
build_hybridapp: | |
description: 'Build HybridApp artifacts' | |
required: false | |
type: boolean | |
push: | |
branches: | |
- main | |
paths: | |
- package.json | |
- patches/react-native+*.patch | |
- patches/@react-native+*.patch | |
- Mobile-Expensify | |
jobs: | |
verifyPatches: | |
name: Verify React Native Patches | |
runs-on: 'ubuntu-latest' | |
outputs: | |
build_targets: ${{ steps.getArtifactBuildTargets.outputs.BUILD_TARGETS }} | |
hybrid_app_patches_hash: ${{ steps.getNewPatchesHash.outputs.HYBRID_APP_HASH }} | |
standalone_patches_hash: ${{ steps.getNewPatchesHash.outputs.STANDALONE_APP_HASH }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 | |
with: | |
submodules: true | |
ref: ${{ github.event.before || 'main' }} | |
token: ${{ secrets.OS_BOTIFY_TOKEN }} | |
- name: Get previous patches hash | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
id: getOldPatchesHash | |
run: | | |
echo "HYBRID_APP_HASH=$(./scripts/compute-patches-hash.sh patches Mobile-Expensify/patches)" >> "$GITHUB_OUTPUT" | |
echo "STANDALONE_APP_HASH=$(./scripts/compute-patches-hash.sh patches)" >> "$GITHUB_OUTPUT" | |
- name: Get previous react-native version | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
id: getOldVersion | |
run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT" | |
- name: Checkout new ref | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
run: | | |
git fetch origin ${{ github.event.after }} --depth=1 | |
git checkout ${{ github.event.after }} | |
git submodule update | |
- name: Get new patches hash | |
id: getNewPatchesHash | |
run: | | |
echo "HYBRID_APP_HASH=$(./scripts/compute-patches-hash.sh patches Mobile-Expensify/patches)" >> "$GITHUB_OUTPUT" | |
echo "STANDALONE_APP_HASH=$(./scripts/compute-patches-hash.sh patches)" >> "$GITHUB_OUTPUT" | |
- name: Get new react-native version | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
id: getNewVersion | |
run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT" | |
- name: Check if version changed | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
id: didVersionChange | |
run: | | |
readonly DID_VERSION_CHANGE=${{ steps.getOldVersion.outputs.VERSION != steps.getNewVersion.outputs.VERSION && 'true' || 'false' }} | |
echo "DID_VERSION_CHANGE=$DID_VERSION_CHANGE" >> "$GITHUB_OUTPUT" | |
if [[ "$DID_VERSION_CHANGE" == 'true' ]]; then | |
echo "::notice::Detected react-native version bump (${{ steps.getOldVersion.outputs.VERSION }} -> ${{ steps.getNewVersion.outputs.VERSION }})" | |
fi | |
- name: Check if patches changed | |
if: ${{ github.event_name != 'workflow_dispatch' }} | |
id: didPatchesChange | |
run: | | |
readonly DID_HYBRID_APP_PATCHES_CHANGE=${{ steps.getOldPatchesHash.outputs.HYBRID_APP_HASH != steps.getNewPatchesHash.outputs.HYBRID_APP_HASH && 'true' || 'false' }} | |
readonly DID_STANDALONE_APP_PATCHES_CHANGE=${{ steps.getOldPatchesHash.outputs.STANDALONE_APP_HASH != steps.getNewPatchesHash.outputs.STANDALONE_APP_HASH && 'true' || 'false' }} | |
echo "DID_HYBRID_APP_PATCHES_CHANGE=$DID_HYBRID_APP_PATCHES_CHANGE" >> "$GITHUB_OUTPUT" | |
echo "DID_STANDALONE_APP_PATCHES_CHANGE=$DID_STANDALONE_APP_PATCHES_CHANGE" >> "$GITHUB_OUTPUT" | |
if [[ "$DID_HYBRID_APP_PATCHES_CHANGE" == 'true' ]]; then | |
echo "::notice::Detected changes in HybridApp patches (${{ steps.getOldPatchesHash.outputs.HYBRID_APP_HASH }} -> ${{ steps.getNewPatchesHash.outputs.HYBRID_APP_HASH }})" | |
fi | |
if [[ "$DID_STANDALONE_APP_PATCHES_CHANGE" == 'true' ]]; then | |
echo "::notice::Detected changes in Standalone NewDot patches (${{ steps.getOldPatchesHash.outputs.STANDALONE_APP_HASH }} -> ${{ steps.getNewPatchesHash.outputs.STANDALONE_APP_HASH }})" | |
fi | |
- name: Get artifact build targets | |
id: getArtifactBuildTargets | |
run: | | |
if [[ '${{ github.event_name }}' == 'workflow_dispatch' ]]; then | |
BUILD_TARGETS=() | |
if [[ '${{ inputs.build_standalone }}' == 'true' ]]; then | |
BUILD_TARGETS+=(false) | |
fi | |
if [[ '${{ inputs.build_hybridapp }}' == 'true' ]]; then | |
BUILD_TARGETS+=(true) | |
fi | |
if [[ ${#BUILD_TARGETS[@]} -ne 0 ]]; then | |
echo "BUILD_TARGETS=$(printf '%s\n' "${BUILD_TARGETS[@]}" | jq -R . | jq -c -s .)" >> "$GITHUB_OUTPUT" | |
fi | |
exit 0 | |
fi | |
# When there is a version change or standalone app patches change, we need to build for both hybrid and standalone | |
if [[ '${{ steps.didVersionChange.outputs.DID_VERSION_CHANGE }}' == 'true' || '${{ steps.didPatchesChange.outputs.DID_STANDALONE_APP_PATCHES_CHANGE }}' == 'true' ]]; then | |
echo "BUILD_TARGETS=[\"true\", \"false\"]" >> "$GITHUB_OUTPUT" | |
elif [[ '${{ steps.didPatchesChange.outputs.DID_HYBRID_APP_PATCHES_CHANGE }}' == 'true' ]]; then | |
echo "BUILD_TARGETS=[\"true\"]" >> "$GITHUB_OUTPUT" | |
fi | |
buildAndPublishReactNativeArtifacts: | |
name: Build and Publish React Native Artifacts | |
runs-on: ${{ github.repository_owner == 'Expensify' && 'ubuntu-latest-xl' || 'ubuntu-latest' }} | |
needs: verifyPatches | |
if: needs.verifyPatches.outputs.build_targets != '' | |
strategy: | |
# Disable fail-fast to prevent cancelling both jobs when only one needs to be stopped due to concurrency limits | |
fail-fast: false | |
matrix: | |
# Dynamically build the matrix based on the build targets | |
is_hybrid: ${{ fromJSON(needs.verifyPatches.outputs.build_targets) }} | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.job }}-${{ matrix.is_hybrid }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 | |
with: | |
submodules: ${{ matrix.is_hybrid }} | |
token: ${{ secrets.OS_BOTIFY_TOKEN }} | |
- name: Setup Node | |
uses: ./.github/actions/composite/setupNode | |
with: | |
IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} | |
- name: Setup Java | |
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 | |
with: | |
distribution: oracle | |
java-version: 17 | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 | |
- name: Determine new patched RN version | |
id: getNewPatchedVersion | |
run: echo "NEW_PATCHED_VERSION=$(./.github/scripts/getNewPatchedRNVersion.sh)" >> "$GITHUB_OUTPUT" | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} | |
- name: Build and publish React Native artifacts | |
working-directory: ${{ matrix.is_hybrid == 'true' && 'Mobile-Expensify/Android' || 'android' }} | |
run: | | |
echo "Starting artifacts build for ${{ matrix.is_hybrid == 'true' && 'HybridApp' || 'NewDot Standalone' }}" | |
echo "Version: ${{ env.PATCHED_VERSION }}" | |
echo "Patches hash: ${{ env.PATCHES_HASH }}" | |
export ORG_GRADLE_PROJECT_reactNativeArchitectures="armeabi-v7a,arm64-v8a,x86,x86_64" | |
./gradlew buildReactNativeArtifacts -PpatchedArtifacts.forceBuildFromSource=true -x lint -x test -x check | |
./gradlew publishReactNativeArtifacts -PpatchedArtifacts.forceBuildFromSource=true | |
env: | |
GH_PUBLISH_ACTOR: ${{ github.actor }} | |
GH_PUBLISH_TOKEN: ${{ github.token }} | |
IS_HYBRID_BUILD: ${{ matrix.is_hybrid }} | |
PATCHED_VERSION: ${{ steps.getNewPatchedVersion.outputs.NEW_PATCHED_VERSION }} | |
PATCHES_HASH: ${{ matrix.is_hybrid == 'true' && needs.verifyPatches.outputs.hybrid_app_patches_hash || needs.verifyPatches.outputs.standalone_patches_hash }} | |
- name: Announce failed workflow in Slack | |
if: ${{ failure() }} | |
uses: ./.github/actions/composite/announceFailedWorkflowInSlack | |
with: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
CHANNEL: '#expensify-open-source' |