Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Backend & Frontend for Parallel Cypress Jobs #8989

Draft
wants to merge 25 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
510f525
fixed resource utilisation
nihal467 Nov 4, 2024
95e2816
removed the forked and non-forked repo check
nihal467 Nov 4, 2024
675ddd3
reinstall npm
nihal467 Nov 4, 2024
8bc2ddc
reinstall frontend
nihal467 Nov 4, 2024
cf1cd75
Merge branch 'develop' into cypress-parallel-job
nihal467 Nov 4, 2024
e732828
cache docker only
nihal467 Nov 4, 2024
1dfb79e
Merge branch 'cypress-parallel-job' of https://github.com/ohcnetwork/…
nihal467 Nov 4, 2024
f0442a4
cache docker only
nihal467 Nov 4, 2024
13e68ce
cache docker only
nihal467 Nov 4, 2024
72fa809
trying cache and multiple job approach
nihal467 Nov 5, 2024
1ec27ba
trying cache and multiple job approach
nihal467 Nov 5, 2024
e99c16c
Merge branch 'develop' into cypress-parallel-job
nihal467 Nov 5, 2024
0f81d3b
trying cache and multiple job approach
nihal467 Nov 5, 2024
433d274
Merge branch 'cypress-parallel-job' of https://github.com/ohcnetwork/…
nihal467 Nov 5, 2024
ed42ccc
modified backend name
nihal467 Nov 5, 2024
985fb68
modified backend name
nihal467 Nov 5, 2024
a7c6e41
modified backend name of image
nihal467 Nov 5, 2024
e31df55
check the image list
nihal467 Nov 5, 2024
5c22e0f
check the available image list
nihal467 Nov 5, 2024
01b2fc0
check the image list
nihal467 Nov 5, 2024
8f25f6b
check the ava image list
nihal467 Nov 5, 2024
a4ac0fc
modified the backend name
nihal467 Nov 5, 2024
4a37989
modified the backend name list
nihal467 Nov 5, 2024
33ef986
debug the cypress step 2
nihal467 Nov 5, 2024
53bdd6c
debug the cypress step 2
nihal467 Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 107 additions & 23 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ on:
workflow_dispatch:

jobs:
cypress-run:
build-and-cache:
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
if: github.repository == 'ohcnetwork/care_fe'
steps:
- name: Checkout 📥
uses: actions/checkout@v3
Expand All @@ -31,14 +25,14 @@ jobs:
echo "branch=develop" >> $GITHUB_OUTPUT
fi

- name: Checkout care 📥
- name: Checkout care backend 📥
uses: actions/checkout@v3
with:
repository: ohcnetwork/care
path: care
ref: ${{ steps.backend-branch.outputs.branch }}

- name: Start care docker containers 🐳
- name: Start care backend docker containers 🐳
run: |
cd care
echo DISABLE_RATELIMIT=True >> docker/.prebuilt.env
Expand All @@ -50,15 +44,25 @@ jobs:
env:
JWKS_BASE64: ${{ secrets.JWKS_BASE64 }}

- name: Wait for care to be up ♻
- name: Wait for care backend to be up ♻
uses: nick-fields/retry@v2
with:
timeout_minutes: 1
max_attempts: 5
command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000
on_retry_command: sleep 5

- name: Determine PR Origin
- name: Cache Backend Docker Image 📦
run: |
docker save ghcr.io/ohcnetwork/care:latest -o backend-cache.tar

- name: Upload Backend Cache Artifact
uses: actions/upload-artifact@v3
with:
name: backend-docker-cache
path: backend-cache.tar

- name: Determine Frontend PR Origin
id: pr_origin
run: echo "::set-output name=is_forked::$( echo ${{ github.event.pull_request.head.repo.fork }})"

Expand All @@ -67,24 +71,102 @@ jobs:
with:
node-version: "20"

- name: Install dependencies 📦
- name: Install frontend dependencies 📦
run: npm run install-all

- name: Build ⚙️
- name: Build the frontend after downloading all dependencies ⚙️
run: npm run build

- name: Cache Frontend Build 📦
run: |
tar -cvf frontend-build-cache.tar ./build

- name: Upload Frontend Cache Artifact
uses: actions/upload-artifact@v3
with:
name: frontend-build-cache
path: frontend-build-cache.tar

jobs:
cypress-tests:
needs: build-and-cache
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3, 4]
env:
REACT_CARE_API_URL: http://localhost:9000
steps:
- name: Checkout care_fe repository 📥
uses: actions/checkout@v3

- name: Checkout care backend repository 📥
uses: actions/checkout@v3
with:
repository: ohcnetwork/care # Replace with the actual owner/repo if different
path: care
ref: ${{ needs.build-and-cache.outputs.backend-branch }} # Ensure this is defined in the previous job

# Download the cached backend Docker image
- name: Download Backend Cache
uses: actions/download-artifact@v3
with:
name: backend-docker-cache
path: .

# Load the cached Docker image
- name: Load Backend Docker Image 🐳
run: docker load -i backend-cache.tar

- name: List Directory Contents After Checkout 🗂️
run: ls -al

# Start backend Docker containers
- name: Start care backend 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=${{ secrets.JWKS_BASE64 }}" >> docker/.prebuilt.env
make docker_config_file=docker-compose.pre-built.yaml up
env:
JWKS_BASE64: ${{ secrets.JWKS_BASE64 }}

# Check backend health
- name: Wait for backend health check ♻
uses: nick-fields/retry@v2
with:
timeout_minutes: 1
max_attempts: 5
command: curl -o /dev/null -s -w "%{http_code}\n" http://localhost:9000
on_retry_command: sleep 5

# Download the cached frontend build
- name: Download Frontend Cache
uses: actions/download-artifact@v3
with:
name: frontend-build-cache
path: .

# Extract frontend cache and install dependencies
- name: Extract and Install Frontend Dependencies 📦
run: |
tar -xvf frontend-build-cache.tar
npm install

# Install Chrome
- 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

# Run Cypress tests for Non-Forked PRs
- 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
Expand All @@ -96,15 +178,14 @@ jobs:
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 }}

# Run Cypress tests for Forked PRs
- 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
Expand All @@ -117,21 +198,24 @@ jobs:
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 }}

# Upload Cypress screenshots on failure
- name: Upload cypress screenshots on failure 📸
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots

# Upload Cypress videos
- name: Upload cypress videos 📹
uses: actions/upload-artifact@v3
if: steps.pr_origin.outputs.is_forked == 'true'
with:
name: cypress-videos
path: cypress/videos
path: cypress/videos

Empty file.
16 changes: 16 additions & 0 deletions package-lock.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock file changes needs to be discarded;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading