Skip to content

[No QA] Refactor artifacts workflow to enable valid usage of concurrency #62101

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 56 additions & 41 deletions .github/workflows/publishReactNativeAndroidArtifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,28 @@ on:
- Mobile-Expensify

jobs:
publish:
runs-on: ${{ github.repository_owner == 'Expensify' && 'ubuntu-latest-xl' || 'ubuntu-latest' }}
strategy:
matrix:
is_hybrid: [true, false]
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:
# v4
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
with:
submodules: ${{ matrix.is_hybrid }}
submodules: true
ref: ${{ github.event.before }}
token: ${{ secrets.OS_BOTIFY_TOKEN }}

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

id: getOldVersion
run: echo "VERSION=$(jq -r '.dependencies["react-native"]' package.json)" >> "$GITHUB_OUTPUT"

Expand All @@ -48,11 +45,8 @@ jobs:
- 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
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
id: getNewVersion
Expand All @@ -70,54 +64,75 @@ jobs:
- name: Check if patches changed
id: didPatchesChange
run: |
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 }})"
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: Check if we should build and publish the package
id: shouldPublish
- name: Get artifact build targets
id: getArtifactBuildTargets
run: |
if [[ '${{ steps.didVersionChange.outputs.DID_VERSION_CHANGE }}' == 'true' || '${{ steps.didPatchesChange.outputs.DID_PATCHES_CHANGE }}' == 'true' ]]; then
echo "SHOULD_PUBLISH=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::No relevant changes, skipping publishing a new React Native build"
echo "SHOULD_PUBLISH=false" >> "$GITHUB_OUTPUT"
# 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
if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }}
uses: ./.github/actions/composite/setupNode
with:
IS_HYBRID_BUILD: ${{ matrix.is_hybrid }}

# v4
- name: Setup Java
if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }}
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12
with:
distribution: oracle
java-version: 17

# v4
- name: Setup Gradle
if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }}
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244

- name: Determine new patched RN version
if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }}
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 RN artifacts
if: ${{ steps.shouldPublish.outputs.SHOULD_PUBLISH == 'true' }}
working-directory: ${{ matrix.is_hybrid && 'Mobile-Expensify/Android' || 'android' }}
- 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 && 'HybridApp' || 'NewDot Standalone' }}"
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"
Expand All @@ -128,7 +143,7 @@ jobs:
GH_PUBLISH_TOKEN: ${{ github.token }}
IS_HYBRID_BUILD: ${{ matrix.is_hybrid }}
PATCHED_VERSION: ${{ steps.getNewPatchedVersion.outputs.NEW_PATCHED_VERSION }}
PATCHES_HASH: ${{ steps.getNewPatchesHash.outputs.HASH }}
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() }}
Expand Down
Loading