-
Notifications
You must be signed in to change notification settings - Fork 724
208 lines (176 loc) · 6.92 KB
/
Copy pathtest.yml
File metadata and controls
208 lines (176 loc) · 6.92 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Test Suite
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
# Least-privilege token: this workflow only reads the repo (tests + coverage
# artifact upload need no write scopes)
permissions:
contents: read
env:
# Coverage threshold - configurable, not hardcoded
# Set to 0 to disable threshold enforcement
#
# NOTE: kcov cannot trace subprocess executions due to LD_PRELOAD limitations.
# When bats runs tests, it spawns new bash processes that kcov cannot instrument.
# This is a known limitation (see: https://github.com/bats-core/bats-core/issues/15)
# Coverage is kept as informational-only; test pass rate is the quality gate.
COVERAGE_THRESHOLD: 0
KCOV_VERSION: "42"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
# Test jobs never push — don't persist GITHUB_TOKEN in git config (#282)
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '18'
- name: Install dependencies
run: |
npm install
sudo apt-get update
sudo apt-get install -y jq
- name: Run unit tests
run: npm run test:unit
- name: Run integration tests
run: npm run test:integration || true
- name: Run E2E tests
run: npm run test:e2e
timeout-minutes: 15
- name: Generate test report
run: |
{
echo "## Test Results"
echo "✅ Unit tests passed"
echo "✅ E2E tests passed"
} >> "$GITHUB_STEP_SUMMARY"
coverage:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
# Test jobs never push — don't persist GITHUB_TOKEN in git config (#282)
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '18'
- name: Install dependencies
run: |
npm install
sudo apt-get update
sudo apt-get install -y jq
- name: Build and install kcov from source
run: |
# Install kcov build dependencies
sudo apt-get install -y \
cmake \
g++ \
binutils-dev \
libcurl4-openssl-dev \
libdw-dev \
libiberty-dev \
zlib1g-dev \
libssl-dev
# Clone and build kcov
git clone --depth 1 --branch v${KCOV_VERSION} https://github.com/SimonKagstrom/kcov.git /tmp/kcov-src
cd /tmp/kcov-src
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
sudo make install
# Verify installation
/usr/local/bin/kcov --version
- name: Verify kcov installation
run: |
which kcov
kcov --version
- name: Run tests with coverage
run: |
mkdir -p coverage
# Use full path to bats since kcov subprocess doesn't inherit npm PATH
BATS_CMD="$(pwd)/node_modules/.bin/bats"
# Run CLI parsing tests under kcov
kcov --include-path="$(pwd)/ralph_loop.sh,$(pwd)/lib" \
--exclude-pattern=tests/,node_modules/ \
coverage/cli-parsing \
bash -c "$BATS_CMD tests/unit/test_cli_parsing.bats" || true
# Run all unit tests under kcov for comprehensive coverage
kcov --include-path="$(pwd)/ralph_loop.sh,$(pwd)/lib" \
--exclude-pattern=tests/,node_modules/ \
coverage/all-unit \
bash -c "$BATS_CMD tests/unit/" || true
- name: Parse coverage results
id: coverage
run: |
# Extract coverage percentage from kcov JSON output
COVERAGE_FILE="coverage/all-unit/kcov-merged/coverage.json"
if [[ -f "$COVERAGE_FILE" ]]; then
COVERAGE_PCT=$(jq -r '.percent_covered // "0"' "$COVERAGE_FILE" | cut -d'.' -f1)
echo "coverage_percent=$COVERAGE_PCT" >> $GITHUB_OUTPUT
echo "Coverage: ${COVERAGE_PCT}%"
else
# Fallback: try to find any coverage.json
COVERAGE_FILE=$(find coverage -name "coverage.json" -type f 2>/dev/null | head -1)
if [[ -n "$COVERAGE_FILE" && -f "$COVERAGE_FILE" ]]; then
COVERAGE_PCT=$(jq -r '.percent_covered // "0"' "$COVERAGE_FILE" | cut -d'.' -f1)
echo "coverage_percent=$COVERAGE_PCT" >> $GITHUB_OUTPUT
echo "Coverage (from $COVERAGE_FILE): ${COVERAGE_PCT}%"
else
echo "coverage_percent=0" >> $GITHUB_OUTPUT
echo "Warning: Could not find coverage results"
# List what we do have for debugging
find coverage -type f -name "*.json" 2>/dev/null || echo "No JSON files found"
ls -laR coverage/ 2>/dev/null || echo "Coverage directory empty or not found"
fi
fi
- name: Check coverage threshold
run: |
COVERAGE=${{ steps.coverage.outputs.coverage_percent }}
THRESHOLD=${{ env.COVERAGE_THRESHOLD }}
echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Coverage | ${COVERAGE}% |" >> $GITHUB_STEP_SUMMARY
echo "| Threshold | ${THRESHOLD}% |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "$THRESHOLD" -eq 0 ]]; then
echo "✅ Coverage threshold enforcement disabled" >> $GITHUB_STEP_SUMMARY
echo "Coverage threshold enforcement disabled (COVERAGE_THRESHOLD=0)"
exit 0
fi
if [[ -z "$COVERAGE" || "$COVERAGE" == "0" ]]; then
echo "⚠️ Coverage measurement failed - skipping threshold check" >> $GITHUB_STEP_SUMMARY
echo "Coverage measurement failed - skipping threshold check"
exit 0
fi
if [[ "$COVERAGE" -lt "$THRESHOLD" ]]; then
echo "❌ Coverage ${COVERAGE}% is below threshold ${THRESHOLD}%" >> $GITHUB_STEP_SUMMARY
echo "::error::Coverage ${COVERAGE}% is below threshold ${THRESHOLD}%"
exit 1
else
echo "✅ Coverage ${COVERAGE}% meets threshold ${THRESHOLD}%" >> $GITHUB_STEP_SUMMARY
echo "Coverage ${COVERAGE}% meets threshold ${THRESHOLD}%"
fi
- name: Upload coverage artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: coverage-report
path: coverage/
retention-days: 7
- name: Upload coverage to Codecov (optional)
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
if: always()
continue-on-error: true
with:
directory: coverage/all-unit
fail_ci_if_error: false
verbose: true