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

feat: shard client and login tests #7186

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
147 changes: 147 additions & 0 deletions .github/workflows/lint-and-test-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# OpenCRVS is also distributed under the terms of the Civil Registration
# & Healthcare Disclaimer located at http://opencrvs.org/license.
#
# Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.

name: Lint, run client tests and security scans

on: [pull_request]

jobs:
setup:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4

build:
runs-on: ubuntu-22.04
needs: setup
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check package.json and scripts
id: check-scripts
run: |
if [ ! -f "packages/client/package.json" ]; then
echo "No package.json found for packages/client. Stopping pipeline."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT

if ! grep -q "\"test\":" "packages/client/package.json"; then
echo "Test not found in packages/client"
echo "skip-test=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi

if ! grep -q "\"lint\":" "packages/client/package.json"; then
echo "Lint scripts not found in packages/client. Stopping pipeline."
echo "skip-lint=true" >> $GITHUB_OUTPUT
else
echo "skip-lint=false" >> $GITHUB_OUTPUT
fi
fi

- name: Use Node.js from .nvmrc
if: steps.check-scripts.outputs.skip != 'true'
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Cache node modules
if: steps.check-scripts.outputs.skip != 'true'
uses: actions/cache@v4
with:
path: |
packages/client/node_modules
packages/commons/node_modules
packages/components/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-

- name: Runs dependency installation
if: steps.check-scripts.outputs.skip != 'true'
run: CI="" yarn install --frozen-lockfile

- name: Build common package
if: steps.check-scripts.outputs.skip != 'true'
run: cd packages/commons && yarn build

- name: Build components client and login
if: steps.check-scripts.outputs.skip != 'true'
run: cd packages/components && yarn build

- name: Upload build artifacts
if: steps.check-scripts.outputs.skip != 'true'
uses: actions/upload-artifact@v3
with:
name: client-build
path: |
packages/commons/build
packages/components/build

test:
needs: [setup, build]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
shard: [1/4, 2/4, 3/4, 4/4]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: client-build
path: packages/

- name: Use Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Cache node modules
uses: actions/cache@v4
with:
path: |
packages/client/node_modules
packages/commons/node_modules
packages/components/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-

- name: Runs dependency installation
run: CI="" yarn install --frozen-lockfile

- name: Run linting
if: steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-lint != 'true'
run: cd packages/client && yarn lint

- name: Run Unit Test
if: steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-test != 'true'
run: cd packages/client && yarn test --shard ${{ matrix.shard }}

security-scans:
needs: setup
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner in fs mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
trivy-config: trivy.yaml
9 changes: 1 addition & 8 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Get list of packages
id: set-matrix
run: |
PACKAGES=$(ls -d packages/* | jq -R -s -c 'split("\n")[:-1]')
PACKAGES=$(ls -d packages/* | grep -v 'packages/client' | jq -R -s -c 'split("\n")[:-1]')
echo "Found packages: $PACKAGES"
echo "matrix=${PACKAGES}" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -107,13 +107,6 @@ jobs:
if: steps.check-scripts.outputs.skip != 'true'
run: cd packages/commons && yarn build

- name: Build components client and login
if: steps.check-scripts.outputs.skip != 'true'
run: |
if [[ "${{ matrix.package }}" == "packages/client" || "${{ matrix.package }}" == "packages/login" ]]; then
cd packages/components && yarn build
fi

# TODO: should run parallel to unit tests as can take as much as unit tests
- name: Run linting
if: steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-lint != 'true'
Expand Down
Loading