Skip to content

Commit

Permalink
Add GitHub Actions CI workflows (#196)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
acj authored Oct 31, 2024
1 parent 37dccac commit 9604962
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 9 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:

jobs:

build:
name: Build
strategy:
matrix:
runs-on:
- macos-14
- ubuntu-22.04
fail-fast: false
runs-on: ${{ matrix.runs-on }}
steps:
- name: Check out repo
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
cache: false
go-version: "1.23"

- name: Build
run: go build

- name: Test
run: go test -v

- name: Build examples
run: |
cd examples
go build
101 changes: 101 additions & 0 deletions .github/workflows/deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build dependencies

on:
push:
branches:
- main
- master
paths:
- 'deps/**'
pull_request:
branches:
- main
- master
paths:
- 'deps/**'
workflow_dispatch:

jobs:
linux:
name: Linux
runs-on: ubuntu-22.04
steps:
- name: Check out repo
uses: actions/checkout@v4

- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install nasm
- name: Build deps
run: |
export MAKEFLAGS="-j$(nproc)"
./deps/build-deps-linux.sh
- run: |
git status
git diff
- name: Install Go
uses: actions/setup-go@v5
with:
cache: false
go-version: "1.23"

- name: Build and test lilliput with the new deps
run: |
go build
go test -v
- name: Compress deps
run: tar -czf deps.tar.gz deps/linux

- name: Upload deps artifact
uses: actions/upload-artifact@v4
with:
name: deps-linux.tar.gz
path: deps.tar.gz

macos:
name: macOS
runs-on: macos-14
steps:
- name: Check out repo
uses: actions/checkout@v4

- name: Install build tools
run: |
brew install autoconf
brew install automake
brew install coreutils # for ffmpeg build
brew install libtool
- name: Build deps
run: |
export MAKEFLAGS="-j$(nproc)"
./deps/build-deps-osx.sh
- run: |
git status
git diff
- name: Install Go
uses: actions/setup-go@v5
with:
cache: false
go-version: "1.23"

- name: Build and test lilliput with the new deps
run: |
go build
go test -v
- name: Compress deps
run: tar -czf deps.tar.gz deps/osx

- name: Upload deps artifact
uses: actions/upload-artifact@v4
with:
name: deps-macos.tar.gz
path: deps.tar.gz
15 changes: 14 additions & 1 deletion deps/build-deps-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ mkdir -p $BASEDIR/opencv
tar -xzf $SRCDIR/opencv-3.2.0.tar.gz -C $BASEDIR/opencv --strip-components 1
cd $BASEDIR/opencv
patch -p1 < $SRCDIR/0001-export-exif-orientation.patch
patch -p1 < $BASEDIR/patches/0001-remove-invalid-flow-control.patch
mkdir -p $BUILDDIR/opencv
cd $BUILDDIR/opencv
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
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
make
make install

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

rm -rf $BASEDIR/linux/$ARCH/bin
rm -f $BASEDIR/linux/$ARCH/**/*.cmake

# Since go modules don't currently download symlinked files
# (see https://github.com/golang/go/issues/39417)
# we replace symlinks with copies of the target.
# We use a `find -exec` with a separate file because POSIX sh
# is that much more limited than bash.
find "$PREFIX" -type l -exec "${BASEDIR}/copy-symlink-target.sh" {} \;

rm -rf $BASEDIR/linux/$ARCH/bin
rm -f $BASEDIR/linux/$ARCH/**/*.cmake

if [ -n "$CI" ]; then
echo "CI detected, cleaning up build artifacts"
rm -rf "$SRCDIR"
rm -rf "$BUILDDIR"
fi
13 changes: 12 additions & 1 deletion deps/build-deps-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ cmake $BASEDIR/opencv \
-DWITH_APPLE_VISION=OFF \
-DWITH_COREIMAGE=OFF \
-DWITH_CAROTENE=OFF \
-DWITH_VIDEOTOOLBOX=ON
-DWITH_VIDEOTOOLBOX=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python=OFF

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

rm -rf $BASEDIR/osx/$ARCH/bin
rm -f $BASEDIR/osx/$ARCH/**/*.cmake

# Since go modules don't currently download symlinked files
# (see https://github.com/golang/go/issues/39417)
# we replace symlinks with copies of the target.
# We use a `find -exec` with a separate file because POSIX sh
# is that much more limited than bash.
find "$PREFIX" -type l -exec "${BASEDIR}/copy-symlink-target.sh" {} \;
echo "Done!"

if [ -n "$CI" ]; then
echo "CI detected, cleaning up build artifacts"
rm -rf "$SRCDIR"
rm -rf "$BUILDDIR"
fi
13 changes: 13 additions & 0 deletions deps/patches/0001-remove-invalid-flow-control.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake
index 5bb0479..3d07b1c 100644
--- a/cmake/OpenCVCompilerOptions.cmake
+++ b/cmake/OpenCVCompilerOptions.cmake
@@ -18,8 +18,6 @@ if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
message(STATUS "Unable to compile program with enabled ccache, reverting...")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}")
endif()
- else()
- message(STATUS "Looking for ccache - not found")
endif()
endif()
endif()
7 changes: 7 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module example

