# GitHub Actions Workflow: Coverage Reports for Pull Requests
#
# This workflow runs tests with coverage on PRs and comments the results.
# Actual deployment to GitHub Pages is handled by docs.yml workflow.
#
# Coverage reports on the live site:
# https://gitlab-mcp.sw.foundation/coverage/
name: Coverage Report
on:
pull_request:
branches:
- main
paths:
- "src/**"
- "package.json"
- "yarn.lock"
- "tsconfig.json"
- "jest.config.*"
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
issues: write
jobs:
coverage:
name: Generate Coverage Report
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Enable Corepack
run: corepack enable
- name: Install dependencies
run: yarn install --immutable
- name: Generate Prisma client
run: yarn prisma generate
- name: Run tests with coverage
run: yarn test:cov
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(cat coverage/lcov-report/index.html | grep -o 'class="strong">[0-9.]*%' | head -1 | grep -o '[0-9.]*')
echo "percentage=${COVERAGE:-0}" >> $GITHUB_OUTPUT
- name: Comment coverage on PR
continue-on-error: true
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
let summary;
try {
const json = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
const t = json.total;
summary = [
'## Test Coverage Report',
'',
`**Overall Coverage:** ${t.lines.pct}%`,
'',
'| Metric | Percentage |',
'|--------|------------|',
`| Statements | ${t.statements.pct}% |`,
`| Branches | ${t.branches.pct}% |`,
`| Functions | ${t.functions.pct}% |`,
`| Lines | ${t.lines.pct}% |`,
'',
'[View detailed coverage report](https://gitlab-mcp.sw.foundation/coverage/)',
].join('\n');
} catch {
summary = `## Test Coverage Report\n\n**Coverage:** ${{ steps.coverage.outputs.percentage }}%`;
}
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.data.find(c => c.body.includes('## Test Coverage Report'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: summary
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: summary
});
}
- name: Upload coverage artifacts
uses: actions/upload-artifact@v6
with:
name: coverage-reports-${{ github.sha }}
path: coverage/
retention-days: 14