From 971eb9ab2ac800467d120c5498c7c7730fb66195 Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <janeknowakowski9@gmail.com>
Date: Mon, 3 Feb 2025 14:07:22 +0100
Subject: [PATCH 1/8] Enable profiling PR builds

---
 .github/workflows/compareNDandODbuilds.yml | 90 +++++++++++++++++++++-
 1 file changed, 88 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index 51ba44a192e9..dbba17dfda6c 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -2,24 +2,108 @@ name: Build and profile Android apps
 
 on:
   workflow_dispatch:
+    inputs:
+      PULL_REQUEST_NUMBER:
+        description: Pull Request number for correct placement of app
+        required: false
+        default: ''
+      OLD_DOT_PULL_REQUEST_NUMBER:
+        description: Old Dot Pull Request number for correct placement of app
+        required: false
+        default: ''
 
 jobs:
+  getBranchRef:
+    runs-on: ubuntu-latest
+    outputs:
+      REF: ${{ steps.getHeadRef.outputs.REF }}
+    steps:
+      - name: Get ND PR commit SHA
+        id: getHeadRef
+        run: |
+          set -e
+          if [[ ${{ github.event.inputs.PULL_REQUEST_NUMBER }} == ' ']]; then
+            echo "REF=" >> "$GITHUB_OUTPUT"
+          else
+            echo "REF=$(gh pr view ${{ github.event.inputs.PULL_REQUEST_NUMBER }} --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"
+          fi
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+    
+  getOldDotBranchRef:
+    runs-on: ubuntu-latest
+    outputs:
+      OLD_DOT_REF: ${{ steps.getHeadRef.outputs.REF }}
+    steps:
+      - name: Get OD PR commit SHA
+        id: getHeadRef
+        run: |
+          set -e
+          if [[ ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} == ' ']]; then
+            echo "REF=" >> "$GITHUB_OUTPUT"
+          else
+            echo "REF=$(gh pr view ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} -R Expensify/Mobile-Expensify --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"
+          fi
+        env:
+          GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
+  
+  
+  postGitHubCommentBuildStarted:
+    runs-on: ubuntu-latest
+    needs: [getBranchRef, getOldDotBranchRef]
+    steps:
+      - name: Add comment to ND PR 
+        if: ${{ github.event.inputs.PULL_REQUEST_NUMBER != ''}}
+        uses: actions/github-script@v7
+        with:
+          github-token: ${{ github.token }}
+          script: |
+            const workflowURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
+            github.rest.issues.createComment({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: ${{ github.event.inputs.PULL_REQUEST_NUMBER }},
+              body: `🚧 @${{ github.actor }} has triggered build profiling. You can view the [workflow run here](${workflowURL}).`
+            });  
+      
+      - name: Add comment to OD PR 
+        if: ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER != '' }}
+        uses: actions/github-script@v7
+        with:
+          github-token: ${{ github.token }}
+          script: |
+            const workflowURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
+            github.rest.issues.createComment({
+              owner: context.repo.owner,
+              repo: 'Mobile-Expensify',
+              issue_number: ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }},
+              body: `🚧 @${{ github.actor }} has triggered build profiling. You can view the [workflow run here](${workflowURL}).`
+            });
+       
   buildHybridAppAndroid:
     name: Build HybridApp Android
+    needs: [getBranchRef, getOldDotBranchRef]
     runs-on: ubuntu-latest-xl
     steps:
       - name: Checkout
         uses: actions/checkout@v4
         with:
           submodules: true
+          ref: ${{ needs.getBranchRef || 'main' }}
           token: ${{ secrets.OS_BOTIFY_TOKEN }}
+          fetch-depth: 0
 
       - name: Update submodule to match main
         run: |
           git submodule update --init --remote
+      
+      - name: Checkout Old Dot if PR specified
+        if: ${{ needs.getOldDotBranchRef.outputs.OLD_DOT_REF != '' }}
+        run: |
           cd Mobile-Expensify
-          git fetch
-          git checkout main
+          git fetch origin ${{ needs.getOldDotBranchRef.outputs.OLD_DOT_REF }}
+          git checkout ${{ needs.getOldDotBranchRef.outputs.OLD_DOT_REF }}
+                
 
       - name: Configure MapBox SDK
         run: ./scripts/setup-mapbox-sdk.sh ${{ secrets.MAPBOX_SDK_DOWNLOAD_TOKEN }}
@@ -88,12 +172,14 @@ jobs:
 
   buildStandaloneAndroid:
     name: Build Standalone Android
