From ff7e5d402d2003acef6efb864ab8241ea8ad3447 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 10:01:04 +0100
Subject: [PATCH 01/19] add web job to testBuild workflow

---
 .../scripts/createCloudfrontDistribution.sh   | 20 +++++++++
 .github/workflows/testBuild.yml               | 41 +++++++++++++++++--
 2 files changed, 57 insertions(+), 4 deletions(-)
 create mode 100644 .github/scripts/createCloudfrontDistribution.sh

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
new file mode 100644
index 000000000000..08354f4a210e
--- /dev/null
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+set -e
+
+if [[ $(aws s3 ls s3://ad-hoc-expensify-cash/web/$1 | head) ]]; then 
+    exit 0;
+else
+    echo $(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com) >> cloudfront.config.json
+
+    CONFIG=$(cat "./cloudfront.config.json")
+    DISTRIBUTION_ID=$(echo $CONFIG | jq -r .Distribution.Id) 
+    ETAG=$(echo $CONFIG | jq -r .ETag) 
+
+    echo $CONFIG | jq -r .Distribution.DistributionConfig >> dist.config.json
+
+    tmp=$(mktemp /tmp/tmp.XXXXXXX)
+    NEW_ORIGIN_PATH=$(echo "/web/$1")
+    jq --arg originPath "$NEW_ORIGIN_PATH" '(.Origins.Items[] | select(.OriginPath == "")).OriginPath |= $originPath' dist.config.json  > "$tmp" && mv "$tmp"  dist.config.json
+
+    aws cloudfront update-distribution --id $DISTRIBUTION_ID --if-match $ETAG --distribution-config file://dist.config.json 
+fi
\ No newline at end of file
diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index e2af94a00472..92c807254704 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -160,6 +160,39 @@ jobs:
           AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
           AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
           PULL_REQUEST_NUMBER: ${{ github.event.number }}
+  web:
+    name: Build and deploy Web
+    needs: validateActor
+    if: ${{ fromJSON(needs.validateActor.outputs.IS_TEAM_MEMBER) }}
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
+        with:
+          fetch-depth: 0
+          ref: ${{ github.event.pull_request.head.sha }}
+      - uses: Expensify/App/.github/actions/composite/setupNode@main
+      - name: Configure AWS Credentials
+        uses: Expensify/App/.github/actions/composite/configureAwsCredentials@main
+        with:
+          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
+          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
+
+      - name: Build web for testing
+        run: npm run build-staging
+
+      - name: Build docs
+        run: npm run storybook-build
+        continue-on-error: true
+
+      - name: Create CloudFront distribution for the PR if needed
+        run: ./.github/scripts/verifyActions.sh "$PULL_REQUEST_NUMBER"
+        env:
+          PULL_REQUEST_NUMBER: ${{ github.event.number }}
+
+      - name: Deploy to S3 for internal testing
+        run: aws s3 cp --recursive --acl public-read "$GITHUB_WORKSPACE"/dist s3://ad-hoc-expensify-cash/web/"$PULL_REQUEST_NUMBER"
+        env:
+          PULL_REQUEST_NUMBER: ${{ github.event.number }}
 
   postGithubComment:
     runs-on: ubuntu-latest
@@ -191,9 +224,9 @@ jobs:
         run: |
           gh pr comment --body \
           ":test_tube::test_tube: Use the links below to test this build in android and iOS. Happy testing! :test_tube::test_tube:
-          | android :robot:  | iOS :apple: | desktop :computer: |
-          | ------------- | ------------- | ------------- | 
-          | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg |
-          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg) |"
+          | android :robot:  | iOS :apple: | desktop :computer: | :spider_web: |
+          | ------------- | ------------- | ------------- | ------------- | 
+          | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/web/${{github.event.number}}/index.html |
+          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg) | ![web](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/web/${{github.event.number}}/index.html) |"
         env:
           GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

From 5d1200c881de90938dda1b491631044008456af4 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 10:05:13 +0100
Subject: [PATCH 02/19] new line fix

---
 .github/scripts/createCloudfrontDistribution.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index 08354f4a210e..4d6b5bdbaaa6 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -17,4 +17,4 @@ else
     jq --arg originPath "$NEW_ORIGIN_PATH" '(.Origins.Items[] | select(.OriginPath == "")).OriginPath |= $originPath' dist.config.json  > "$tmp" && mv "$tmp"  dist.config.json
 
     aws cloudfront update-distribution --id $DISTRIBUTION_ID --if-match $ETAG --distribution-config file://dist.config.json 
-fi
\ No newline at end of file
+fi

From cdc8718d9bc32988183c6d91112d1b9aedaf332e Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 11:57:57 +0100
Subject: [PATCH 03/19] fix cloudfront urls

---
 .github/scripts/createCloudfrontDistribution.sh |  2 +-
 .github/workflows/testBuild.yml                 | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index 4d6b5bdbaaa6..7a0738ed3750 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -4,7 +4,7 @@ set -e
 if [[ $(aws s3 ls s3://ad-hoc-expensify-cash/web/$1 | head) ]]; then 
     exit 0;
 else
-    echo $(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com) >> cloudfront.config.json
+    echo $(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html) >> cloudfront.config.json
 
     CONFIG=$(cat "./cloudfront.config.json")
     DISTRIBUTION_ID=$(echo $CONFIG | jq -r .Distribution.Id) 
diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 92c807254704..124cde5364b4 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -219,6 +219,14 @@ jobs:
           content_ios="${content_ios//$'\n'/'%0A'}"
           content_ios="${content_ios//$'\r'/'%0D'}"
           echo "ios_paths=$content_ios" >> "$GITHUB_OUTPUT"
+      
+      - name: Get CloudFront URL
+        id: get_cloudfront_url
+        run: |
+          cloudfront_url=$(echo $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$PULL_REQUEST_NUMBER']].DomainName" --output text))
+          echo "cloudfront_url=$cloudfront_url" >> "$GITHUB_OUTPUT"
+        env:
+          PULL_REQUEST_NUMBER: ${{github.event.number}}
 
       - name: Publish links to apps for download
         run: |
@@ -226,7 +234,7 @@ jobs:
           ":test_tube::test_tube: Use the links below to test this build in android and iOS. Happy testing! :test_tube::test_tube:
           | android :robot:  | iOS :apple: | desktop :computer: | :spider_web: |
           | ------------- | ------------- | ------------- | ------------- | 
-          | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/web/${{github.event.number}}/index.html |
-          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg) | ![web](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/web/${{github.event.number}}/index.html) |"
+          | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg | https://${{steps.get_cloudfront_url.outputs.cloudfront_url}} |
+          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg) | ![web](https://${{steps.get_cloudfront_url.outputs.cloudfront_url}}) |"
         env:
           GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

From 89e2f2546db276770411f2c8b726db2b89365591 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 12:03:34 +0100
Subject: [PATCH 04/19] add web to comment job needs

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 124cde5364b4..873482ebc491 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -197,7 +197,7 @@ jobs:
   postGithubComment:
     runs-on: ubuntu-latest
     name: Post a GitHub comment with app download links for testing
-    needs: [android, ios, desktop]
+    needs: [android, ios, desktop, web]
     steps:
       - name: Checkout
         uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

From 42c776e4083e19272204c3a3b23e38de3ffe8522 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 12:12:06 +0100
Subject: [PATCH 05/19] fix github actions linter

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 873482ebc491..50f6360983fc 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -223,7 +223,7 @@ jobs:
       - name: Get CloudFront URL
         id: get_cloudfront_url
         run: |
-          cloudfront_url=$(echo $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$PULL_REQUEST_NUMBER']].DomainName" --output text))
+          cloudfront_url=$(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$PULL_REQUEST_NUMBER']].DomainName" --output text)
           echo "cloudfront_url=$cloudfront_url" >> "$GITHUB_OUTPUT"
         env:
           PULL_REQUEST_NUMBER: ${{github.event.number}}

From 7a30941d37dc21cbd7387c83b7a92391ce9b5116 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 14:02:40 +0100
Subject: [PATCH 06/19] improve distribution existence check

---
 .github/scripts/createCloudfrontDistribution.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index 7a0738ed3750..ff1a5ed71061 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -1,7 +1,8 @@
 #!/bin/bash
 set -e
 
-if [[ $(aws s3 ls s3://ad-hoc-expensify-cash/web/$1 | head) ]]; then 
+if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].DomainName" --output text | head) ]]; then 
+    echo "Distribution for PR #$1 already exists!"
     exit 0;
 else
     echo $(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html) >> cloudfront.config.json

From f936a8c3488a4cfdb51a48f9a0aaecb665a15ee6 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 14:04:45 +0100
Subject: [PATCH 07/19] move creating distribution after deployment

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 50f6360983fc..e3f329e6aed2 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -184,13 +184,13 @@ jobs:
         run: npm run storybook-build
         continue-on-error: true
 
-      - name: Create CloudFront distribution for the PR if needed
-        run: ./.github/scripts/verifyActions.sh "$PULL_REQUEST_NUMBER"
+      - name: Deploy to S3 for internal testing
+        run: aws s3 cp --recursive --acl public-read "$GITHUB_WORKSPACE"/dist s3://ad-hoc-expensify-cash/web/"$PULL_REQUEST_NUMBER"
         env:
           PULL_REQUEST_NUMBER: ${{ github.event.number }}
 
-      - name: Deploy to S3 for internal testing
-        run: aws s3 cp --recursive --acl public-read "$GITHUB_WORKSPACE"/dist s3://ad-hoc-expensify-cash/web/"$PULL_REQUEST_NUMBER"
+      - name: Create CloudFront distribution for the PR if needed
+        run: ./.github/scripts/verifyActions.sh "$PULL_REQUEST_NUMBER"
         env:
           PULL_REQUEST_NUMBER: ${{ github.event.number }}
 

From d0d21d2865f695e498b39ac53e16f1d59ca76387 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 14:51:32 +0100
Subject: [PATCH 08/19] fix condition in createCloudfrontDistribution

---
 .github/scripts/createCloudfrontDistribution.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index ff1a5ed71061..571caf8f65ed 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 set -e
 
-if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].DomainName" --output text | head) ]]; then 
+if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text) ]] && [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != null ]] ; then 
     echo "Distribution for PR #$1 already exists!"
     exit 0;
 else

From 1b87de52d59e31696f3f5ab7101aff6a00f97c00 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 15:06:50 +0100
Subject: [PATCH 09/19] switch condition order

---
 .github/scripts/createCloudfrontDistribution.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index 571caf8f65ed..89f57abb877e 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 set -e
 
-if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text) ]] && [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != null ]] ; then 
+if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != null ]] && [[ $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text) ]] ; then 
     echo "Distribution for PR #$1 already exists!"
     exit 0;
 else

