Skip to content

Commit bedb4ab

Browse files
authored
Feature/maintenance 2502 (#21)
* update packages for ocaml * run formatter * update github CI * fix artifact name
1 parent bde0041 commit bedb4ab

12 files changed

+252
-228
lines changed

.devcontainer/Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:lts AS node
22
FROM hadolint/hadolint:latest-alpine AS hadolint
3-
FROM ocaml/opam:debian-12-ocaml-4.14
3+
FROM ocaml/opam:debian-12-ocaml-5.3
44

55
USER root
66

@@ -45,6 +45,9 @@ RUN ln -fs /usr/share/zoneinfo/Europe/Zurich /etc/localtime
4545
RUN bash -c 'echo "http 80/tcp www # WorldWideWeb HTTP" >> /etc/services' \
4646
&& bash -c 'echo "https 443/tcp www # WorldWideWeb HTTPS" >> /etc/services'
4747

48+
# link opam version
49+
RUN ln -fs /usr/bin/opam-2.3 /usr/bin/opam
50+
4851
USER opam
4952

5053
# install oh-my-zsh

.devcontainer/postCreate.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ opam init -a --shell=zsh
99
opam remote remove --all default
1010
opam repository add default --all-switches --set-default https://opam.ocaml.org
1111

12-
opam pin add -yn guardian .
13-
opam depext --with-test --with-doc -y guardian
12+
opam install --with-test --with-doc --deps-only -y .
1413

1514
make deps

.github/workflows/ci.yml

+29-18
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,42 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
ocaml-compiler: [4.14.x]
31+
ocaml-compiler:
32+
- 4.14
33+
- 5.2
34+
- 5.3
3235

3336
steps:
3437
- name: Checkout code
35-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
39+
40+
- name: Retrieve opam cache
41+
uses: actions/cache@v4
42+
if: runner.os != 'Windows'
43+
id: cache-opam
44+
with:
45+
path: ~/.opam
46+
key: v1-${{ runner.os }}-opam-${{ matrix.ocaml-compiler }}-${{ hashFiles('*.opam.locked') }}
3647

3748
- name: Use OCaml ${{ matrix.ocaml-version }}
38-
uses: ocaml/setup-ocaml@v2
49+
uses: ocaml/setup-ocaml@v3
3950
with:
4051
ocaml-compiler: ${{ matrix.ocaml-compiler }}
4152
dune-cache: true
4253
opam-pin: true
43-
opam-depext: false
4454

4555
- name: Install system dependencies
4656
run: sudo apt-get update -y && sudo apt-get install -y libmariadb-dev
4757

48-
- name: Pin current guardian
49-
run: |
50-
opam pin add -yn guardian .
51-
OPAMSOLVERTIMEOUT=180 opam depext --with-test --with-doc -y guardian
52-
5358
- name: Install dependencies
5459
run: opam install --deps-only --with-test --with-doc -y .
5560

61+
- name: Recover from an Opam broken state
62+
if: steps.cache-opam.outputs.cache-hit == 'true'
63+
run: |
64+
opam install -y dune
65+
opam upgrade --fixup
66+
5667
- name: Build
5768
run: |
5869
make build
@@ -71,15 +82,15 @@ jobs:
7182
run: |
7283
make doc
7384
74-
- uses: actions/upload-artifact@v3
85+
- uses: actions/upload-artifact@v4
7586
with:
76-
name: documentation
87+
name: documentation-${{ matrix.ocaml-compiler }}
7788
path: _build/default/_doc/_html
7889

79-
- uses: actions/upload-artifact@v3
90+
- uses: actions/upload-artifact@v4
8091
if: failure()
8192
with:
82-
name: tests
93+
name: tests-${{ matrix.ocaml-compiler }}
8394
path: _build/default/test/_build/_tests/
8495

8596
- name: Notify about failure
@@ -98,13 +109,13 @@ jobs:
98109
url: ${{ steps.deploy-doc.outputs.page_url }}
99110
steps:
100111
- name: Checkout code
101-
uses: actions/checkout@v3
112+
uses: actions/checkout@v4
102113

103114
- name: Download all workflow run artifacts
104-
uses: actions/download-artifact@v3
115+
uses: actions/download-artifact@v4
105116

106117
- name: Deploy odoc to GitHub Pages
107-
uses: peaceiris/actions-gh-pages@v3
118+
uses: peaceiris/actions-gh-pages@v4
108119
with:
109120
github_token: ${{ github.token }}
110121
publish_dir: documentation
@@ -121,13 +132,13 @@ jobs:
121132
if: github.ref_type == 'tag'
122133
steps:
123134
- name: Checkout code
124-
uses: actions/checkout@v3
135+
uses: actions/checkout@v4
125136

126137
- name: Extract version changelog
127138
run: sed -nr "/^## .?v?${GITHUB_REF_NAME}/,/^## /p" CHANGELOG.md | sed '1d;2d;$d' > changes.md
128139

129140
- name: Create release
130-
uses: softprops/action-gh-release@v1
141+
uses: softprops/action-gh-release@v2
131142
with:
132143
token: ${{ secrets.GITHUB_TOKEN }}
133144
body_path: changes.md

backend/database_pools.ml

+29-28
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ module Make (Config : ConfigSig) = struct
7070
;;
7171

7272
let connect
73-
?(retries = 2)
74-
({ database_label; database_url; required; _ } as pool)
73+
?(retries = 2)
74+
({ database_label; database_url; required; _ } as pool)
7575
=
7676
let tags = database_label |> LogTag.create in
7777
CCResult.retry retries (fun () -> database_url |> connect_pool)
7878
|> (function
79-
| Error [] -> raise (Exception "Failed to connect: empty error")
80-
| Error (err :: _) when required -> raise (Caqti_error.Exn err)
81-
| Error (err :: _ as errors) ->
82-
Logs.warn ~src (fun m ->
83-
m
84-
~tags
85-
"Failed to connect: %s (%s)"
86-
database_label
87-
([%show: Caqti_error.t list] errors));
88-
Fail err
89-
| Ok con -> Open con)
79+
| Error [] -> raise (Exception "Failed to connect: empty error")
80+
| Error (err :: _) when required -> raise (Caqti_error.Exn err)
81+
| Error (err :: _ as errors) ->
82+
Logs.warn ~src (fun m ->
83+
m
84+
~tags
85+
"Failed to connect: %s (%s)"
86+
database_label
87+
([%show: Caqti_error.t list] errors));
88+
Fail err
89+
| Ok con -> Open con)
9090
|> fun connection -> { pool with connection }
9191
;;
9292
end
@@ -293,13 +293,14 @@ module Make (Config : ConfigSig) = struct
293293
;;
294294