+    needs: [getBranchRef]
     runs-on: ubuntu-latest-xl
     steps:
       - name: Checkout
         uses: actions/checkout@v4
         with:
           token: ${{ secrets.OS_BOTIFY_TOKEN }}
+          ref: ${{ needs.getBranchRef || 'main' }}
 
       - name: Configure MapBox SDK
         run: ./scripts/setup-mapbox-sdk.sh ${{ secrets.MAPBOX_SDK_DOWNLOAD_TOKEN }}

From c98a41dd46c335cc449341d1bc7a40f88eed186b Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <janeknowakowski9@gmail.com>
Date: Mon, 3 Feb 2025 14:21:02 +0100
Subject: [PATCH 2/8] Fix workflow syntax

---
 .github/workflows/compareNDandODbuilds.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index dbba17dfda6c..a6791a88fb9c 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -22,7 +22,7 @@ jobs:
         id: getHeadRef
         run: |
           set -e
-          if [[ ${{ github.event.inputs.PULL_REQUEST_NUMBER }} == ' ']]; then
+          if [[ ${{ github.event.inputs.PULL_REQUEST_NUMBER }} == '' ]]; then
             echo "REF=" >> "$GITHUB_OUTPUT"
           else
             echo "REF=$(gh pr view ${{ github.event.inputs.PULL_REQUEST_NUMBER }} --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"
@@ -39,7 +39,7 @@ jobs:
         id: getHeadRef
         run: |
           set -e
-          if [[ ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} == ' ']]; then
+          if [[ ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} == '' ]]; then
             echo "REF=" >> "$GITHUB_OUTPUT"
           else
             echo "REF=$(gh pr view ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} -R Expensify/Mobile-Expensify --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"

From e1cd0c928721bc050ec772b7fa47e5ab25c74728 Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <janeknowakowski9@gmail.com>
Date: Thu, 6 Feb 2025 14:44:10 +0100
Subject: [PATCH 3/8] Update descriptions and fix syntax error

---
 .github/workflows/compareNDandODbuilds.yml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index a6791a88fb9c..0a51bc768272 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -4,11 +4,11 @@ on:
   workflow_dispatch:
     inputs:
       PULL_REQUEST_NUMBER:
-        description: Pull Request number for correct placement of app
+        description: Pull request number to build the app from
         required: false
         default: ''
       OLD_DOT_PULL_REQUEST_NUMBER:
-        description: Old Dot Pull Request number for correct placement of app
+        description: Old Dot Pull request number to build the app from
         required: false
         default: ''
 
@@ -22,7 +22,7 @@ jobs:
         id: getHeadRef
         run: |
           set -e
-          if [[ ${{ github.event.inputs.PULL_REQUEST_NUMBER }} == '' ]]; then
+          if [[ -z "${{ github.event.inputs.PULL_REQUEST_NUMBER }}" ]]; then
             echo "REF=" >> "$GITHUB_OUTPUT"
           else
             echo "REF=$(gh pr view ${{ github.event.inputs.PULL_REQUEST_NUMBER }} --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"
@@ -39,7 +39,7 @@ jobs:
         id: getHeadRef
         run: |
           set -e
-          if [[ ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} == '' ]]; then
+          if [[ -z "${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }}" ]]; then
             echo "REF=" >> "$GITHUB_OUTPUT"
           else
             echo "REF=$(gh pr view ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER }} -R Expensify/Mobile-Expensify --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"

From 287b4c2790b8e36f35e377b4781dd0679ab602ab Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <janeknowakowski9@gmail.com>
Date: Fri, 7 Feb 2025 08:14:05 +0100
Subject: [PATCH 4/8] Fix checkout step

---
 .github/workflows/compareNDandODbuilds.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index 0a51bc768272..aed4567094d7 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -89,7 +89,7 @@ jobs:
         uses: actions/checkout@v4
         with:
           submodules: true
-          ref: ${{ needs.getBranchRef || 'main' }}
+          ref: ${{ needs.getBranchRef.outputs.REF || 'main' }}
           token: ${{ secrets.OS_BOTIFY_TOKEN }}
           fetch-depth: 0
 
@@ -179,7 +179,7 @@ jobs:
         uses: actions/checkout@v4
         with:
           token: ${{ secrets.OS_BOTIFY_TOKEN }}
-          ref: ${{ needs.getBranchRef || 'main' }}
+          ref: ${{ needs.getBranchRef.outputs.REF || 'main' }}
 
       - name: Configure MapBox SDK
         run: ./scripts/setup-mapbox-sdk.sh ${{ secrets.MAPBOX_SDK_DOWNLOAD_TOKEN }}