From 91ddfd5ada2de71280125319e26dd41e2a17d3dc Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Tue, 6 Dec 2022 15:43:49 +0100
Subject: [PATCH 10/19] add cache invalidation

---
 .github/scripts/createCloudfrontDistribution.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index 89f57abb877e..01e7a2c9b629 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -1,10 +1,14 @@
 #!/bin/bash
 set -e
 
-if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != null ]] && [[ $(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text) ]] ; then 
-    echo "Distribution for PR #$1 already exists!"
+DISTRIBUTION_ID=$(echo aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text)
+
+if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != null ]] && [[ $DISTRIBUTION_ID ]] ; then 
+    echo "Distribution for PR #$1 already exists! Invalidating cache..."
+    aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/'
     exit 0;
 else
+    echo "A new distribution for PR #$1 is being created"
     echo $(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html) >> cloudfront.config.json
 
     CONFIG=$(cat "./cloudfront.config.json")

From 713b9093d3ba0eef1f2d0f42fb3002d2f6eda364 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 7 Dec 2022 10:43:37 +0100
Subject: [PATCH 11/19] fix wrong script passed

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index e3f329e6aed2..afccb254b042 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -190,7 +190,7 @@ jobs:
           PULL_REQUEST_NUMBER: ${{ github.event.number }}
 
       - name: Create CloudFront distribution for the PR if needed
