From a35c05fda7e53130bb8d170836f37c28e92d831d Mon Sep 17 00:00:00 2001 From: Jan Nowakowski Date: Fri, 20 Dec 2024 14:16:03 +0100 Subject: [PATCH 1/4] Cache old dot node_modules in workflows --- .github/actions/composite/setupNode/action.yml | 17 +++++++++++++++-- .github/workflows/deploy.yml | 4 ++++ .github/workflows/testBuildHybrid.yml | 4 ++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/actions/composite/setupNode/action.yml b/.github/actions/composite/setupNode/action.yml index 8eb4f6474638..63b91a899864 100644 --- a/.github/actions/composite/setupNode/action.yml +++ b/.github/actions/composite/setupNode/action.yml @@ -1,6 +1,12 @@ name: Set up Node description: Set up Node +inputs: + IS_HYBRID_BUILD: + description: "Indicates if node is set up for hybrid app" + required: false + default: 'false' + outputs: cache-hit: description: Was there a cache hit on the main node_modules? @@ -27,6 +33,13 @@ runs: path: node_modules key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json', 'patches/**') }} + - id: cache-old-dot-node-modules + if: inputs.IS_HYBRID_BUILD == 'true' + uses: actions/cache@v4 + with: + path: Mobile-Expensify/node_modules + key: ${{ runner.os }}-node-modules-${{ hashFiles('Mobile-Expensify/package-lock.json', 'Mobile-Expensify/patches/**') }} + - id: cache-desktop-node-modules uses: actions/cache@v4 with: @@ -34,12 +47,12 @@ runs: key: ${{ runner.os }}-desktop-node-modules-${{ hashFiles('desktop/package-lock.json', 'desktop/patches/**') }} - name: Install root project node packages - if: steps.cache-node-modules.outputs.cache-hit != 'true' + if: (steps.cache-node-modules.outputs.cache-hit != 'true') || (inputs.IS_HYBRID_BUILD == 'true' && steps.cache-old-dot-node-modules.outputs.cache-hit != 'true') uses: nick-fields/retry@3f757583fb1b1f940bc8ef4bf4734c8dc02a5847 with: timeout_minutes: 30 max_attempts: 3 - command: npm ci + command: rm -rf node_modules && npm ci # if we want to build hybrid app then we have to remove ND node_modules first - name: Install node packages for desktop submodule if: steps.cache-desktop-node-modules.outputs.cache-hit != 'true' diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 354b78d437a3..86bfa195cd75 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -137,6 +137,8 @@ jobs: - name: Setup Node id: setup-node uses: ./.github/actions/composite/setupNode + with: + IS_HYBRID_BUILD: 'true' - name: Run grunt build run: | @@ -449,6 +451,8 @@ jobs: - name: Setup Node id: setup-node uses: ./.github/actions/composite/setupNode + with: + IS_HYBRID_BUILD: 'true' - name: Setup Ruby uses: ruby/setup-ruby@v1.190.0 diff --git a/.github/workflows/testBuildHybrid.yml b/.github/workflows/testBuildHybrid.yml index c8027f93a2a5..1dd968c8cb6d 100644 --- a/.github/workflows/testBuildHybrid.yml +++ b/.github/workflows/testBuildHybrid.yml @@ -115,6 +115,8 @@ jobs: - name: Setup Node id: setup-node uses: ./.github/actions/composite/setupNode + with: + IS_HYBRID_BUILD: 'true' - name: Run grunt build run: | @@ -223,6 +225,8 @@ jobs: - name: Setup Node id: setup-node uses: ./.github/actions/composite/setupNode + with: + IS_HYBRID_BUILD: 'true' - name: Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it run: | From 00685ab7775bdb80a77cc1c974e4319795afeac6 Mon Sep 17 00:00:00 2001 From: Jan Nowakowski Date: Tue, 7 Jan 2025 15:38:29 +0100 Subject: [PATCH 2/4] Simplify step condition --- .github/actions/composite/setupNode/action.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/actions/composite/setupNode/action.yml b/.github/actions/composite/setupNode/action.yml index 63b91a899864..2dba0252ae87 100644 --- a/.github/actions/composite/setupNode/action.yml +++ b/.github/actions/composite/setupNode/action.yml @@ -46,13 +46,17 @@ runs: path: desktop/node_modules key: ${{ runner.os }}-desktop-node-modules-${{ hashFiles('desktop/package-lock.json', 'desktop/patches/**') }} + - name: Remove ND node_modules if needed for hybrid app build + if: inputs.IS_HYBRID_BUILD == 'true' && steps.cache-node-modules.outputs.cache-hit == 'true' && steps.cache-old-dot-node-modules.outputs.cache-hit != 'true' + run: rm -rf node_modules + - name: Install root project node packages - if: (steps.cache-node-modules.outputs.cache-hit != 'true') || (inputs.IS_HYBRID_BUILD == 'true' && steps.cache-old-dot-node-modules.outputs.cache-hit != 'true') + if: steps.cache-node-modules.outputs.cache-hit != 'true' || steps.cache-old-dot-node-modules.outputs.cache-hit != 'true' uses: nick-fields/retry@3f757583fb1b1f940bc8ef4bf4734c8dc02a5847 with: timeout_minutes: 30 max_attempts: 3 - command: rm -rf node_modules && npm ci # if we want to build hybrid app then we have to remove ND node_modules first + command: npm ci - name: Install node packages for desktop submodule if: steps.cache-desktop-node-modules.outputs.cache-hit != 'true' From a7fe07b815bf51e14c4381552d969615aec72ddd Mon Sep 17 00:00:00 2001 From: Jan Nowakowski Date: Tue, 7 Jan 2025 15:42:36 +0100 Subject: [PATCH 3/4] Add shell --- .github/actions/composite/setupNode/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/composite/setupNode/action.yml b/.github/actions/composite/setupNode/action.yml index 2dba0252ae87..df4642875a0d 100644 --- a/.github/actions/composite/setupNode/action.yml +++ b/.github/actions/composite/setupNode/action.yml @@ -48,6 +48,7 @@ runs: - name: Remove ND node_modules if needed for hybrid app build if: inputs.IS_HYBRID_BUILD == 'true' && steps.cache-node-modules.outputs.cache-hit == 'true' && steps.cache-old-dot-node-modules.outputs.cache-hit != 'true' + shell: bash run: rm -rf node_modules - name: Install root project node packages From 65f1be5b76ae4bed666b3bc76fb2c7b4cc53478f Mon Sep 17 00:00:00 2001 From: Jan Nowakowski Date: Tue, 7 Jan 2025 15:55:36 +0100 Subject: [PATCH 4/4] Fix condition --- .github/actions/composite/setupNode/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/composite/setupNode/action.yml b/.github/actions/composite/setupNode/action.yml index df4642875a0d..086a2a383d28 100644 --- a/.github/actions/composite/setupNode/action.yml +++ b/.github/actions/composite/setupNode/action.yml @@ -52,7 +52,7 @@ runs: run: rm -rf node_modules - name: Install root project node packages - if: steps.cache-node-modules.outputs.cache-hit != 'true' || steps.cache-old-dot-node-modules.outputs.cache-hit != 'true' + if: steps.cache-node-modules.outputs.cache-hit != 'true' || (inputs.IS_HYBRID_BUILD == 'true' && steps.cache-old-dot-node-modules.outputs.cache-hit != 'true') uses: nick-fields/retry@3f757583fb1b1f940bc8ef4bf4734c8dc02a5847 with: timeout_minutes: 30