From 57460ccd29503e6cbfd7152eeb06fe0602fdc756 Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <janeknowakowski9@gmail.com>
Date: Fri, 14 Feb 2025 08:19:33 +0100
Subject: [PATCH 5/8] Update workflow

---
 .github/workflows/compareNDandODbuilds.yml | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index aed4567094d7..aaef5c8b82ad 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -18,6 +18,9 @@ jobs:
     outputs:
       REF: ${{ steps.getHeadRef.outputs.REF }}
     steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
       - name: Get ND PR commit SHA
         id: getHeadRef
         run: |
@@ -70,7 +73,7 @@ jobs:
         if: ${{ github.event.inputs.OLD_DOT_PULL_REQUEST_NUMBER != '' }}
         uses: actions/github-script@v7
         with:
-          github-token: ${{ github.token }}
+          github-token: ${{ secrets.OS_BOTIFY_TOKEN }}
           script: |
             const workflowURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
             github.rest.issues.createComment({
@@ -189,10 +192,15 @@ jobs:
         uses: ./.github/actions/composite/setupNode
         with:
           IS_HYBRID_BUILD: 'false'
+     
+      - name: Install 1Password CLI
+        uses: 1password/install-cli-action@v1
 
-      - name: Decrypt keystore to sign the APK/AAB
-        run: gpg --batch --yes --decrypt --passphrase="${{ secrets.LARGE_SECRET_PASSPHRASE }}" --output my-upload-key.keystore my-upload-key.keystore.gpg
+      - name: Load files from 1Password
         working-directory: android/app
+        env:
+          OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
+        run: op read "op://${{ vars.OP_VAULT }}/New Expensify my-upload-key.keystore/my-upload-key.keystore" --force --out-file ./my-upload-key.keystore
 
       - name: Build Android Release
         working-directory: android

From 7d5629bd156f9f11ff621e334222c56ed550a4c6 Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <janeknowakowski9@gmail.com>
Date: Mon, 17 Feb 2025 15:42:52 +0100
Subject: [PATCH 6/8] Use correct keystore

---
 .github/workflows/compareNDandODbuilds.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index 2305623bee61..0a16f9d42d9b 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -145,7 +145,7 @@ jobs:
           OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
         run: |
           op read "op://${{ vars.OP_VAULT }}/android-fastlane-json-key.json/android-fastlane-json-key.json" --force --out-file ./android-fastlane-json-key.json
-          op read "op://${{ vars.OP_VAULT }}/New Expensify my-upload-key.keystore/my-upload-key.keystore" --force --out-file ./my-upload-key.keystore
+          op read "op://${{ vars.OP_VAULT }}/upload-key.keystore/upload-key.keystore" --force --out-file ./upload-key.keystore
           
           # Copy the keystore to the Android directory for Fullstory
           cp ./upload-key.keystore Mobile-Expensify/Android 

From d8534d77ca7962e6c391436ed25e09fe9b0d1322 Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <56261019+jnowakow@users.noreply.github.com>
Date: Wed, 19 Feb 2025 08:40:24 +0100
Subject: [PATCH 7/8] Update description

Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com>
---
 .github/workflows/compareNDandODbuilds.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index 0a16f9d42d9b..39b01c4a4b64 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -100,7 +100,7 @@ jobs:
         run: |
           git submodule update --init --remote
       
-      - name: Checkout Old Dot if PR specified
+      - name: Checkout OldDot if PR specified
         if: ${{ needs.getOldDotBranchRef.outputs.OLD_DOT_REF != '' }}
         run: |
           cd Mobile-Expensify

From 801c4327a1c9208862f44d1366654b9bcf967031 Mon Sep 17 00:00:00 2001
From: Jan Nowakowski <56261019+jnowakow@users.noreply.github.com>
Date: Wed, 19 Feb 2025 08:49:15 +0100
Subject: [PATCH 8/8] Update description

Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com>
---
 .github/workflows/compareNDandODbuilds.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/compareNDandODbuilds.yml b/.github/workflows/compareNDandODbuilds.yml
index 39b01c4a4b64..bb61f1ba58cb 100644
--- a/.github/workflows/compareNDandODbuilds.yml
+++ b/.github/workflows/compareNDandODbuilds.yml
@@ -21,7 +21,7 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v4
 
-      - name: Get ND PR commit SHA
+      - name: Get NewDot PR commit SHA
         id: getHeadRef
         run: |
           set -e