-        run: ./.github/scripts/verifyActions.sh "$PULL_REQUEST_NUMBER"
+        run: ./.github/scripts/createCloudfrontDistribution.sh "$PULL_REQUEST_NUMBER"
         env:
           PULL_REQUEST_NUMBER: ${{ github.event.number }}
 

From a9daebec5cbdbb37ac1e836763260bbca8f7de70 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 7 Dec 2022 13:29:19 +0100
Subject: [PATCH 12/19] improve createCloudfrontDistribution

---
 .github/scripts/createCloudfrontDistribution.sh | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index 01e7a2c9b629..dbc30899d75b 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -1,21 +1,20 @@
 #!/bin/bash
 set -e
 
-DISTRIBUTION_ID=$(echo aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text)
+DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text)
 
-if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != null ]] && [[ $DISTRIBUTION_ID ]] ; then 
-    echo "Distribution for PR #$1 already exists! Invalidating cache..."
+if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != "null" ]] && [[ $DISTRIBUTION_ID ]] ; then 
+    echo "Distribution for PR #$1 already exists!"
     aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/'
-    exit 0;
+    exit 0
 else
     echo "A new distribution for PR #$1 is being created"
-    echo $(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html) >> cloudfront.config.json
+    CLOUDFRONT_CONFIG=$(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html)
 
