Skip to content

Commit ff49b63

Browse files
committed
ci.yml: reduce duplication using a matrix
Assisted-by: Cursor
1 parent e3f5156 commit ff49b63

1 file changed

Lines changed: 103 additions & 129 deletions

File tree

.github/workflows/ci.yml

Lines changed: 103 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,47 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os == 'alpine' && 'ubuntu-latest' || 'ubuntu-latest' }}
12+
container: ${{ matrix.os == 'alpine' && 'alpine:latest' || null }}
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
# Ubuntu tests
19+
- name: "Ubuntu with PCRE2 + Coverage"
20+
os: ubuntu
21+
pcre2: true
22+
coverage: true
23+
configure_flags: "--with-pcre2"
24+
25+
- name: "Ubuntu without PCRE2"
26+
os: ubuntu
27+
pcre2: false
28+
coverage: false
29+
configure_flags: "--without-pcre2"
30+
31+
# Alpine (musl) tests
32+
- name: "Musl with PCRE2"
33+
os: alpine
34+
pcre2: true
35+
coverage: false
36+
configure_flags: "--with-pcre2"
37+
38+
- name: "Musl without PCRE2"
39+
os: alpine
40+
pcre2: false
41+
coverage: false
42+
configure_flags: "--without-pcre2"
43+
44+
name: ${{ matrix.name }}
1245

1346
steps:
1447
- uses: actions/checkout@v4
1548

16-
- name: Install dependencies
49+
# Install dependencies - Ubuntu
50+
- name: Install dependencies (Ubuntu)
51+
if: matrix.os == 'ubuntu'
1752
run: |
1853
sudo apt-get update
1954
sudo apt-get install -y \
@@ -28,23 +63,80 @@ jobs:
2863
gnulib \
2964
lcov
3065
66+
# Install dependencies - Alpine with PCRE2
67+
- name: Install dependencies (Alpine with PCRE2)
68+
if: matrix.os == 'alpine' && matrix.pcre2
69+
run: |
70+
apk add --no-cache \
71+
build-base \
72+
autoconf \
73+
automake \
74+
perl \
75+
patch \
76+
diffutils \
77+
xmlto \
78+
pcre2-dev \
79+
bash \
80+
git \
81+
coreutils \
82+
python3
83+
84+
# Install dependencies - Alpine without PCRE2
85+
- name: Install dependencies (Alpine without PCRE2)
86+
if: matrix.os == 'alpine' && !matrix.pcre2
87+
run: |
88+
apk add --no-cache \
89+
build-base \
90+
autoconf \
91+
automake \
92+
perl \
93+
patch \
94+
diffutils \
95+
xmlto \
96+
bash \
97+
git \
98+
coreutils \
99+
python3
100+
101+
# Bootstrap - Ubuntu
31102
- name: Bootstrap
103+
if: matrix.os == 'ubuntu'
32104
run: ./bootstrap
33105

106+
# Bootstrap - Alpine
107+
- name: Bootstrap (Alpine)
108+
if: matrix.os == 'alpine'
109+
run: |
110+
./gnulib-update.sh
111+
export PATH="/tmp/gnulib:$PATH"
112+
./bootstrap
113+
114+
# Configure
34115
- name: Configure
35116
run: |
36-
./configure \
37-
--with-pcre2 \
38-
CFLAGS="--coverage -g -O0" \
39-
LDFLAGS="--coverage"
117+
CFLAGS_EXTRA=""
118+
LDFLAGS_EXTRA=""
119+
120+
if [ "${{ matrix.coverage }}" = "true" ]; then
121+
CFLAGS_EXTRA="--coverage -g -O0"
122+
LDFLAGS_EXTRA="--coverage"
123+
fi
40124
125+
./configure ${{ matrix.configure_flags }} \
126+
${CFLAGS_EXTRA:+CFLAGS="$CFLAGS_EXTRA"} \
127+
${LDFLAGS_EXTRA:+LDFLAGS="$LDFLAGS_EXTRA"}
128+
129+
# Build
41130
- name: Build
42131
run: make -j$(nproc)
43132

133+
# Test
44134
- name: Run tests
45135
run: make check
46136

