Skip to content

Commit b85e202

Browse files
authored
Merge pull request #56 from paurkedal/ci
Add GitHub Actions workflow for testing
2 parents fa56e50 + 3d5a199 commit b85e202

File tree

4 files changed

+106
-3
lines changed

4 files changed

+106
-3
lines changed

.github/workflows/workflow.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build, test, and lint
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
permissions: read-all
8+
9+
jobs:
10+
build-and-test:
11+
12+
services:
13+
mariadb:
14+
image: mariadb:latest
15+
env:
16+
MARIADB_USER: testuser
17+
MARIADB_PASSWORD: testpw
18+
MARIADB_DATABASE: testdb
19+
MARIADB_RANDOM_ROOT_PASSWORD: 1
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os:
25+
# The main aim is to target different kinds of MariaDB client
26+
# libraries; see the OPAM specification of conf-mariadb.
27+
- "alpine" # MariaDB C connector
28+
- "ubuntu" # libmariadb
29+
# "ubuntu-18.04" has libmariadbclient but has too old libc for node.js
30+
ocaml-compiler:
31+
- "5.3"
32+
- "4.14"
33+
- "4.07"
34+
35+
runs-on: ubuntu-latest
36+
container:
37+
image: "ocaml/opam:${{ matrix.os }}-ocaml-${{ matrix.ocaml-compiler }}"
38+
# Currently needed for the GitHub Actions, use sudo for other steps.
39+
options: "--user root"
40+
41+
steps:
42+
- name: Check out source code
43+
uses: actions/checkout@v4
44+
45+
- name: Install system dependencies (alpine)
46+
if: "${{ matrix.os == 'alpine' }}"
47+
run: "apk add --no-cache linux-headers mariadb-connector-c-dev"
48+
49+
- name: Install system dependencies (ubuntu)
50+
if: "${{ matrix.os == 'ubuntu' }}"
51+
run: "apt-get update && apt-get install -y pkg-config libmariadb-dev"
52+
53+
- name: Restore cached dependencies
54+
uses: actions/cache@v3
55+
with:
56+
# This gives the precise OCaml version via .opam/config, but only the
57+
# approximate OS version via the matrix. In particular we cannot use
58+
# /etc/*-release, since hashFiles only works within GITHUB_WORKSPACE.
59+
key: "${{ matrix.os }}-${{ hashFiles('*.opam', '.opam/config') }}"
60+
path: /home/opam/.opam
61+
62+
- name: Give the opam user access to the workspace
63+
run: "chown -Rh opam: ."
64+
65+
- name: Install dependencies
66+
run: "sudo -u opam opam install -y --deps-only -t ."
67+
if: "${{ matrix.os == 'ubuntu' && matrix.ocaml-compiler == '4.14' }}"
68+
69+
- name: Install minimal dependencies
70+
run: |
71+
sudo -u opam opam install -y --deps-only .
72+
sudo -u opam opam install -y lwt
73+
if: "${{ matrix.os != 'ubuntu' || matrix.ocaml-compiler != '4.14' }}"
74+
75+
- name: Build
76+
run: "sudo -u opam opam exec -- dune build @install @runtest"
77+
# Skipping @check, since it would force compilation of (optional)
78+
# targets.
79+
80+
- name: Run tests
81+
run: "sudo -u opam --preserve-env=OCAML_MARIADB_HOST,OCAML_MARIADB_PORT,OCAML_MARIADB_USER,OCAML_MARIADB_PASS,OCAML_MARIADB_DB,OCAML_MARIADB_QUERY opam exec -- dune runtest"
82+
env:
83+
OCAML_MARIADB_HOST: mariadb
84+
OCAML_MARIADB_PORT: 3306
85+
OCAML_MARIADB_USER: testuser
86+
OCAML_MARIADB_PASS: testpw
87+
OCAML_MARIADB_DB: testdb
88+
89+
# lint-opam:
90+
# runs-on: ubuntu-latest
91+
# steps:
92+
# - name: Check out source code
93+
# uses: actions/checkout@v4
94+
#
95+
# - name: Set up OCaml
96+
# uses: ocaml/setup-ocaml@v3
97+
# with:
98+
# ocaml-compiler: 5
99+
#
100+
# - name: Lint OPAM package descriptions
101+
# uses: ocaml/setup-ocaml/lint-opam@v3

examples/async/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
(executable
22
(name nonblocking_async_example)
3-
(libraries mariadb async))
3+
(libraries async mariadb threads)
4+
(optional))

examples/lwt/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
(executable
22
(name nonblocking_lwt_example)
3-
(libraries mariadb lwt lwt.unix))
3+
(libraries mariadb lwt lwt.unix)
4+
(optional))

tests/nonblocking-async/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
(env_var OCAML_MARIADB_USER)
99
(env_var OCAML_MARIADB_PASS)
1010
(env_var OCAML_MARIADB_DB))
11-
(libraries mariadb async nonblocking_testsuite))
11+
(libraries async mariadb nonblocking_testsuite threads))

0 commit comments

Comments
 (0)