-    CONFIG=$(cat "./cloudfront.config.json")
-    DISTRIBUTION_ID=$(echo $CONFIG | jq -r .Distribution.Id) 
-    ETAG=$(echo $CONFIG | jq -r .ETag) 
+    DISTRIBUTION_ID=$(jq -r .Distribution.Id <<< $CLOUDFRONT_CONFIG) 
+    ETAG=$(jq -r .ETag <<< $CLOUDFRONT_CONFIG) 
 
-    echo $CONFIG | jq -r .Distribution.DistributionConfig >> dist.config.json
+    echo $CLOUDFRONT_CONFIG | jq -r .Distribution.DistributionConfig >> dist.config.json
 
     tmp=$(mktemp /tmp/tmp.XXXXXXX)
     NEW_ORIGIN_PATH=$(echo "/web/$1")

From c6127cabf5ef222c23d4c55920bc8e713b1488d8 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 7 Dec 2022 15:04:30 +0100
Subject: [PATCH 13/19] fix linting issues

---
 .github/scripts/createCloudfrontDistribution.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
index dbc30899d75b..fbc11af1c665 100644
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ b/.github/scripts/createCloudfrontDistribution.sh
@@ -3,22 +3,22 @@ set -e
 
 DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text)
 
-if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != "null" ]] && [[ $DISTRIBUTION_ID ]] ; then 
+if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != "null" ]] && [[ "$DISTRIBUTION_ID" ]] ; then 
     echo "Distribution for PR #$1 already exists!"
-    aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/'
+    aws cloudfront create-invalidation --distribution-id "$DISTRIBUTION_ID" --paths '/'
     exit 0
 else
     echo "A new distribution for PR #$1 is being created"
     CLOUDFRONT_CONFIG=$(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html)
 
-    DISTRIBUTION_ID=$(jq -r .Distribution.Id <<< $CLOUDFRONT_CONFIG) 
-    ETAG=$(jq -r .ETag <<< $CLOUDFRONT_CONFIG) 
+    DISTRIBUTION_ID=$(jq -r .Distribution.Id <<< "$CLOUDFRONT_CONFIG") 
+    ETAG=$(jq -r .ETag <<< "$CLOUDFRONT_CONFIG") 
 
-    echo $CLOUDFRONT_CONFIG | jq -r .Distribution.DistributionConfig >> dist.config.json
+    echo "$CLOUDFRONT_CONFIG" | jq -r .Distribution.DistributionConfig >> dist.config.json
 
     tmp=$(mktemp /tmp/tmp.XXXXXXX)
-    NEW_ORIGIN_PATH=$(echo "/web/$1")
+    NEW_ORIGIN_PATH="/web/$1"
     jq --arg originPath "$NEW_ORIGIN_PATH" '(.Origins.Items[] | select(.OriginPath == "")).OriginPath |= $originPath' dist.config.json  > "$tmp" && mv "$tmp"  dist.config.json
 
-    aws cloudfront update-distribution --id $DISTRIBUTION_ID --if-match $ETAG --distribution-config file://dist.config.json 
+    aws cloudfront update-distribution --id "$DISTRIBUTION_ID" --if-match "$ETAG" --distribution-config file://dist.config.json 
 fi

From 721ed6e47d9453aada046480008b49b480f07cf7 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 7 Dec 2022 15:20:00 +0100
Subject: [PATCH 14/19] fix wrong path to ios app

---
 fastlane/Fastfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fastlane/Fastfile b/fastlane/Fastfile
index 32e10fddc413..7677dd14b13f 100644
--- a/fastlane/Fastfile
+++ b/fastlane/Fastfile
@@ -161,7 +161,7 @@ platform :ios do
       region: ENV['S3_REGION'],
 
       ipa: lane_context[SharedValues::IPA_OUTPUT_PATH],
-      app_directory: "android/#{ENV['PULL_REQUEST_NUMBER']}",
+      app_directory: "ios/#{ENV['PULL_REQUEST_NUMBER']}",
     )
 
     sh("echo '{\"ipa_path\": \"#{lane_context[SharedValues::S3_IPA_OUTPUT_PATH]}\",\"html_path\": \"#{lane_context[SharedValues::S3_HTML_OUTPUT_PATH]}\"}' > ../ios_paths.json")