295295
let transaction
296-
?ctx
297-
?(setup : (Caqti_lwt.connection -> (unit, Caqti_error.t) Lwt_result.t) list =
298-
[])
299-
?(cleanup :
300-
(Caqti_lwt.connection -> (unit, Caqti_error.t) Lwt_result.t) list =
301-
[])
302-
(f : Caqti_lwt.connection -> ('a, Caqti_error.t) Lwt_result.t)
296+
?ctx
297+
?(setup :
298+
(Caqti_lwt.connection -> (unit, Caqti_error.t) Lwt_result.t) list =
299+
[])
300+
?(cleanup :
301+
(Caqti_lwt.connection -> (unit, Caqti_error.t) Lwt_result.t) list =
302+
[])
303+
(f : Caqti_lwt.connection -> ('a, Caqti_error.t) Lwt_result.t)
303304
: 'a Lwt.t
304305
=
305306
let open Lwt_result.Syntax in
@@ -308,12 +309,12 @@ module Make (Config : ConfigSig) = struct
308309
let* () = Connection.start () in
309310
Lwt.catch
310311
(fun () ->
311-
let* () = exec_each connection setup in
312-
let* result = f connection in
313-
let* () = exec_each connection cleanup in
314-
match%lwt Connection.commit () with
315-
| Ok () -> Lwt.return_ok result
316-
| Error error -> Lwt.return_error error)
312+
let* () = exec_each connection setup in
313+
let* result = f connection in
314+
let* () = exec_each connection cleanup in
315+
match%lwt Connection.commit () with
316+
| Ok () -> Lwt.return_ok result
317+
| Error error -> Lwt.return_error error)
317318
(rollback ?ctx connection))
318319
|> map_fetched ?ctx
319320
;;
@@ -325,8 +326,8 @@ module Make (Config : ConfigSig) = struct
325326
let* () = Connection.start () in
326327
Lwt.catch
327328
(fun () ->
328-
let* () = exec_each connection queries in
329-
Connection.commit ())
329+
let* () = exec_each connection queries in
330+
Connection.commit ())
330331
(rollback ?ctx connection))
331332
|> map_fetched ?ctx
332333
;;

