|
| 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 |
0 commit comments