brackt/.github/workflows/test.yml

90 lines
2.4 KiB
YAML

name: Test
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: brackt_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run type check
run: npm run typecheck
continue-on-error: true
- name: Run unit tests
run: npm run test:run
env:
DATABASE_URL: postgresql://test:test@localhost:5432/brackt_test
- name: Upload test coverage
uses: codecov/codecov-action@v3
if: always()
with:
files: ./coverage/coverage-final.json
flags: unittests
continue-on-error: true
- name: Comment test results on PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request' && always()
with:
script: |
const fs = require('fs');
let coverageComment = '## ✅ Tests Passed\n\n';
try {
const coverage = JSON.parse(fs.readFileSync('./coverage/coverage-summary.json', 'utf8'));
const total = coverage.total;
coverageComment += '**Coverage:**\n';
coverageComment += `- Lines: ${total.lines.pct}%\n`;
coverageComment += `- Statements: ${total.statements.pct}%\n`;
coverageComment += `- Functions: ${total.functions.pct}%\n`;
coverageComment += `- Branches: ${total.branches.pct}%\n`;
} catch (error) {
coverageComment += 'Coverage report not available.\n';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: coverageComment
});
continue-on-error: true