-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (92 loc) · 3.05 KB
/
coverage.yml
File metadata and controls
104 lines (92 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Reusable coverage workflow — called by consumer repos
# Usage: uses: Solvely-Colin/solvely-launchpad/.github/workflows/coverage.yml@v1
name: Tests & Coverage
on:
workflow_call:
inputs:
node-version:
description: 'Node.js version'
type: string
default: '22'
package-manager:
description: 'Package manager (npm, pnpm, yarn)'
type: string
default: 'npm'
coverage-command:
description: 'Coverage command'
type: string
default: 'npx vitest run --coverage'
has-build:
description: 'Run build before coverage'
type: boolean
default: true
build-command:
description: 'Build command'
type: string
default: ''
permissions:
contents: read
concurrency:
group: coverage-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
coverage:
name: Tests with coverage
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: ${{ inputs.node-version }}
cache: ${{ inputs.package-manager }}
- name: Enable corepack
if: inputs.package-manager != 'npm'
run: corepack enable
- name: Install dependencies
run: |
if [ "${{ inputs.package-manager }}" = "pnpm" ]; then
pnpm install --frozen-lockfile
elif [ "${{ inputs.package-manager }}" = "yarn" ]; then
yarn install --frozen-lockfile
else
npm ci
fi
- name: Build
if: ${{ inputs.has-build }}
run: |
BUILD_CMD="${{ inputs.build-command }}"
if [ -z "$BUILD_CMD" ]; then
if [ "${{ inputs.package-manager }}" = "pnpm" ]; then
BUILD_CMD="pnpm run build"
elif [ "${{ inputs.package-manager }}" = "yarn" ]; then
BUILD_CMD="yarn build"
else
BUILD_CMD="npm run build"
fi
fi
$BUILD_CMD
- name: Run tests with coverage
run: ${{ inputs.coverage-command }}
- name: Upload coverage artifact
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: coverage
path: coverage/
- name: Coverage summary
if: always()
run: |
if [ -f coverage/coverage-summary.json ]; then
echo "## Coverage Summary" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
node -e "
const c = require('./coverage/coverage-summary.json').total;
for (const [k, v] of Object.entries(c)) {
console.log(k.padEnd(12) + ': ' + v.pct + '%');
}
" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
else
echo "No coverage summary found" >> "$GITHUB_STEP_SUMMARY"
fi