-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (207 loc) · 7.71 KB
/
bdd-matrix.yml
File metadata and controls
214 lines (207 loc) · 7.71 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
209
210
211
212
213
214
name: BDD Matrix
permissions:
contents: read
on:
pull_request:
branches: [ main ]
paths:
- '**.go'
- 'go.*'
- 'modules/**'
- '.github/workflows/bdd-matrix.yml'
push:
branches: [ main ]
paths:
- '**.go'
- 'go.*'
- 'modules/**'
- '.github/workflows/bdd-matrix.yml'
workflow_dispatch:
env:
GO_VERSION: '^1.26'
jobs:
# Discover modules (reused for matrix)
discover:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.set-matrix.outputs.modules }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- id: set-matrix
run: |
ALL_MODULES=$(find modules -maxdepth 1 -mindepth 1 -type d -exec basename {} \; | sort)
MODULES_JSON=$(echo "$ALL_MODULES" | tr ' ' '\n' | grep -v '^$' | jq -R . | jq -s .)
echo "Modules: $MODULES_JSON"
{
echo "matrix<<EOF"; echo "{\"module\":$MODULES_JSON}"; echo "EOF"; } >> $GITHUB_OUTPUT
{ echo "modules<<EOF"; echo "$MODULES_JSON"; echo "EOF"; } >> $GITHUB_OUTPUT
# Core framework BDD tests (single job)
core-bdd:
runs-on: ubuntu-latest
needs: discover
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
cache: true
- name: Run core framework BDD tests
run: |
set -e
echo '=== Core Framework BDD Tests ==='
export CGO_ENABLED=1
export GORACE=halt_on_error=1
go test -race -v -coverprofile=core-bdd-coverage.txt -covermode=atomic -run 'TestApplicationLifecycle|TestConfigurationManagement|TestBaseConfigBDDFeatures|TestLoggerDecorator' .
- name: Upload core BDD coverage
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: GoCodeAlone/modular
files: core-bdd-coverage.txt
flags: core-bdd
- name: Persist core BDD coverage artifact
uses: actions/upload-artifact@v7
with:
name: core-bdd-coverage
path: core-bdd-coverage.txt
# Run each module's BDD tests in parallel matrix
module-bdd:
runs-on: ubuntu-latest
needs: discover
permissions:
contents: read
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.discover.outputs.matrix) }}
name: BDD ${{ matrix.module }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
cache: true
- name: Run BDD tests
working-directory: modules/${{ matrix.module }}
run: |
echo "=== BDD for ${{ matrix.module }} ==="
# Run BDD-focused Go tests (naming convention: *BDD*)
export CGO_ENABLED=1
export GORACE=halt_on_error=1
set -euo pipefail
# Modules expected to contain BDD tests (update as coverage grows)
EXPECTED_BDD_MODULES=(reverseproxy cache auth database eventbus)
expected=false
for m in "${EXPECTED_BDD_MODULES[@]}"; do
if [ "$m" = "${{ matrix.module }}" ]; then expected=true; break; fi
done
if go test -race -v -coverprofile=bdd-${{ matrix.module }}-coverage.txt -covermode=atomic -run '.*BDD|.*Module' .; then
echo "BDD tests executed for ${{ matrix.module }}"
else
echo "::error title=BDD Tests Failed::go test command failed for ${{ matrix.module }}" >&2
exit 1
fi
if [ ! -s bdd-${{ matrix.module }}-coverage.txt ]; then
if [ "$expected" = true ]; then
echo "::error title=Missing Expected BDD Tests::Module ${{ matrix.module }} is in EXPECTED_BDD_MODULES but produced no BDD coverage" >&2
exit 1
else
echo "::notice title=No BDD Tests Detected::No matching BDD tests for non-BDD module ${{ matrix.module }}" >&2
echo 'mode: atomic' > bdd-${{ matrix.module }}-coverage.txt
fi
fi
- name: Upload module BDD coverage
if: always()
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: GoCodeAlone/modular
files: modules/${{ matrix.module }}/bdd-${{ matrix.module }}-coverage.txt
flags: bdd-${{ matrix.module }}
- name: Persist module BDD coverage artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: bdd-${{ matrix.module }}-coverage
path: modules/${{ matrix.module }}/bdd-${{ matrix.module }}-coverage.txt
# Summary job collates results
summary:
if: always()
needs: [core-bdd, module-bdd, discover]
runs-on: ubuntu-latest
steps:
- name: Checkout repository (for merge script)
uses: actions/checkout@v6
- name: Summarize
run: |
echo '# BDD Matrix Summary' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo 'Core BDD Job: ${{ needs.core-bdd.result }}' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo 'Modules (parallel) overall result: ${{ needs.module-bdd.result }}' >> $GITHUB_STEP_SUMMARY
- name: Download all coverage artifacts
uses: actions/download-artifact@v8
with:
path: bdd-coverage
- name: Merge BDD coverage
run: |
set -euo pipefail
ls -R bdd-coverage || true
shopt -s globstar nullglob
FILES=(bdd-coverage/**/*.txt)
if [ ${#FILES[@]} -eq 0 ]; then
echo "No coverage files found to merge" >&2
# Nothing to do (don't fail)
exit 0
fi
echo "Found ${#FILES[@]} coverage profiles"
# Prefer central script if present, else inline merge
if [ -f scripts/merge-coverprofiles.sh ]; then
chmod +x scripts/merge-coverprofiles.sh
if ! ./scripts/merge-coverprofiles.sh merged-bdd-coverage.txt "${FILES[@]}"; then
echo "[warn] merge-coverprofiles.sh failed, falling back to inline merge" >&2
else
echo "Merged via script"; exit 0
fi
else
echo "[info] merge-coverprofiles.sh not found, using inline merge" >&2
fi
# Inline merge fallback
OUT=merged-bdd-coverage.txt
FIRST=1
: > "$OUT"
for f in "${FILES[@]}"; do
[ -f "$f" ] || { echo "[warn] Missing profile $f" >&2; continue; }
if [ $FIRST -eq 1 ]; then
cat "$f" >> "$OUT"; FIRST=0
else
{ grep -v '^mode:' "$f" || true; } >> "$OUT"
fi
done
# Ensure a mode line exists at top
if ! grep -q '^mode:' "$OUT"; then
echo 'mode: atomic' | cat - "$OUT" > "$OUT.tmp" && mv "$OUT.tmp" "$OUT"
fi
# Never fail this step due to merge nuances
true
echo "Merged (fallback) into $OUT from ${#FILES[@]} files" >&2
- name: Upload merged BDD coverage
if: always()
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: GoCodeAlone/modular
files: merged-bdd-coverage.txt
flags: merged-bdd
- name: Persist merged BDD coverage artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: merged-bdd-coverage
path: merged-bdd-coverage.txt