Skip to content

API connector to model server #61

API connector to model server

API connector to model server #61

# Pre-merge Checks (for Nodejs/Typescript projects)
# 1. Unit tests with code coverage (jest)
# 2. Code quality analysis (lint)
# 3. Dependency analysis (vulnerabilities)
# 4. Dependency analysis (undesirable licenses)
# 5. Deploy reports generated from the above to GitHub Pages
name: Pre-Merge Checks (ai-verify-portal)
on:
# Runs when a pull request to main is being assigned
pull_request:
types: [assigned, synchronize]
branches:
- "main"
paths:
- "ai-verify-portal/**"
# Run this workflow manually from Actions tab
workflow_dispatch:
# Allow one concurrent deployment
concurrency:
group: ${{ github.repository }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
pre-merge-checks:
# Run only when PR is assigned, even on subsequent commits (i.e. synchronize)
if: (github.event_name == 'pull_request' && github.event.pull_request.assignee != null) || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3
with:
sparse-checkout: |
ai-verify-portal
ai-verify-shared-library
# Install dependencies
- name: Setup npm cache/install
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: ai-verify-portal
- name: Install dependencies for shared-library
working-directory: ${{ github.workspace }}/ai-verify-shared-library
run: |
npm install --omit=dev
npx license-checker --summary --out licenses-found.txt -y
npm install -D
npm run build
- name: Install dependencies for portal
working-directory: ${{ github.workspace }}/ai-verify-portal
run: |
npm install --omit=dev
npx license-checker --summary --out licenses-found.txt -y
npm install -D
npm i -D badge-maker
npm i -D eslint-formatter-html
npm link ../ai-verify-shared-library
# Compile typescript source files
- name: Build portal (next build)
working-directory: ${{ github.workspace }}/ai-verify-portal
run: |
cp .env.development .env
npm run build
# Format check
- name: Format check
if: ${{ ! cancelled() }}
working-directory: ${{ github.workspace }}/ai-verify-portal
run: |
npm run format-check
# Unit Tests & Coverage
- name: Unit tests with coverage
if: ${{ ! cancelled() }}
working-directory: ${{ github.workspace }}/ai-verify-portal
timeout-minutes: 30
run: |
set +e
sudo timedatectl set-timezone Asia/Singapore
npm run coverage
exit_code_jest=$?
node ci/createBadges.mjs test
node ci/createBadges.mjs coverage
set -e
if [ $exit_code_jest -ne 0 ]; then
echo "jest failed, exiting..."
exit $exit_code_jest
fi
# eslint
- name: Code quality analysis - lint
if: ${{ ! cancelled() }}
working-directory: ${{ github.workspace }}/ai-verify-portal
run: |
set +e
npm run lint
exit_code_lint=$?
npm run lint-html-report
npm run lint-json-report
node ci/createBadges.mjs lint
set -e
if [ $exit_code_lint -ne 0 ]; then
echo "lint failed, exiting..."
exit $exit_code_lint
fi
# npm audit
- name: Dependency analysis - vulnerabilities & licenses
if: ${{ ! cancelled() }}
working-directory: ${{ github.workspace }}/ai-verify-portal
run: |
set +e
npm audit --omit=dev
exit_code_audit=$?
npm audit --omit=dev --json | npx npm-audit-markdown --output npm-audit-report.md
npx markdown-to-html-cli --source npm-audit-report.md --output npm-audit-report.html -y
echo -e "License Check Summary for portal\n" > license-report.txt
cat licenses-found.txt >> license-report.txt
echo -e "\nLicense Check Summary for shared-library\n" >> license-report.txt
cat ../ai-verify-shared-library/licenses-found.txt >> license-report.txt
cat license-report.txt
cp license-report.txt licenses-found.txt
node ci/createBadges.mjs dependency
node ci/createBadges.mjs license
set -e
if [ $exit_code_audit -ne 0 ]; then
echo "npm audit failed, exiting..."
exit $exit_code_audit
fi
### Publish reports to ci dashboard ###
- name: Checkout dashboard
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && always() }}
uses: actions/checkout@v3
with:
repository: IMDA-BTG/ci-dashboard
token: ${{ secrets.CHECKOUT_TOKEN }}
ref: main
path: check-results
- name: Push results to dashboard
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && always() }}
working-directory: ${{ github.workspace }}/check-results
run: |
set +e
find ../ -type f -name ".gitignore" -exec rm {} +
[ -d "docs/pre-merge/portal" ] && rm -rf docs/pre-merge/portal
mkdir -p docs/pre-merge/portal
mv ../ai-verify-portal/coverage docs/pre-merge/portal/
mv ../ai-verify-portal/*.svg docs/pre-merge/portal/
mv ../ai-verify-portal/*.html docs/pre-merge/portal/
mv ../ai-verify-portal/*.md docs/pre-merge/portal/
mv ../ai-verify-portal/*.txt docs/pre-merge/portal/
git add docs/pre-merge/portal
git config user.name "imda-btg"
git config user.email "[email protected]"
git commit -m "feat(portal) actions publish portal reports to dashboard"
git push
set -e