go 1.23.2

require github.com/discord/lilliput v0.0.0-20241012171911-37dccacf7c50 // indirect

replace github.com/discord/lilliput => ..
2 changes: 2 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/discord/lilliput v0.0.0-20241012171911-37dccacf7c50 h1:5tSOh98txNCq1k4SwG4ZYCBjKjNg3fXHfdjOv8t4kBk=
github.com/discord/lilliput v0.0.0-20241012171911-37dccacf7c50/go.mod h1:0euuUBAD72MAYRm2ElLaG1h0nBR+CgpfnKc/U6y/uE8=
24 changes: 17 additions & 7 deletions webp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
resizeMethod: ImageOpsResize,
},
{
name: "Animated WebP - Supported",
name: "Animated WebP - Resize #1",
inputPath: "testdata/ferry_sunset.webp",
outputPath: "testdata/out/ferry_sunset_out_resize.webp",
width: 266,
Expand All @@ -244,7 +244,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
resizeMethod: ImageOpsResize,
},
{
name: "Animated WebP - Supported",
name: "Animated WebP - Resize #2",
inputPath: "testdata/animated-webp-supported.webp",
outputPath: "testdata/out/animated-webp-supported_out_resize.webp",
width: 400,
Expand All @@ -253,7 +253,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
resizeMethod: ImageOpsResize,
},
{
name: "Animated WebP - Supported",
name: "Animated WebP - Fit #1",
inputPath: "testdata/animated-webp-supported.webp",
outputPath: "testdata/out/animated-webp-supported_out_fit.webp",
width: 400,
Expand All @@ -262,7 +262,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
resizeMethod: ImageOpsFit,
},
{
name: "Animated WebP - Supported",
name: "Animated WebP - No resize",
inputPath: "testdata/animated-webp-supported.webp",
outputPath: "testdata/out/animated-webp-supported_out_no_resize.webp",
width: 0,
Expand All @@ -271,7 +271,7 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
resizeMethod: ImageOpsNoResize,
},
{
name: "Animated WebP - Supported",
name: "Animated WebP - Fit #2",
inputPath: "testdata/animated-webp-supported.webp",
outputPath: "testdata/out/animated-webp-supported_out.webp",
width: 200,
Expand Down Expand Up @@ -341,18 +341,20 @@ func testNewWebpEncoderWithAnimatedWebPSource(t *testing.T) {
DisableAnimatedOutput: tc.disableAnimatedOutput,
}

ops := NewImageOps(50000)
ops := NewImageOps(2000)
var newDst []byte
newDst, err = ops.Transform(decoder, options, dstBuf)
if err != nil {
decoder.Close()
ops.Close()
t.Errorf("Transform() error for %s: %v", tc.inputPath, err)
return
}

// verify length of newDst
if len(newDst) == 0 {
decoder.Close()
ops.Close()
t.Errorf("Transform() returned empty data for %s", tc.inputPath)
}

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

if err = os.WriteFile(tc.outputPath, newDst, 0644); err != nil {
decoder.Close()
ops.Close()
t.Errorf("Failed to write %s: %v", tc.outputPath, err)
}
}
decoder.Close()
ops.Close()
})
}
}
Expand Down Expand Up @@ -429,18 +434,20 @@ func testNewWebpEncoderWithAnimatedGIFSource(t *testing.T) {
EncodeTimeout: time.Second * 300,
}

ops := NewImageOps(50000)
ops := NewImageOps(2000)
var newDst []byte
newDst, err = ops.Transform(decoder, options, dstBuf)
if err != nil {
decoder.Close()
ops.Close()
t.Errorf("Transform() error for %s: %v", tc.inputPath, err)
return
}

// verify length of newDst
if len(newDst) == 0 {
decoder.Close()
ops.Close()
t.Errorf("Transform() returned empty data for %s", tc.inputPath)
}

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

if err = os.WriteFile(tc.outputPath, newDst, 0644); err != nil {
decoder.Close()
ops.Close()
t.Errorf("Failed to write %s: %v", tc.outputPath, err)
}
}
decoder.Close()
ops.Close()
})
}
}

0 comments on commit 9604962

Please sign in to comment.