137+
# Coverage reporting (only for coverage builds)
47138
- name: Generate coverage report
139+
if: matrix.coverage
48140
run: |
49141
# Create coverage directory
50142
mkdir -p coverage
@@ -73,6 +165,7 @@ jobs:
73165
echo "FUNCTIONS_COVERED=$FUNCTIONS_COVERED" >> $GITHUB_ENV
74166
75167
- name: Upload coverage to Codecov
168+
if: matrix.coverage
76169
uses: codecov/codecov-action@v4
77170
with:
78171
file: ./coverage/coverage_filtered.info
@@ -81,6 +174,7 @@ jobs:
81174
fail_ci_if_error: false
82175
token: ${{ secrets.CODECOV_TOKEN }}
83176

177+
# Show failures
84178
- name: Show test results on failure
85179
if: failure()
86180
run: |
@@ -92,38 +186,10 @@ jobs:
92186
cat "$f" 2>/dev/null || echo "Cannot read file"
93187
done
94188
95-
test-without-pcre2:
189+
# Separate distcheck job (doesn't fit well in matrix)
190+
distcheck:
96191
runs-on: ubuntu-latest
97-
steps:
98-
- uses: actions/checkout@v4
99-
100-
- name: Install dependencies (without PCRE2)
101-
run: |
102-
sudo apt-get update
103-
sudo apt-get install -y \
104-
autoconf \
105-
automake \
106-
build-essential \
107-
perl \
108-
patch \
109-
diffutils \
110-
xmlto \
111-
gnulib
112-
113-
- name: Bootstrap
114-
run: ./bootstrap
115-
116-
- name: Configure without PCRE2
117-
run: ./configure --without-pcre2
118192

119-
- name: Build
120-
run: make -j$(nproc)
121-
122-
- name: Run tests
123-
run: make check
124-
125-
test-distcheck:
126-
runs-on: ubuntu-latest
127193
steps:
128194
- uses: actions/checkout@v4
129195

@@ -150,46 +216,6 @@ jobs:
150216
- name: Build and test distribution
151217
run: make distcheck
152218

153-
test-musl:
154-
runs-on: ubuntu-latest
155-
container: alpine:latest
156-
steps:
157-
- uses: actions/checkout@v4
158-
159-
- name: Install dependencies
160-
run: |
161-
apk add --no-cache \
162-
build-base \
163-
autoconf \
164-
automake \
165-
perl \
166-
patch \
167-
diffutils \
168-
xmlto \
169-
pcre2-dev \
170-
bash \
171-
git \
172-
coreutils \
173-
python3
174-
175-
- name: Clone gnulib for bootstrap
176-
run: |
177-
./gnulib-update.sh
178-
179-
- name: Bootstrap
180-
run: |
181-
export PATH="/tmp/gnulib:$PATH"
182-
./bootstrap
183-
184-
- name: Configure
185-
run: ./configure --with-pcre2
186-
187-
- name: Build
188-
run: make -j$(nproc)
189-
190-
- name: Run tests
191-
run: make check
192-
193219
- name: Show test results on failure
194220
if: failure()
195221
run: |
@@ -199,56 +225,4 @@ jobs:
199225
find test-arena -type f 2>/dev/null | head -20 | while read f; do
200226
echo "=== $f ==="
201227
cat "$f" 2>/dev/null || echo "Cannot read file"
202-
done
203-
204-
test-musl-without-pcre2:
205-
runs-on: ubuntu-latest
206-
container: alpine:latest
207-
steps:
208-
- uses: actions/checkout@v4
209-
210-
- name: Install dependencies (without PCRE2)
211-
run: |
212-
apk add --no-cache \
213-
build-base \
214-
autoconf \
215-
automake \
216-
perl \
217-
patch \
218-
diffutils \
219-
xmlto \
220-
bash \
221-
git \
222-
coreutils \
223-
python3
224-
225-
- name: Clone gnulib for bootstrap
226-
run: |
227-
./gnulib-update.sh
228-
229-
- name: Bootstrap
230-
run: |
231-
export PATH="/tmp/gnulib:$PATH"
232-
./bootstrap
233-
234-
- name: Configure without PCRE2
235-
run: ./configure --without-pcre2
236-
237-
- name: Build
238-
run: make -j$(nproc)
239-
240-
- name: Run tests
241-
run: make check
242-
243-
- name: Show test results on failure
244-
if: failure()
245-
run: |
246-
echo "=== Test logs ==="
247-
find . -name "*.log" -type f -exec echo "=== {} ===" \; -exec cat {} \;
248-
echo "=== Test arena contents ==="
249-
find test-arena -type f 2>/dev/null | head -20 | while read f; do
250-
echo "=== $f ==="
251-
cat "$f" 2>/dev/null || echo "Cannot read file"
252-
done
253-
254-
228+
done

0 commit comments

Comments
 (0)