Skip to content

Commit

Permalink
chore: Try to build on gh actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrKovalenko committed Aug 17, 2024
1 parent ba1bf66 commit 0e22fda
Show file tree
Hide file tree
Showing 19 changed files with 267 additions and 169 deletions.
109 changes: 49 additions & 60 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,62 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-latest]
os: [windows-latest]
steps:
- uses: actions/setup-node@v2
- uses: actions/[email protected]
- shell: bash
run: rm -rf $(which pkg-config)

- uses: actions/setup-node@v4
with:
node-version: "20"

- uses: lukka/get-cmake@latest
- name: Setup anew (or from cache) vcpkg (and does not build any package)
uses: lukka/run-vcpkg@v11
env:
VCPKG_DEFAULT_TRIPLET: x64-mingw-static
VCPKG_DEFAULT_HOST_TRIPLET: x64-mingw-static
with:
node-version: '18'
- uses: actions/[email protected]
runVcpkgInstall: true
runVcpkgFormatString: '["install", "--clean-after-build"]'

- name: Install esy
run: npm install -g esy
- run: vcpkg install

- name: Try to restore install cache
uses: actions/[email protected]
with:
path: ~/.esy/source
key: source-${{ hashFiles('**/index.json') }}
- name: Set pkg-config path on Unix
if: runner.os != 'Windows'
run: |
ls "${GITHUB_WORKSPACE}/vcpkg_installed/${VCPKG_DEFAULT_TRIPLET}/lib/pkgconfig"
echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}/vcpkg_installed/${VCPKG_DEFAULT_TRIPLET}/lib/pkgconfig" >> $GITHUB_ENV
- name: Install
run: esy install
- name: Set pkg-config path on Unix
if: runner.os == 'Windows'
run: |
echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}\vcpkg_installed\\${VCPKG_DEFAULT_TRIPLET}\lib\pkgconfig" >> $GITHUB_ENV
- name: Print esy cache
uses: actions/[email protected]
id: print_esy_cache
with:
script: |
const path = require('path')
const scriptPath = path.resolve('.github/workflows/print_esy_cache.js')
require(scriptPath)(core)
- name: Try to restore build cache
id: deps-cache
uses: actions/[email protected]
- shell: cmd
run: tree /f /a D:\a\odiff\odiff\vcpkg_installed\x64-mingw-static

- run: |
choco install pkgconfiglite
- run: |
echo "LIBPNG_CFLAGS=$(pkg-config --cflags libspng_static)" >> $GITHUB_ENV
echo "LIBPNG_LIBS=$(pkg-config --libs libspng_static)" >> $GITHUB_ENV
echo "LIBTIFF_LIBS=$(pkg-config --libs libtiff-4)" >> $GITHUB_ENV
echo "LIBTIFF_CFLAGS=$(pkg-config --cflags libtiff-4)" >> $GITHUB_ENV
echo "LIBJPEG_CFLAGS=$(pkg-config --cflags libturbojpeg)" >> $GITHUB_ENV
echo "LIBJPEG_LIBS=$(pkg-config --libs libturbojpeg)" >> $GITHUB_ENV
- uses: ocaml/setup-ocaml@v3
with:
path: ${{ steps.print_esy_cache.outputs.esy_cache }}
key: build-odiff-${{ matrix.os }}-${{ hashFiles('**/index.json') }}
restore-keys: build-odiff-${{ matrix.os }}

# Here we use a low-level command. In real situation you don't have to
# but it is useful in CI as it split the log in GitHub UI.
# You can see at a glance if it is your project or your deps that break.
#
# We also use --release flag to build less.
# This allow us to spot syntax/type error more quickly.
- name: Build release dependencies

if: steps.deps-cache.outputs.cache-hit != 'true'
run: esy build-dependencies --release

- name: Build project in release
run: esy build --release

# Now that our core project build let builds others deps
- name: Build dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: esy build-dependencies

- name: Build project
run: esy build

- name: Ensure readme is up-to-date
run: node scripts/process-readme.js verify

# Here we cleanup if we have a cache fail because we use restore-keys.
# restore-keys take the old store even on cache fail.
# So, we have deps we don't care anymore. We prune them.
- name: Clean global store
if: steps.deps-cache.outputs.cache-hit != 'true'
run: esy cleanup .
ocaml-compiler: 4.14.0
dune-cache: true

- name: Install deps & build
run: opam install . --with-test

- run: opam exec -- dune build --verbose

- name: Test
run: esy test
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ _release
*.install
images/diff.png
test/test-images/_*.png