From f5df70a22aed0b6d630ab4c825b957bde50e9418 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 7 Dec 2022 17:53:54 +0100
Subject: [PATCH 15/19] fix qr code urls

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index afccb254b042..41a115e2a32b 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -235,6 +235,6 @@ jobs:
           | android :robot:  | iOS :apple: | desktop :computer: | :spider_web: |
           | ------------- | ------------- | ------------- | ------------- | 
           | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg | https://${{steps.get_cloudfront_url.outputs.cloudfront_url}} |
-          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg) | ![web](https://${{steps.get_cloudfront_url.outputs.cloudfront_url}}) |"
+          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/${{github.event.number}}/NewExpensify.dmg) | ![web](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://${{steps.get_cloudfront_url.outputs.cloudfront_url}}) |"
         env:
           GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

From 2635be79b2221f0cfb6c75c6b80c89e3a38d73dc Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 14 Dec 2022 11:08:53 +0100
Subject: [PATCH 16/19] fix needs in web job

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 68dd2666d8a5..194baee8cc3a 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -191,7 +191,7 @@ jobs:
 
   web:
     name: Build and deploy Web
-    needs: validateActor
+    needs: [validateActor, getBranchRef]
     if: ${{ fromJSON(needs.validateActor.outputs.IS_TEAM_MEMBER) }}
     env:
       PULL_REQUEST_NUMBER: ${{ github.event.number || github.event.inputs.PULL_REQUEST_NUMBER }}

From d356c7daff27c176972fd9c97da1772805a4ed91 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 14 Dec 2022 11:09:59 +0100
Subject: [PATCH 17/19] fix comment

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 194baee8cc3a..d49092616ece 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -268,7 +268,7 @@ jobs:
         run: |
           gh pr comment --body \
           ":test_tube::test_tube: Use the links below to test this build in android and iOS. Happy testing! :test_tube::test_tube:
-          | android :robot:  | iOS :apple: | desktop :computer: | :spider_web: |
+          | android :robot:  | iOS :apple: | desktop :computer: | web :spider_web: |
           | ------------- | ------------- | ------------- | ------------- | 
           | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/$PULL_REQUEST_NUMBER/NewExpensify.dmg | https://${{steps.get_cloudfront_url.outputs.cloudfront_url}} |
           | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://ad-hoc-expensify-cash.us-east-1.amazonaws.com/desktop/$PULL_REQUEST_NUMBER/NewExpensify.dmg) | ![web](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://${{steps.get_cloudfront_url.outputs.cloudfront_url}}) |"

From d54bd4bfeafac98609f5b44503402c1d846b0e48 Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Wed, 14 Dec 2022 21:19:32 +0100
Subject: [PATCH 18/19] align refs

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

diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 916e4d5bfd61..1ad2e49110ab 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -200,7 +200,7 @@ jobs:
       - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
         with:
           fetch-depth: 0
-          ref: ${{ github.head_ref || needs.getBranchRef.outputs.REF }}
+          ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }}
       - uses: Expensify/App/.github/actions/composite/setupNode@main
       - name: Configure AWS Credentials
         uses: Expensify/App/.github/actions/composite/configureAwsCredentials@main

From 204af9c42f7790ad934b26072ae87ca8f64d393f Mon Sep 17 00:00:00 2001
From: staszekscp <mariusz.stanisz@swmansion.com>
Date: Fri, 16 Dec 2022 12:24:41 +0100
Subject: [PATCH 19/19] remove cloudfront distribution and update the web app
 url

---
 .../scripts/createCloudfrontDistribution.sh   | 24 -------------------
 .github/workflows/testBuild.yml               | 20 ++++++----------
 2 files changed, 7 insertions(+), 37 deletions(-)
 delete mode 100644 .github/scripts/createCloudfrontDistribution.sh

