From 596fc0a554e9db133d1a656509e6793236fc08de Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 00:43:45 +0530 Subject: [PATCH 01/16] cypress resource split --- .github/workflows/cypress.yaml | 115 ++++++--------------------------- 1 file changed, 20 insertions(+), 95 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 0f588568bbc..1a28b6e83f1 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -11,20 +11,16 @@ on: jobs: cypress-run: - permissions: write-all - if: github.repository == 'ohcnetwork/care_fe' runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - containers: [1, 2, 3, 4, 5, 6, 7, 8] env: REACT_CARE_API_URL: http://localhost:9000 steps: - - name: Checkout 📥 + - name: Checkout Backend and Frontend uses: actions/checkout@v3 + with: + path: repo - - name: Set backend branch + - name: Set Backend Branch id: backend-branch run: | if [[ '${{ github.event.pull_request.base.ref }}' == 'staging' ]]; then @@ -33,26 +29,14 @@ jobs: echo "branch=develop" >> $GITHUB_OUTPUT fi - - name: Checkout care 📥 - uses: actions/checkout@v3 - with: - repository: ohcnetwork/care - path: care - ref: ${{ steps.backend-branch.outputs.branch }} - - - name: Start care docker containers 🐳 + - name: Setup Docker Backend Cache run: | - cd care - echo DISABLE_RATELIMIT=True >> docker/.prebuilt.env - echo "CORS_ALLOWED_ORIGINS=\"[\\\"http://localhost:4000\\\"]\"" >> docker/.prebuilt.env - echo JWKS_BASE64=\"$(cat ../.github/runner-files/jwks.b64.txt)\" >> docker/.prebuilt.env - make docker_config_file=docker-compose.pre-built.yaml up - make docker_config_file=docker-compose.pre-built.yaml load-dummy-data - cd .. - env: - JWKS_BASE64: ${{ secrets.JWKS_BASE64 }} + # Build and cache the backend Docker image here + cd repo/care + docker-compose up -d --build + cd ../.. - - name: Wait for care to be up ♻ + - name: Wait for Backend to Be Up uses: nick-fields/retry@v2 with: timeout_minutes: 1 @@ -60,80 +44,21 @@ jobs: command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000 on_retry_command: sleep 5 - - name: Determine PR Origin - id: pr_origin - run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})" - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Install dependencies 📦 - run: npm run install-all - - - name: Build ⚙️ - run: npm run build - - - name: Install Specific Chrome Version + - name: Install Frontend Dependencies run: | - sudo apt-get install -y wget - sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb - sudo apt-get install ./google-chrome-stable_current_amd64.deb - - - name: Cypress run for Non-Forked PRs 🥬 - if: steps.pr_origin.outputs.is_forked == 'false' - uses: cypress-io/github-action@v5 - with: - env: SKIP_PREFLIGHT_CHECK=true - install: false - start: "npx vite preview --host" - wait-on: "http://localhost:4000" - wait-on-timeout: 300 - browser: chrome - record: true - parallel: true - group: "UI-Chrome" - env: - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_OPTIONS: --max_old_space_size=4096 - COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}} - COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}} + cd repo/frontend + npm ci + npm run build + cd ../.. - - name: Cypress run for Forked PRs 🥬 - if: steps.pr_origin.outputs.is_forked == 'true' - uses: cypress-io/github-action@v5 - with: - env: SKIP_PREFLIGHT_CHECK=true - install: false - start: "npx vite preview --host" - wait-on: "http://localhost:4000" - wait-on-timeout: 300 - browser: chrome - record: true - parallel: true - group: "UI-Chrome" + - name: Cypress Parallel Tests within Single Runner + run: | + # Run Cypress in parallel using a single runner with 6 processes + # Here we split tests in Node, simulating "parallelization" + npx cypress run --parallel --record --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" env: - CYPRESS_SPLIT_TESTS: "true" CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_OPTIONS: --max_old_space_size=4096 COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}} COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}} - SPLIT: ${{ strategy.job-total }} - SPLIT_INDEX: ${{ strategy.job-index }} - - - name: Upload cypress screenshots on failure 📸 - uses: actions/upload-artifact@v3 - if: failure() - with: - name: cypress-screenshots - path: cypress/screenshots - - - name: Upload cypress videos 📹 - uses: actions/upload-artifact@v3 - if: steps.pr_origin.outputs.is_forked == 'true' - with: - name: cypress-videos - path: cypress/videos From 1af04216363ad1ab55dffe21b1de8272fe28a0f1 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 00:56:05 +0530 Subject: [PATCH 02/16] cypress resource split process --- .github/workflows/cypress.yaml | 103 +++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 1a28b6e83f1..c220d136cd6 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -1,8 +1,6 @@ name: Cypress Tests on: - schedule: - - cron: "30 22 * * *" pull_request: branches: - develop @@ -10,12 +8,13 @@ on: workflow_dispatch: jobs: - cypress-run: + setup: + name: Setup Backend and Frontend runs-on: ubuntu-latest - env: - REACT_CARE_API_URL: http://localhost:9000 + outputs: + backend_url: ${{ steps.backend-url.outputs.backend_url }} steps: - - name: Checkout Backend and Frontend + - name: Checkout Repository uses: actions/checkout@v3 with: path: repo @@ -29,14 +28,25 @@ jobs: echo "branch=develop" >> $GITHUB_OUTPUT fi - - name: Setup Docker Backend Cache + - name: Checkout Backend Repository + uses: actions/checkout@v3 + with: + repository: ohcnetwork/care + path: repo/care + ref: ${{ steps.backend-branch.outputs.branch }} + + - name: Start Backend Services run: | - # Build and cache the backend Docker image here cd repo/care - docker-compose up -d --build - cd ../.. + echo DISABLE_RATELIMIT=True >> docker/.prebuilt.env + echo "CORS_ALLOWED_ORIGINS=\"[\\\"http://localhost:4000\\\"]\"" >> docker/.prebuilt.env + echo JWKS_BASE64=\"$(cat ../.github/runner-files/jwks.b64.txt)\" >> docker/.prebuilt.env + docker-compose -f docker-compose.pre-built.yaml up -d + cd .. + env: + JWKS_BASE64: ${{ secrets.JWKS_BASE64 }} - - name: Wait for Backend to Be Up + - name: Wait for Backend to be Up uses: nick-fields/retry@v2 with: timeout_minutes: 1 @@ -44,21 +54,80 @@ jobs: command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000 on_retry_command: sleep 5 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Cache Node Modules + uses: actions/cache@v3 + with: + path: repo/frontend/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('repo/frontend/package-lock.json') }} + - name: Install Frontend Dependencies run: | cd repo/frontend npm ci + cd ../.. + + - name: Build Frontend + run: | + cd repo/frontend npm run build cd ../.. - - name: Cypress Parallel Tests within Single Runner + test: + name: Run Cypress Tests + needs: setup + runs-on: ubuntu-latest + env: + REACT_CARE_API_URL: http://localhost:9000 + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_OPTIONS: --max_old_space_size=4096 + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + path: repo + + - name: Determine PR Origin + id: pr_origin + run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})" + + - name: Cypress Run for Non-Forked PRs + if: steps.pr_origin.outputs.is_forked == 'false' run: | - # Run Cypress in parallel using a single runner with 6 processes - # Here we split tests in Node, simulating "parallelization" + cd repo/frontend npx cypress run --parallel --record --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_OPTIONS: --max_old_space_size=4096 - COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}} - COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}} + COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} + COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} + + - name: Cypress Run for Forked PRs + if: steps.pr_origin.outputs.is_forked == 'true' + run: | + cd repo/frontend + npx cypress-split run --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" --env CYPRESS_SPLIT_TESTS="true" + env: + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + NODE_OPTIONS: --max_old_space_size=4096 + COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} + COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} + + - name: Upload Cypress Screenshots on Failure + if: failure() + uses: actions/upload-artifact@v3 + with: + name: cypress-screenshots + path: repo/frontend/cypress/screenshots + + - name: Upload Cypress Videos + if: failure() && steps.pr_origin.outputs.is_forked == 'true' + uses: actions/upload-artifact@v3 + with: + name: cypress-videos + path: repo/frontend/cypress/videos From 17e944db35d74dbb25a61cf0cd4a476d067c6b4a Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 00:57:46 +0530 Subject: [PATCH 03/16] cypress resource split --- .github/workflows/cypress.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index c220d136cd6..0bb2eaf7493 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -10,6 +10,7 @@ on: jobs: setup: name: Setup Backend and Frontend + if: github.repository == 'ohcnetwork/care_fe' # Ensures job runs only for the care_fe repository runs-on: ubuntu-latest outputs: backend_url: ${{ steps.backend-url.outputs.backend_url }} @@ -79,6 +80,7 @@ jobs: test: name: Run Cypress Tests + if: github.repository == 'ohcnetwork/care_fe' # Ensures job runs only for the care_fe repository needs: setup runs-on: ubuntu-latest env: From 398f82697cbc6412ce9ccfd069c8544f298ebd4b Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:00:14 +0530 Subject: [PATCH 04/16] cypress resource split --- .github/workflows/cypress.yaml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 0bb2eaf7493..47da4d9f273 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -50,10 +50,10 @@ jobs: - name: Wait for Backend to be Up uses: nick-fields/retry@v2 with: - timeout_minutes: 1 - max_attempts: 5 + timeout_minutes: 2 + max_attempts: 10 command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000 - on_retry_command: sleep 5 + on_retry_command: sleep 10 - name: Set up Node.js uses: actions/setup-node@v4 @@ -98,6 +98,19 @@ jobs: id: pr_origin run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})" + - name: Wait for Backend Health Check + run: | + for i in {1..10}; do + response=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:9000/health) + if [ "$response" -eq 200 ]; then + echo "Backend is healthy!" + break + else + echo "Waiting for backend to be healthy..." + sleep 10 + fi + done + - name: Cypress Run for Non-Forked PRs if: steps.pr_origin.outputs.is_forked == 'false' run: | From 9f9b4eb7bd390b6817ae873223fa8cb2bb3e963b Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:03:36 +0530 Subject: [PATCH 05/16] cypress resource split --- .github/workflows/cypress.yaml | 91 ++++++++++------------------------ 1 file changed, 27 insertions(+), 64 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 47da4d9f273..6ac83ecac84 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -8,17 +8,18 @@ on: workflow_dispatch: jobs: - setup: - name: Setup Backend and Frontend - if: github.repository == 'ohcnetwork/care_fe' # Ensures job runs only for the care_fe repository + setup_and_test: + name: Setup and Run Cypress Tests + if: github.repository == 'ohcnetwork/care_fe' runs-on: ubuntu-latest - outputs: - backend_url: ${{ steps.backend-url.outputs.backend_url }} + env: + REACT_CARE_API_URL: http://localhost:9000 + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_OPTIONS: --max_old_space_size=4096 steps: - name: Checkout Repository uses: actions/checkout@v3 - with: - path: repo - name: Set Backend Branch id: backend-branch @@ -33,16 +34,17 @@ jobs: uses: actions/checkout@v3 with: repository: ohcnetwork/care - path: repo/care + path: care ref: ${{ steps.backend-branch.outputs.branch }} - name: Start Backend Services run: | - cd repo/care + cd care echo DISABLE_RATELIMIT=True >> docker/.prebuilt.env echo "CORS_ALLOWED_ORIGINS=\"[\\\"http://localhost:4000\\\"]\"" >> docker/.prebuilt.env echo JWKS_BASE64=\"$(cat ../.github/runner-files/jwks.b64.txt)\" >> docker/.prebuilt.env - docker-compose -f docker-compose.pre-built.yaml up -d + make docker_config_file=docker-compose.pre-built.yaml up + make docker_config_file=docker-compose.pre-built.yaml load-dummy-data cd .. env: JWKS_BASE64: ${{ secrets.JWKS_BASE64 }} @@ -63,73 +65,34 @@ jobs: - name: Cache Node Modules uses: actions/cache@v3 with: - path: repo/frontend/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('repo/frontend/package-lock.json') }} + path: frontend/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }} - name: Install Frontend Dependencies run: | - cd repo/frontend + cd frontend npm ci - cd ../.. + cd .. - name: Build Frontend run: | - cd repo/frontend + cd frontend npm run build - cd ../.. - - test: - name: Run Cypress Tests - if: github.repository == 'ohcnetwork/care_fe' # Ensures job runs only for the care_fe repository - needs: setup - runs-on: ubuntu-latest - env: - REACT_CARE_API_URL: http://localhost:9000 - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_OPTIONS: --max_old_space_size=4096 - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - with: - path: repo + cd .. - name: Determine PR Origin id: pr_origin run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})" - - name: Wait for Backend Health Check - run: | - for i in {1..10}; do - response=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:9000/health) - if [ "$response" -eq 200 ]; then - echo "Backend is healthy!" - break - else - echo "Waiting for backend to be healthy..." - sleep 10 - fi - done - - - name: Cypress Run for Non-Forked PRs - if: steps.pr_origin.outputs.is_forked == 'false' + - name: Run Cypress Tests run: | - cd repo/frontend - npx cypress run --parallel --record --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" - env: - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - NODE_OPTIONS: --max_old_space_size=4096 - COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} - COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} - - - name: Cypress Run for Forked PRs - if: steps.pr_origin.outputs.is_forked == 'true' - run: | - cd repo/frontend - npx cypress-split run --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" --env CYPRESS_SPLIT_TESTS="true" + cd frontend + if [ "${{ steps.pr_origin.outputs.is_forked }}" == "false" ]; then + npx cypress run --parallel --record --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" + else + npx cypress-split run --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" --env CYPRESS_SPLIT_TESTS="true" + fi env: - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - NODE_OPTIONS: --max_old_space_size=4096 COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} @@ -138,11 +101,11 @@ jobs: uses: actions/upload-artifact@v3 with: name: cypress-screenshots - path: repo/frontend/cypress/screenshots + path: frontend/cypress/screenshots - name: Upload Cypress Videos if: failure() && steps.pr_origin.outputs.is_forked == 'true' uses: actions/upload-artifact@v3 with: name: cypress-videos - path: repo/frontend/cypress/videos + path: frontend/cypress/videos From 0aedccf5091fed7ca51bfd86f2461a2110090df7 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:05:16 +0530 Subject: [PATCH 06/16] cypress resource split --- .github/workflows/cypress.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 6ac83ecac84..c520e1d2078 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -10,7 +10,7 @@ on: jobs: setup_and_test: name: Setup and Run Cypress Tests - if: github.repository == 'ohcnetwork/care_fe' + if: github.repository == 'ohcnetwork/care_fe' # Ensures job runs only for the care_fe repository runs-on: ubuntu-latest env: REACT_CARE_API_URL: http://localhost:9000 @@ -43,8 +43,8 @@ jobs: echo DISABLE_RATELIMIT=True >> docker/.prebuilt.env echo "CORS_ALLOWED_ORIGINS=\"[\\\"http://localhost:4000\\\"]\"" >> docker/.prebuilt.env echo JWKS_BASE64=\"$(cat ../.github/runner-files/jwks.b64.txt)\" >> docker/.prebuilt.env - make docker_config_file=docker-compose.pre-built.yaml up - make docker_config_file=docker-compose.pre-built.yaml load-dummy-data + docker-compose -f docker-compose.pre-built.yaml up -d + docker-compose -f docker-compose.pre-built.yaml load-dummy-data cd .. env: JWKS_BASE64: ${{ secrets.JWKS_BASE64 }} From 49f779f1b96981b0bc00a047ea3093af4940c8c2 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:08:26 +0530 Subject: [PATCH 07/16] cypress resource split --- .github/workflows/cypress.yaml | 95 ++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index c520e1d2078..c489e52e61f 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -1,6 +1,8 @@ name: Cypress Tests on: + schedule: + - cron: "30 22 * * *" pull_request: branches: - develop @@ -8,20 +10,17 @@ on: workflow_dispatch: jobs: - setup_and_test: - name: Setup and Run Cypress Tests - if: github.repository == 'ohcnetwork/care_fe' # Ensures job runs only for the care_fe repository + cypress-run: + permissions: write-all + if: github.repository == 'ohcnetwork/care_fe' runs-on: ubuntu-latest env: REACT_CARE_API_URL: http://localhost:9000 - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_OPTIONS: --max_old_space_size=4096 steps: - - name: Checkout Repository + - name: Checkout 📥 uses: actions/checkout@v3 - - name: Set Backend Branch + - name: Set backend branch id: backend-branch run: | if [[ '${{ github.event.pull_request.base.ref }}' == 'staging' ]]; then @@ -30,82 +29,86 @@ jobs: echo "branch=develop" >> $GITHUB_OUTPUT fi - - name: Checkout Backend Repository + - name: Checkout care 📥 uses: actions/checkout@v3 with: repository: ohcnetwork/care path: care ref: ${{ steps.backend-branch.outputs.branch }} - - name: Start Backend Services + - name: Start care docker containers 🐳 run: | cd care echo DISABLE_RATELIMIT=True >> docker/.prebuilt.env echo "CORS_ALLOWED_ORIGINS=\"[\\\"http://localhost:4000\\\"]\"" >> docker/.prebuilt.env echo JWKS_BASE64=\"$(cat ../.github/runner-files/jwks.b64.txt)\" >> docker/.prebuilt.env - docker-compose -f docker-compose.pre-built.yaml up -d - docker-compose -f docker-compose.pre-built.yaml load-dummy-data + make docker_config_file=docker-compose.pre-built.yaml up + make docker_config_file=docker-compose.pre-built.yaml load-dummy-data cd .. env: JWKS_BASE64: ${{ secrets.JWKS_BASE64 }} - - name: Wait for Backend to be Up + - name: Wait for care to be up ♻ uses: nick-fields/retry@v2 with: - timeout_minutes: 2 - max_attempts: 10 + timeout_minutes: 1 + max_attempts: 5 command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000 - on_retry_command: sleep 10 + on_retry_command: sleep 5 + + - name: Determine PR Origin + id: pr_origin + run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})" - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: "20" - - name: Cache Node Modules - uses: actions/cache@v3 - with: - path: frontend/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }} + - name: Install dependencies 📦 + run: npm run install-all - - name: Install Frontend Dependencies - run: | - cd frontend - npm ci - cd .. + - name: Build ⚙️ + run: npm run build - - name: Build Frontend + - name: Install Specific Chrome Version run: | - cd frontend - npm run build - cd .. + sudo apt-get install -y wget + sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb + sudo apt-get install ./google-chrome-stable_current_amd64.deb - - name: Determine PR Origin - id: pr_origin - run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})" + - name: Cypress run for Non-Forked PRs 🥬 + if: steps.pr_origin.outputs.is_forked == 'false' + run: | + npx cypress run --record --parallel --ci-build-id ${{ github.run_id }} --group "UI-Chrome" --spec "cypress/e2e/**/*.cy.ts" + env: + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_OPTIONS: --max_old_space_size=4096 + COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} + COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} - - name: Run Cypress Tests + - name: Cypress run for Forked PRs 🥬 + if: steps.pr_origin.outputs.is_forked == 'true' run: | - cd frontend - if [ "${{ steps.pr_origin.outputs.is_forked }}" == "false" ]; then - npx cypress run --parallel --record --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" - else - npx cypress-split run --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" --env CYPRESS_SPLIT_TESTS="true" - fi + npx cypress-split run --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" --env CYPRESS_SPLIT_TESTS="true" env: + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_OPTIONS: --max_old_space_size=4096 COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} - - name: Upload Cypress Screenshots on Failure - if: failure() + - name: Upload cypress screenshots on failure 📸 uses: actions/upload-artifact@v3 + if: failure() with: name: cypress-screenshots - path: frontend/cypress/screenshots + path: cypress/screenshots - - name: Upload Cypress Videos - if: failure() && steps.pr_origin.outputs.is_forked == 'true' + - name: Upload cypress videos 📹 uses: actions/upload-artifact@v3 + if: steps.pr_origin.outputs.is_forked == 'true' with: name: cypress-videos - path: frontend/cypress/videos + path: cypress/videos From c1fe6101eb62f9f157edd2bee8ddc7f0b48b1a63 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:21:50 +0530 Subject: [PATCH 08/16] cypress resource split --- .github/workflows/cypress.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index c489e52e61f..4807b9548c0 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -77,6 +77,14 @@ jobs: sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt-get install ./google-chrome-stable_current_amd64.deb + - name: Start Frontend Server in Background 🌐 + run: | + nohup npx vite preview --host & + + - name: Wait for Frontend to be Up 🕒 + run: | + npx wait-on http://localhost:4000 --timeout 300000 # Wait for frontend + - name: Cypress run for Non-Forked PRs 🥬 if: steps.pr_origin.outputs.is_forked == 'false' run: | From d154de2e01f4502c23047a1ece3d64ad135d097d Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:38:51 +0530 Subject: [PATCH 09/16] reduce runner --- .github/workflows/cypress.yaml | 53 ++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 4807b9548c0..1104d7f480d 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -1,8 +1,6 @@ name: Cypress Tests on: - schedule: - - cron: "30 22 * * *" pull_request: branches: - develop @@ -14,6 +12,10 @@ jobs: permissions: write-all if: github.repository == 'ohcnetwork/care_fe' runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + containers: [1, 2, 3, 4] env: REACT_CARE_API_URL: http://localhost:9000 steps: @@ -77,35 +79,48 @@ jobs: sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt-get install ./google-chrome-stable_current_amd64.deb - - name: Start Frontend Server in Background 🌐 - run: | - nohup npx vite preview --host & - - - name: Wait for Frontend to be Up 🕒 - run: | - npx wait-on http://localhost:4000 --timeout 300000 # Wait for frontend - - name: Cypress run for Non-Forked PRs 🥬 if: steps.pr_origin.outputs.is_forked == 'false' - run: | - npx cypress run --record --parallel --ci-build-id ${{ github.run_id }} --group "UI-Chrome" --spec "cypress/e2e/**/*.cy.ts" + uses: cypress-io/github-action@v5 + with: + env: SKIP_PREFLIGHT_CHECK=true + install: false + start: "npx vite preview --host" + wait-on: "http://localhost:4000" + wait-on-timeout: 300 + browser: chrome + record: true + parallel: true + group: "UI-Chrome" env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_OPTIONS: --max_old_space_size=4096 - COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} - COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} + COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}} + COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}} - name: Cypress run for Forked PRs 🥬 if: steps.pr_origin.outputs.is_forked == 'true' - run: | - npx cypress-split run --group "UI-Chrome" --ci-build-id ${{ github.run_id }} --spec "cypress/e2e/**/*.cy.ts" --env CYPRESS_SPLIT_TESTS="true" + uses: cypress-io/github-action@v5 + with: + env: SKIP_PREFLIGHT_CHECK=true + install: false + start: "npx vite preview --host" + wait-on: "http://localhost:4000" + wait-on-timeout: 300 + browser: chrome + record: true + parallel: true + group: "UI-Chrome" env: + CYPRESS_SPLIT_TESTS: "true" CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_OPTIONS: --max_old_space_size=4096 - COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} - COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} + COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}} + COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}} + SPLIT: ${{ strategy.job-total }} + SPLIT_INDEX: ${{ strategy.job-index }} - name: Upload cypress screenshots on failure 📸 uses: actions/upload-artifact@v3 @@ -119,4 +134,4 @@ jobs: if: steps.pr_origin.outputs.is_forked == 'true' with: name: cypress-videos - path: cypress/videos + path: cypress/videos \ No newline at end of file From bbe0bfbadadf93bbce644f6d21768163b985d30c Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:55:52 +0530 Subject: [PATCH 10/16] removed the chrome browser --- .github/workflows/cypress.yaml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 1104d7f480d..292c1dcde61 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -73,12 +73,6 @@ jobs: - name: Build ⚙️ run: npm run build - - name: Install Specific Chrome Version - run: | - sudo apt-get install -y wget - sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb - sudo apt-get install ./google-chrome-stable_current_amd64.deb - - name: Cypress run for Non-Forked PRs 🥬 if: steps.pr_origin.outputs.is_forked == 'false' uses: cypress-io/github-action@v5 @@ -88,10 +82,9 @@ jobs: start: "npx vite preview --host" wait-on: "http://localhost:4000" wait-on-timeout: 300 - browser: chrome record: true parallel: true - group: "UI-Chrome" + group: "UI-Electron" env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -108,10 +101,9 @@ jobs: start: "npx vite preview --host" wait-on: "http://localhost:4000" wait-on-timeout: 300 - browser: chrome record: true parallel: true - group: "UI-Chrome" + group: "UI-Electron" env: CYPRESS_SPLIT_TESTS: "true" CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} From 843882ba2b12d3fe15ed91fb53e7b02787c32d05 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:00:36 +0530 Subject: [PATCH 11/16] reduce the backend duplicate copy --- .github/workflows/cypress.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 292c1dcde61..7d647fe786d 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -19,6 +19,12 @@ jobs: env: REACT_CARE_API_URL: http://localhost:9000 steps: + - name: Cache Docker Images + uses: actions/cache@v2 + with: + path: /tmp/docker + key: ${{ runner.os }}-docker-${{ hashFiles('care/Dockerfile') }} + - name: Checkout 📥 uses: actions/checkout@v3 @@ -126,4 +132,4 @@ jobs: if: steps.pr_origin.outputs.is_forked == 'true' with: name: cypress-videos - path: cypress/videos \ No newline at end of file + path: cypress/videos From 7555d8be36cd7940b4ed615f182ff7b7a11f0b73 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:22:22 +0530 Subject: [PATCH 12/16] reduce the runner --- .github/workflows/cypress.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 7d647fe786d..1104d7f480d 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -19,12 +19,6 @@ jobs: env: REACT_CARE_API_URL: http://localhost:9000 steps: - - name: Cache Docker Images - uses: actions/cache@v2 - with: - path: /tmp/docker - key: ${{ runner.os }}-docker-${{ hashFiles('care/Dockerfile') }} - - name: Checkout 📥 uses: actions/checkout@v3 @@ -79,6 +73,12 @@ jobs: - name: Build ⚙️ run: npm run build + - name: Install Specific Chrome Version + run: | + sudo apt-get install -y wget + sudo wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb + sudo apt-get install ./google-chrome-stable_current_amd64.deb + - name: Cypress run for Non-Forked PRs 🥬 if: steps.pr_origin.outputs.is_forked == 'false' uses: cypress-io/github-action@v5 @@ -88,9 +88,10 @@ jobs: start: "npx vite preview --host" wait-on: "http://localhost:4000" wait-on-timeout: 300 + browser: chrome record: true parallel: true - group: "UI-Electron" + group: "UI-Chrome" env: CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -107,9 +108,10 @@ jobs: start: "npx vite preview --host" wait-on: "http://localhost:4000" wait-on-timeout: 300 + browser: chrome record: true parallel: true - group: "UI-Electron" + group: "UI-Chrome" env: CYPRESS_SPLIT_TESTS: "true" CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} @@ -132,4 +134,4 @@ jobs: if: steps.pr_origin.outputs.is_forked == 'true' with: name: cypress-videos - path: cypress/videos + path: cypress/videos \ No newline at end of file From 5527e6ea52278edbb61f3f21fb1c9b5ababbce0e Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:33:08 +0530 Subject: [PATCH 13/16] reduce the runner --- .github/workflows/cypress.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 1104d7f480d..a09174f9d9f 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - containers: [1, 2, 3, 4] + containers: [1, 2, 3] env: REACT_CARE_API_URL: http://localhost:9000 steps: From bc059ddc4229a4a1489574df26713cafeddf8cc7 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:46:08 +0530 Subject: [PATCH 14/16] reduce to 4 runner --- .github/workflows/cypress.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index a09174f9d9f..eba8b57b3fb 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - containers: [1, 2, 3] + containers: [1, 2, 3,4] env: REACT_CARE_API_URL: http://localhost:9000 steps: From e4018d2f6306093f627fe7c2eb2ef3625a35cbf5 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:10:01 +0530 Subject: [PATCH 15/16] fix flaky test --- cypress/pageobject/Users/UserSearch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index d72c00c0de7..1292395fce3 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -23,7 +23,7 @@ export class UserPage { } checkUsernameText(username: string) { - cy.get(this.usernameText).should("have.text", username); + cy.get(this.usernameText).should("contain.text", username); } checkUsernameBadgeVisibility(shouldBeVisible: boolean) { From e64e8af5e1e572be44dae7713fa01636c51aa9d3 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Mon, 4 Nov 2024 12:21:58 +0530 Subject: [PATCH 16/16] fix spacing --- .github/workflows/cypress.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index eba8b57b3fb..1104d7f480d 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - containers: [1, 2, 3,4] + containers: [1, 2, 3, 4] env: REACT_CARE_API_URL: http://localhost:9000 steps: