Skip to content

Commit 9604962

Browse files
authored
Add GitHub Actions CI workflows (discord#196)
* Add CI workflows for building the package and dependencies * Init Go module for examples * Remove unused artifacts from deps * Patch OpenCV on Linux to fix invalid syntax * Disable unused python and java OpenCV bindings * Reduce max ImageOps size to avoid running out of memory * Close ImageOps when we're done with each test case * Clarify webp test names * Run CI on either main or master branch
1 parent 37dccac commit 9604962

File tree

8 files changed

+210
-9
lines changed

8 files changed

+210
-9
lines changed

.github/workflows/ci.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
workflow_dispatch:
13+
14+
jobs:
15+
16+
build:
17+
name: Build
18+
strategy:
19+
matrix:
20+
runs-on:
21+
- macos-14
22+
- ubuntu-22.04
23+
fail-fast: false
24+
runs-on: ${{ matrix.runs-on }}
25+
steps:
26+
- name: Check out repo
27+
uses: actions/checkout@v4
28+
29+
- name: Install Go
30+
uses: actions/setup-go@v5
31+
with:
32+
cache: false
33+
go-version: "1.23"
34+
35+
- name: Build
36+
run: go build
37+
38+
- name: Test
39+
run: go test -v
40+
41+
- name: Build examples
42+
run: |
43+
cd examples
44+
go build

.github/workflows/deps.yaml

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build dependencies
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- 'deps/**'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
paths:
15+
- 'deps/**'
16+
workflow_dispatch:
17+
18+
jobs:
19+
linux:
20+
name: Linux
21+
runs-on: ubuntu-22.04
22+
steps:
23+
- name: Check out repo
24+
uses: actions/checkout@v4
25+
26+
- name: Install build tools
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install nasm
30+
31+
- name: Build deps
32+
run: |
33+
export MAKEFLAGS="-j$(nproc)"
34+
./deps/build-deps-linux.sh
35+
36+
- run: |
37+
git status
38+
git diff
39+
40+
- name: Install Go
41+
uses: actions/setup-go@v5
42+
with:
43+
cache: false
44+
go-version: "1.23"
45+
46+
- name: Build and test lilliput with the new deps
47+
run: |
48+
go build
49+
go test -v
50+
51+
- name: Compress deps
52+
run: tar -czf deps.tar.gz deps/linux
53+
54+
- name: Upload deps artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: deps-linux.tar.gz
58+
path: deps.tar.gz
59+
60+
macos:
61+
name: macOS
62+
runs-on: macos-14
63+
steps:
64+
- name: Check out repo
65+
uses: actions/checkout@v4
66+
67+
- name: Install build tools
68+
run: |
69+
brew install autoconf
70+
brew install automake
71+
brew install coreutils # for ffmpeg build
72+
brew install libtool
73+
74+
- name: Build deps
75+
run: |
76+
export MAKEFLAGS="-j$(nproc)"
77+
./deps/build-deps-osx.sh
78+
79+
- run: |
80+
git status
81+
git diff
82+
83+
- name: Install Go
84+
uses: actions/setup-go@v5
85+
with:
86+
cache: false
87+
go-version: "1.23"
88+
89+
- name: Build and test lilliput with the new deps
90+
run: |
91+
go build
92+
go test -v
93+
94+
- name: Compress deps
95+
run: tar -czf deps.tar.gz deps/osx
96+
97+
- name: Upload deps artifact
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: deps-macos.tar.gz
101+
path: deps.tar.gz

deps/build-deps-linux.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ mkdir -p $BASEDIR/opencv
9191
tar -xzf $SRCDIR/opencv-3.2.0.tar.gz -C $BASEDIR/opencv --strip-components 1
9292
cd $BASEDIR/opencv
9393
patch -p1 < $SRCDIR/0001-export-exif-orientation.patch
94+
patch -p1 < $BASEDIR/patches/0001-remove-invalid-flow-control.patch
9495
mkdir -p $BUILDDIR/opencv
9596
cd $BUILDDIR/opencv
96-
cmake $BASEDIR/opencv -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_WEBP=ON -DWITH_JASPER=OFF -DWITH_TIFF=OFF -DWITH_OPENEXR=OFF -DWITH_OPENCL=OFF -DBUILD_JPEG=OFF -DBUILD_PNG=OFF -DBUILD_ZLIB=OFF -DENABLE_SSE41=ON -DENABLE_SSE42=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_DOCS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_videoio=OFF -DBUILD_opencv_highgui=OFF -DBUILD_opencv_ml=off -DBUILD_opencv_flann=off -DCMAKE_LIBRARY_PATH=$PREFIX/LIB -DCMAKE_INCLUDE_PATH=$PREFIX/INCLUDE -DCMAKE_INSTALL_PREFIX=$PREFIX
97+
cmake $BASEDIR/opencv -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_WEBP=ON -DWITH_JASPER=OFF -DWITH_TIFF=OFF -DWITH_OPENEXR=OFF -DWITH_OPENCL=OFF -DBUILD_JPEG=OFF -DBUILD_PNG=OFF -DBUILD_ZLIB=OFF -DENABLE_SSE41=ON -DENABLE_SSE42=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_DOCS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_videoio=OFF -DBUILD_opencv_highgui=OFF -DBUILD_opencv_ml=off -DBUILD_opencv_flann=off -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DCMAKE_LIBRARY_PATH=$PREFIX/LIB -DCMAKE_INCLUDE_PATH=$PREFIX/INCLUDE -DCMAKE_INSTALL_PREFIX=$PREFIX
9798
make
9899
make install
99100

@@ -116,9 +117,21 @@ $BASEDIR/ffmpeg/configure --prefix=$PREFIX --disable-doc --disable-programs --di
116117
make
117118
make install
118119

120+
rm -rf $BASEDIR/linux/$ARCH/bin
121+
rm -f $BASEDIR/linux/$ARCH/**/*.cmake
122+
119123
# Since go modules don't currently download symlinked files
120124
# (see https://github.com/golang/go/issues/39417)
121125
# we replace symlinks with copies of the target.
122126
# We use a `find -exec` with a separate file because POSIX sh
123127
# is that much more limited than bash.
124128
find "$PREFIX" -type l -exec "${BASEDIR}/copy-symlink-target.sh" {} \;
129+
130+
rm -rf $BASEDIR/linux/$ARCH/bin
131+
rm -f $BASEDIR/linux/$ARCH/**/*.cmake
132+
133+
if [ -n "$CI" ]; then
134+
echo "CI detected, cleaning up build artifacts"
135+
rm -rf "$SRCDIR"
136+
rm -rf "$BUILDDIR"
137+
fi

deps/build-deps-osx.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ cmake $BASEDIR/opencv \
319319
-DWITH_APPLE_VISION=OFF \
320320
-DWITH_COREIMAGE=OFF \
321321
-DWITH_CAROTENE=OFF \
322-
-DWITH_VIDEOTOOLBOX=ON
322+
-DWITH_VIDEOTOOLBOX=ON \
323+
-DBUILD_opencv_java=OFF \
324+
-DBUILD_opencv_python=OFF
323325

324326
# Remove iOS-specific build files
325327
sed -i '' "s|;$BASEDIR/opencv/modules/imgcodecs/include/opencv2/imgcodecs/ios.h||" $BASEDIR/build/opencv/CMakeCache.txt
@@ -349,10 +351,19 @@ $BASEDIR/ffmpeg/configure --prefix=$PREFIX --disable-doc --disable-programs --di
349351
make
350352
make install
351353

354+
rm -rf $BASEDIR/osx/$ARCH/bin
355+
rm -f $BASEDIR/osx/$ARCH/**/*.cmake
356+
352357
# Since go modules don't currently download symlinked files
353358
# (see https://github.com/golang/go/issues/39417)
354359
# we replace symlinks with copies of the target.
355360
# We use a `find -exec` with a separate file because POSIX sh
356361
# is that much more limited than bash.
357362
find "$PREFIX" -type l -exec "${BASEDIR}/copy-symlink-target.sh" {} \;
358363
echo "Done!"
364+
365+
if [ -n "$CI" ]; then
366+
echo "CI detected, cleaning up build artifacts"
367+
rm -rf "$SRCDIR"
368+
rm -rf "$BUILDDIR"
369+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake
2+
index 5bb0479..3d07b1c 100644
3+
--- a/cmake/OpenCVCompilerOptions.cmake
4+
+++ b/cmake/OpenCVCompilerOptions.cmake
5+
@@ -18,8 +18,6 @@ if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
6+
message(STATUS "Unable to compile program with enabled ccache, reverting...")
7+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}")
8+
endif()
9+
- else()
10+
- message(STATUS "Looking for ccache - not found")
11+
endif()
12+
endif()
13+
endif()

examples/go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module example
2+
3+
go 1.23.2
4+
5+
require github.com/discord/lilliput v0.0.0-20241012171911-37dccacf7c50 // indirect
6+
7+
replace github.com/discord/lilliput => ..

examples/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/discord/lilliput v0.0.0-20241012171911-37dccacf7c50 h1:5tSOh98txNCq1k4SwG4ZYCBjKjNg3fXHfdjOv8t4kBk=
2+
github.com/discord/lilliput v0.0.0-20241012171911-37dccacf7c50/go.mod h1:0euuUBAD72MAYRm2ElLaG1h0nBR+CgpfnKc/U6y/uE8=

webp_test.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
235235
resizeMethod: ImageOpsResize,
236236
},
237237
{
238-
name: "Animated WebP - Supported",
238+
name: "Animated WebP - Resize #1",
239239
inputPath: "testdata/ferry_sunset.webp",
240240
outputPath: "testdata/out/ferry_sunset_out_resize.webp",
241241
width: 266,
@@ -244,7 +244,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
244244
resizeMethod: ImageOpsResize,
245245
},
246246
{
247-
name: "Animated WebP - Supported",
247+
name: "Animated WebP - Resize #2",
248248
inputPath: "testdata/animated-webp-supported.webp",
249249
outputPath: "testdata/out/animated-webp-supported_out_resize.webp",
250250
width: 400,
@@ -253,7 +253,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
253253
resizeMethod: ImageOpsResize,
254254
},
255255
{
256-
name: "Animated WebP - Supported",
256+
name: "Animated WebP - Fit #1",
257257
inputPath: "testdata/animated-webp-supported.webp",
258258
outputPath: "testdata/out/animated-webp-supported_out_fit.webp",
259259
width: 400,
@@ -262,7 +262,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
262262
resizeMethod: ImageOpsFit,
263263
},
264264
{
265-
name: "Animated WebP - Supported",
265+
name: "Animated WebP - No resize",
266266
inputPath: "testdata/animated-webp-supported.webp",
267267
outputPath: "testdata/out/animated-webp-supported_out_no_resize.webp",
268268
width: 0,
@@ -271,7 +271,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
271271
resizeMethod: ImageOpsNoResize,
272272
},
273273
{
274-
name: "Animated WebP - Supported",
274+
name: "Animated WebP - Fit #2",
275275
inputPath: "testdata/animated-webp-supported.webp",
276276
outputPath: "testdata/out/animated-webp-supported_out.webp",
277277
width: 200,
@@ -341,18 +341,20 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
341341
DisableAnimatedOutput: tc.disableAnimatedOutput,
342342
}
343343

344-
ops := NewImageOps(50000)
344+
ops := NewImageOps(2000)
345345
var newDst []byte
346346
newDst, err = ops.Transform(decoder, options, dstBuf)
347347
if err != nil {
348348
decoder.Close()
349+
ops.Close()
349350
t.Errorf("Transform() error for %s: %v", tc.inputPath, err)
350351
return
351352
}
352353

353354
// verify length of newDst
354355
if len(newDst) == 0 {
355356
decoder.Close()
357+
ops.Close()
356358
t.Errorf("Transform() returned empty data for %s", tc.inputPath)
357359
}
358360

@@ -362,17 +364,20 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
362364
if _, err := os.Stat("testdata/out"); os.IsNotExist(err) {
363365
if err = os.Mkdir("testdata/out", 0755); err != nil {
364366
decoder.Close()
367+
ops.Close()
365368
t.Errorf("Failed to create output directory: %v", err)
366369
return
367370
}
368371
}
369372

370373
if err = os.WriteFile(tc.outputPath, newDst, 0644); err != nil {
371374
decoder.Close()
375+
ops.Close()
372376
t.Errorf("Failed to write %s: %v", tc.outputPath, err)
373377
}
374378
}
375379
decoder.Close()
380+
ops.Close()
376381
})
377382
}
378383
}
@@ -429,18 +434,20 @@ func testNewWebpEncoderWithAnimatedGIFSource(t *testing.T) {
429434
EncodeTimeout: time.Second * 300,
430435
}
431436

432-
ops := NewImageOps(50000)
437+
ops := NewImageOps(2000)
433438
var newDst []byte
434439
newDst, err = ops.Transform(decoder, options, dstBuf)
435440
if err != nil {
436441
decoder.Close()
442+
ops.Close()
437443
t.Errorf("Transform() error for %s: %v", tc.inputPath, err)
438444
return
439445
}
440446

441447
// verify length of newDst
442448
if len(newDst) == 0 {
443449
decoder.Close()
450+
ops.Close()
444451
t.Errorf("Transform() returned empty data for %s", tc.inputPath)
445452
}
446453

@@ -450,17 +457,20 @@ func testNewWebpEncoderWithAnimatedGIFSource(t *testing.T) {
450457
if _, err := os.Stat("testdata/out"); os.IsNotExist(err) {
451458
if err = os.Mkdir("testdata/out", 0755); err != nil {
452459
decoder.Close()
460+
ops.Close()
453461
t.Errorf("Failed to create output directory: %v", err)
454462
return
455463
}
456464
}
457465

458466
if err = os.WriteFile(tc.outputPath, newDst, 0644); err != nil {
459467
decoder.Close()
468+
ops.Close()
460469
t.Errorf("Failed to write %s: %v", tc.outputPath, err)
461470
}
462471
}
463472
decoder.Close()
473+
ops.Close()
464474
})
465475
}
466476
}

0 commit comments

Comments
 (0)