vcpkg_installed/*
_opam/
28 changes: 16 additions & 12 deletions bin/ODiffBin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,26 @@ let ignoreRegions =
\"x1:y1-x2:y2\". Multiple regions are separated with a ','."

let cmd =
const Main.main $ base $ comp $ diffPath $ threshold $ diffMask $ failOnLayout
$ diffColor $ parsableOutput $ antialiasing $ ignoreRegions $ diffLines
$ disableGcOptimizations

let info =
let man =
[
`S Manpage.s_description;
`P "$(tname) is the fastest pixel-by-pixel image comparison tool.";
`P "Supported image types: .png, .jpg, .jpeg, .bitmap";
`P "Supported image types: .png, .jpg, .jpeg, .tiff";
]
in
( const Main.main $ base $ comp $ diffPath $ threshold $ diffMask
$ failOnLayout $ diffColor $ parsableOutput $ antialiasing $ ignoreRegions
$ diffLines $ disableGcOptimizations,
Term.info "odiff" ~version:"3.0.1" ~doc:"Find difference between 2 images."
~exits:
(Term.exit_info 0 ~doc:"on image match"
:: Term.exit_info 21 ~doc:"on layout diff when --fail-on-layout"
:: Term.exit_info 22 ~doc:"on image pixel difference"
:: Term.default_error_exits)
~man )
Cmd.info "odiff" ~version:"3.0.1" ~doc:"Find difference between 2 images."
~exits:
[
Cmd.Exit.info 0 ~doc:"on image match";
Cmd.Exit.info 21 ~doc:"on layout diff when --fail-on-layout";
Cmd.Exit.info 22 ~doc:"on image pixel difference";
]
~man

let () = Term.eval cmd |> Term.exit
let cmd = Cmd.v info cmd
let () = Cmd.eval cmd |> Stdlib.exit
100 changes: 50 additions & 50 deletions bin/Print.ml
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
open Odiff.Diff
(* open Odiff.Diff *)

let printDiffResult makeParsableOutput result =
(match (result, makeParsableOutput) with
| Layout, true -> ""
| Layout, false ->
Pastel.createElement
~children:
[
(Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ]
() [@JSX]);
" Images have different layout.\n";
]
() [@JSX]
| Pixel (_output, diffCount, _percentage, _lines), true when diffCount == 0 ->
""
| Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0
->
Pastel.createElement
~children:
[
(Pastel.createElement ~color:Green ~bold:true
~children:[ "Success!" ] () [@JSX]);
" Images are equal.\n";
(Pastel.createElement ~dim:true
~children:[ "No diff output created." ]
() [@JSX]);
]
() [@JSX]
| Pixel (_output, diffCount, diffPercentage, stack), true
when not (Stack.is_empty stack) ->
Int.to_string diffCount ^ ";"
^ Float.to_string diffPercentage
^ ";"
^ (stack
|> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "")
| Pixel (_output, diffCount, diffPercentage, _), true ->
Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage
| Pixel (_output, diffCount, diffPercentage, _lines), false ->
Pastel.createElement
~children:
[
(Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ]
() [@JSX]);
" Images are different.\n";
"Different pixels: ";
(Pastel.createElement ~color:Red ~bold:true
~children:[ Printf.sprintf "%i (%f%%)" diffCount diffPercentage ]
() [@JSX]);
]
() [@JSX])
|> Console.log;
(* (match (result, makeParsableOutput) with *)
(* | Layout, true -> "" *)
(* | Layout, false -> *)
(* Pastel.createElement *)
(* ~children: *)
(* [ *)
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *)
(* () [@JSX]); *)
(* " Images have different layout.\n"; *)
(* ] *)
(* () [@JSX] *)
(* | Pixel (_output, diffCount, _percentage, _lines), true when diffCount == 0 -> *)
(* "" *)
(* | Pixel (_output, diffCount, _percentage, _lines), false when diffCount == 0 *)
(* -> *)
(* Pastel.createElement *)
(* ~children: *)
(* [ *)
(* (Pastel.createElement ~color:Green ~bold:true *)
(* ~children:[ "Success!" ] () [@JSX]); *)
(* " Images are equal.\n"; *)
(* (Pastel.createElement ~dim:true *)
(* ~children:[ "No diff output created." ] *)
(* () [@JSX]); *)
(* ] *)
(* () [@JSX] *)
(* | Pixel (_output, diffCount, diffPercentage, stack), true *)
(* when not (Stack.is_empty stack) -> *)
(* Int.to_string diffCount ^ ";" *)
(* ^ Float.to_string diffPercentage *)
(* ^ ";" *)
(* ^ (stack *)
(* |> Stack.fold (fun acc line -> (line |> Int.to_string) ^ "," ^ acc) "") *)
(* | Pixel (_output, diffCount, diffPercentage, _), true -> *)
(* Int.to_string diffCount ^ ";" ^ Float.to_string diffPercentage *)
(* | Pixel (_output, diffCount, diffPercentage, _lines), false -> *)
(* Pastel.createElement *)
(* ~children: *)
(* [ *)
(* (Pastel.createElement ~color:Red ~bold:true ~children:[ "Failure!" ] *)
(* () [@JSX]); *)
(* " Images are different.\n"; *)
(* "Different pixels: "; *)
(* (Pastel.createElement ~color:Red ~bold:true *)
(* ~children:[ Printf.sprintf "%i (%f%%)" diffCount diffPercentage ] *)
(* () [@JSX]); *)
(* ] *)
(* () [@JSX]) *)
(* |> Console.log; *)
result
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
(package odiff)
(flags
(:standard -w -27))
(libraries console.lib pastel.lib odiff-core odiff-io cmdliner))
(libraries odiff-core odiff-io cmdliner))
11 changes: 6 additions & 5 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(lang dune 2.8)
(name odiff)

; Warning: The flag set for these foreign sources overrides the `:standard` set
; of flags. However the flags in this standard set are still added to the
Expand All @@ -18,9 +19,11 @@

(package
(name odiff)
(synopsis "CLI for comparing images pixel-by-pixel")
(depends
odiff-core
odiff-io
(cmdliner (= 1.3.0))
)
)

Expand All @@ -29,8 +32,7 @@
(synopsis "Pixel-by-pixel image difference algorithm")
(depends
dune
(reason (and (>= 3.6.0) (< 4.0.0)))
(ocaml (and (>= 4.10.0) (< 5.0.0)))
(ocaml (= 4.14.0))
)
)

Expand All @@ -39,9 +41,8 @@
(synopsis "Ready to use io for odiff-core")
(depends
dune
conf-libpng
odiff-core
(reason (and (>= 3.6.0) (< 4.0.0)))
(ocaml (and (>= 4.10.0) (< 4.11.0)))
(ocaml (= 4.14.0))
(dune-configurator (>= 2.8))
)
)
Binary file added images/out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0e22fda

Please sign in to comment.