backend/mariadb_backend.ml

+31-31
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ struct
308308
end
309309

310310
let combine_sql
311-
from_sql
312-
std_filter_sql
313-
?(joins = "")
314-
?where_additions
315-
select
311+
from_sql
312+
std_filter_sql
313+
?(joins = "")
314+
?where_additions
315+
select
316316
=
317317
Format.asprintf
318318
"SELECT\n %s\nFROM %s\n %s\nWHERE\n %s\n %s"
@@ -409,10 +409,10 @@ struct
409409
let find_by_target ?ctx = Database.collect ?ctx find_by_target_request
410410

411411
let create_exclude
412-
?(field = "roles.actor_uuid")
413-
?(dynparam = Guardian.Utils.Dynparam.empty)
414-
?(with_uuid = false)
415-
exclude
412+
?(field = "roles.actor_uuid")
413+
?(dynparam = Guardian.Utils.Dynparam.empty)
414+
?(with_uuid = false)
415+
exclude
416416
=
417417
let open Guardian.Utils.Dynparam in
418418
if CCList.is_empty exclude
@@ -421,22 +421,22 @@ struct
421421
let arguments, params =
422422
CCList.fold_left
423423
(fun (args, dyn) (role, target_uuid) ->
424-
match target_uuid with
425-
| None when with_uuid ->
426-
( "(exclude.role = ? AND exclude.target_uuid IS NULL)"
427-
:: args
428-
, dyn |> add Model.role role )
429-
| None ->
430-
( "exclude.role = ? AND exclude.target_uuid IS NULL"
431-
:: args
432-
, dyn |> add Model.role role )
433-
| Some uuid ->
434-
( [%string
435-
{sql|(exclude.role = ? AND exclude.target_uuid = %{Entity.Uuid.sql_value_fragment "?"})|sql}]
436-
:: args
437-
, dyn
438-
|> add Model.role role
439-
|> add Entity.Uuid.Target.t uuid ))
424+
match target_uuid with
425+
| None when with_uuid ->
426+
( "(exclude.role = ? AND exclude.target_uuid IS NULL)"
427+
:: args
428+
, dyn |> add Model.role role )
429+
| None ->
430+
( "exclude.role = ? AND exclude.target_uuid IS NULL"
431+
:: args
432+
, dyn |> add Model.role role )
433+
| Some uuid ->
434+
( [%string
435+
{sql|(exclude.role = ? AND exclude.target_uuid = %{Entity.Uuid.sql_value_fragment "?"})|sql}]
436+
:: args
437+
, dyn
438+
|> add Model.role role
439+
|> add Entity.Uuid.Target.t uuid ))
440440
([], dynparam)
441441
exclude
442442
in
@@ -1183,12 +1183,12 @@ struct
11831183
;;
11841184

11851185
let validate
1186-
?ctx
1187-
?(any_id = false)
1188-
?target_uuid
1189-
?model
1190-
permission
1191-
{ Guard.Actor.uuid; _ }
1186+
?ctx
1187+
?(any_id = false)
1188+
?target_uuid
1189+
?model
1190+
permission
1191+
{ Guard.Actor.uuid; _ }
11921192
=
11931193
let open Lwt.Infix in
11941194
(match any_id, target_uuid, model with

backend/mariadb_utils.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
let find_request_sql
2-
sql_select_columns
3-
table_name
4-
?(default_where = None)
5-
?(count = false)
6-
?(joins = "")
7-
where_fragment
2+
sql_select_columns
3+
table_name
4+
?(default_where = None)
5+
?(count = false)
6+
?(joins = "")
7+
where_fragment
88
=
99
let where_fragment =
1010
CCOption.map_or ~default:where_fragment (fun default_where ->

guardian.opam

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ depends: [
2121
"logs" {>= "0.7.0"}
2222
"lwt" {>= "5.6.1"}
2323
"lwt_ppx" {>= "2.1.0"}
24-
"mariadb" {>= "1.1.6"}
24+
"mariadb" {>= "1.2.0"}
2525
"ocaml" {>= "4.12.0"}
2626
"ppx_deriving" {>= "5.2.1"}
2727
"ppx_deriving_yojson" {>= "3.6.1"}

0 commit comments

Comments
 (0)