Skip to content

Unit Tests

Unit Tests #3

Workflow file for this run

name: Unit Tests
# TODO: look into github composite actions
on:
workflow_dispatch:
pull_request:
types: [opened]
branches: [main]
paths:
- 'libs/utils/**.js'
- '**/vitest.config.js'
- '.github/workflows/unit-tests.yaml'
jobs:
changes:
runs-on: ubuntu-latest
outputs:
libs-utils: ${{ steps.filter.outputs.libs-utils }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
libs-utils:
- added|modified: 'libs/utils/**.js'
- .github/workflows/unit-tests.yaml
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
continue-on-error: false
libs-utils:
runs-on: ubuntu-latest
needs: [changes, setup]
if: ${{ needs.changes.outputs.libs-utils == 'true' || (github.event_name == 'workflow_dispatch') }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Get pnpm cache
uses: actions/cache@v3
with:
path: '${{ env.STORE_PATH }}'
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Run unit tests
run: pnpm test:ci --filter=@libs/utils
continue-on-error: false
- name: Code coverage
uses: irongut/[email protected]
with:
filename: libs/utils/coverage/cobertura-coverage.xml
badge: true
fail_below_min: true
format: markdown
thresholds: '80 90'
output: both
indicators: true
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
header: '@libs/utils'
hide_and_recreate: true
hide_classify: "OUTDATED"
path: code-coverage-results.md