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

chore: add cicd for running unit test when creating PR #180

Merged
merged 9 commits into from
May 22, 2024
46 changes: 46 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and Test

on:
pull_request:
branches:
- next

jobs:
test_and_build:
runs-on: ubuntu-latest
env:
EXCLUDED_PACKAGE_OA_RENDERERS: '!./packages/vckit-oa-renderers/'
EXCLUDED_PACKAGE_CREDENTIAL_OA: '!./packages/credential-oa/'
EXCLUDED_PACKAGE_EXPLORER: '!./packages/demo-explorer/'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Install pnpm
run: npm i pnpm --global

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '21'

- name: Install dependencies
run: pnpm i --filter ${{ env.EXCLUDED_PACKAGE_OA_RENDERERS }} --filter ${{ env.EXCLUDED_PACKAGE_CREDENTIAL_OA }} --filter ${{ env.EXCLUDED_PACKAGE_EXPLORER }} --no-frozen-lockfile

- name: Build
run: pnpm build:agent

- name: Run tests
run: |
pnpm test:packages --changedSince=origin/next --ci --json --coverage --testLocationInResults --outputFile=report.json

- name: Coverage
uses: artiomtr/jest-coverage-report-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage-file: report.json
base-coverage-file: report.json
threshold: 80
14 changes: 14 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default {
'!**/types/**',
'!**/build/**',
'!**/node_modules/**',
'!packages/vckit-oa-renderers',
'!packages/demo-explorer',
'!packages/credential-oa',
],
coverageReporters: ['text', 'lcov', 'json'],
coverageProvider: 'v8',
Expand All @@ -21,7 +24,9 @@ export default {
'<rootDir>/node_modules/',
'<rootDir>/packages/credential-ld/',
'<rootDir>/packages/vckit-oa-renderers/',
'<rootDir>/packages/demo-explorer/',
'<rootDir>/packages/credential-oa/',
'<rootDir>/.tmp_npm/',
],
testEnvironment: 'node',
automock: false,
Expand All @@ -37,4 +42,13 @@ export default {
},
],
},
// jest will fail if there is less than 80% branch, line, and function coverage, or if there are more than 10 uncovered statements
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
},
},
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"postinstall": "mkdir .tmp_npm; cd .tmp_npm; mkdir veramo; cd veramo; git init; git remote add -f origin https://github.com/gs-gs/veramo.git; git pull --depth=1 origin vc-v2; pnpm install; pnpm build;",
"build": "pnpm build:agent && pnpm build:explorer",
"build:agent": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --experimental-json-modules\" pnpm build:js && pnpm build:api && pnpm build:schema",
"build:js": "pnpm -r --stream --filter=!{@vckit/credential-oa,@vckit/oa-renderers,@vckit/demo-explorer} build",
"build:api": "pnpm --package=@vckit/cli -c dlx \"pnpm -r --stream --filter=!{@vckit/credential-oa,@vckit/oa-renderers,@vckit/demo-explorer} extract-api\"",
"build:js": "pnpm -r --stream --filter !./packages/vckit-oa-renderers/ --filter !./packages/credential-oa/ --filter !./packages/demo-explorer/ build",
"build:api": "pnpm --package=@vckit/cli -c dlx \"pnpm -r --stream --filter !./packages/vckit-oa-renderers/ --filter !./packages/credential-oa/ --filter !./packages/demo-explorer/ extract-api\"",
"build:schema": "pnpm --package=@vckit/cli -c dlx \"pnpm -r --stream generate-plugin-schema\"",
"build:explorer": "pnpm -r --stream --filter=@vckit/demo-explorer build",
"test": "pnpm test:packages",
Expand Down
Loading