diff --git a/.github/scripts/createCloudfrontDistribution.sh b/.github/scripts/createCloudfrontDistribution.sh
deleted file mode 100644
index fbc11af1c665..000000000000
--- a/.github/scripts/createCloudfrontDistribution.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-set -e
-
-DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$1']].Id" --output text)
-
-if [[ $(aws cloudfront list-distributions --query "DistributionList.Items[0].Id") != "null" ]] && [[ "$DISTRIBUTION_ID" ]] ; then 
-    echo "Distribution for PR #$1 already exists!"
-    aws cloudfront create-invalidation --distribution-id "$DISTRIBUTION_ID" --paths '/'
-    exit 0
-else
-    echo "A new distribution for PR #$1 is being created"
-    CLOUDFRONT_CONFIG=$(aws cloudfront create-distribution --origin-domain-name ad-hoc-expensify-cash.s3.us-east-1.amazonaws.com --default-root-object index.html)
-
-    DISTRIBUTION_ID=$(jq -r .Distribution.Id <<< "$CLOUDFRONT_CONFIG") 
-    ETAG=$(jq -r .ETag <<< "$CLOUDFRONT_CONFIG") 
-
-    echo "$CLOUDFRONT_CONFIG" | jq -r .Distribution.DistributionConfig >> dist.config.json
-
-    tmp=$(mktemp /tmp/tmp.XXXXXXX)
-    NEW_ORIGIN_PATH="/web/$1"
-    jq --arg originPath "$NEW_ORIGIN_PATH" '(.Origins.Items[] | select(.OriginPath == "")).OriginPath |= $originPath' dist.config.json  > "$tmp" && mv "$tmp"  dist.config.json
-
-    aws cloudfront update-distribution --id "$DISTRIBUTION_ID" --if-match "$ETAG" --distribution-config file://dist.config.json 
-fi
diff --git a/.github/workflows/testBuild.yml b/.github/workflows/testBuild.yml
index 1ad2e49110ab..98b75f7da3de 100644
--- a/.github/workflows/testBuild.yml
+++ b/.github/workflows/testBuild.yml
@@ -218,9 +218,6 @@ jobs:
       - name: Deploy to S3 for internal testing
         run: aws s3 cp --recursive --acl public-read "$GITHUB_WORKSPACE"/dist s3://ad-hoc-expensify-cash/web/"$PULL_REQUEST_NUMBER"
 
-      - name: Create CloudFront distribution for the PR if needed
-        run: ./.github/scripts/createCloudfrontDistribution.sh "$PULL_REQUEST_NUMBER"
-
   postGithubComment:
     runs-on: ubuntu-latest
     name: Post a GitHub comment with app download links for testing
@@ -248,12 +245,6 @@ jobs:
           content_ios="${content_ios//$'\n'/'%0A'}"
           content_ios="${content_ios//$'\r'/'%0D'}"
           echo "ios_paths=$content_ios" >> "$GITHUB_OUTPUT"
-      
-      - name: Get CloudFront URL
-        id: get_cloudfront_url
-        run: |
-          cloudfront_url=$(aws cloudfront list-distributions --query "DistributionList.Items[?Origins.Items[?OriginPath=='/web/$PULL_REQUEST_NUMBER']].DomainName" --output text)
-          echo "cloudfront_url=$cloudfront_url" >> "$GITHUB_OUTPUT"
 
       # This step removes previous comments with links connected to the PR
       - name: maintain-comment
@@ -270,9 +261,12 @@ jobs:
           gh pr checkout "$PULL_REQUEST_NUMBER"
           gh pr comment --body \
           ":test_tube::test_tube: Use the links below to test this build in android and iOS. Happy testing! :test_tube::test_tube:
-          | android :robot:  | iOS :apple: | desktop :computer: | web :spider_web: |
-          | ------------- | ------------- | ------------- | ------------- | 
-          | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/$PULL_REQUEST_NUMBER/NewExpensify.dmg | https://${{steps.get_cloudfront_url.outputs.cloudfront_url}} |
-          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) | ![desktop](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/$PULL_REQUEST_NUMBER/NewExpensify.dmg) | ![web](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://${{steps.get_cloudfront_url.outputs.cloudfront_url}}) |"
+          | android :robot:  | iOS :apple: |
+          | ------------- | ------------- |
+          | ${{fromJson(steps.set_var.outputs.android_paths).html_path}}  | ${{fromJson(steps.set_var.outputs.ios_paths).html_path}}  | 
+          | ![Android](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.android_paths).html_path}}) | ![iOS](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${{fromJson(steps.set_var.outputs.ios_paths).html_path}}) |
+          | desktop :computer: | web :spider_web: |
+          | https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/$PULL_REQUEST_NUMBER/NewExpensify.dmg | https://$PULL_REQUEST_NUMBER.pr-testing.expensify.com |
+          | ![desktop](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/$PULL_REQUEST_NUMBER/NewExpensify.dmg) | ![web](https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://$(PULL_REQUEST_NUMBER).pr-testing.expensify.com) |"
         env:
           GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
