Skip to content

Commit 3dba636

Browse files
authored
Maintenance 202604 (#25)
* add more edge case tests, increase consistency, add migrate notification, update packages * optimize argument naming, fix typo, performance update for queries * log access requests * combine decorate db calls, return authoritative DB state * update and fix tests, refactor decompose variant * add backend caching option * use only ocaml-setup dune cache * updates from lint-fmt and lint-opam * remove base and ppx_fields_conv dependency * explicit version * update dependency * update discussions * add lower bound
1 parent 462fb0f commit 3dba636

26 files changed

Lines changed: 1018 additions & 509 deletions

.github/workflows/ci.yml

Lines changed: 73 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ on:
99
jobs:
1010
build:
1111
name: Build and test
12-
1312
runs-on: ubuntu-latest
14-
1513
env:
1614
MYSQL_DATABASE: test
1715
MYSQL_ROOT_PASSWORD: password
18-
1916
services:
2017
database:
2118
image: mariadb:10.6
@@ -24,74 +21,102 @@ jobs:
2421
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
2522
ports: ['3306:3306']
2623
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
27-
2824
strategy:
2925
fail-fast: false
3026
matrix:
3127
ocaml-compiler:
32-
- 4.14
33-
- 5.2
34-
- 5.3
28+
- "4.14.3"
29+
- "5.2.1"
30+
- "5.3.0"
3531

3632
steps:
37-
- name: Checkout code
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') }}
33+
- name: Checkout repository
34+
uses: actions/checkout@v6
4735

48-
- name: Use OCaml ${{ matrix.ocaml-version }}
36+
- name: Use OCaml ${{ matrix.ocaml-compiler }}
4937
uses: ocaml/setup-ocaml@v3
5038
with:
5139
ocaml-compiler: ${{ matrix.ocaml-compiler }}
5240
dune-cache: true
53-
opam-pin: true
5441

5542
- name: Install system dependencies
5643
run: sudo apt-get update -y && sudo apt-get install -y libmariadb-dev
5744

5845
- name: Install dependencies
5946
run: opam install --deps-only --with-test --with-doc -y .
6047

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-
6748
- name: Build
68-
run: |
69-
make build
70-
71-
- name: Check formatting
72-
run: |
73-
opam install -y ocamlformat
74-
make format
49+
run: make build
7550

7651
- name: Run tests
7752
env:
7853
DATABASE_URL: mariadb://root:${{ env.MYSQL_ROOT_PASSWORD }}@127.0.0.1:3306/${{ env.MYSQL_DATABASE }}
7954
run: make test
8055

81-
- name: Build documentation
82-
run: |
83-
make doc
56+
- uses: actions/upload-artifact@v6
57+
if: failure()
58+
with:
59+
name: tests-${{ matrix.ocaml-compiler }}
60+
path: _build/default/test/_build/_tests/
61+
62+
- name: Notify about failure
63+
if: failure()
64+
uses: ./.github/actions/notify-failure
65+
with:
66+
webhook: ${{ secrets.ECON_TEAMS_WEBHOOK }}
8467

85-
- uses: actions/upload-artifact@v4
68+
lint-doc:
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Checkout tree
72+
uses: actions/checkout@v6
73+
- name: Install system dependencies
74+
run: sudo apt-get update -y && sudo apt-get install -y libmariadb-dev
75+
- name: Set-up OCaml
76+
uses: ocaml/setup-ocaml@v3
8677
with:
87-
name: documentation-${{ matrix.ocaml-compiler }}
78+
ocaml-compiler: 5.3.0
79+
opam-pin: true
80+
dune-cache: true
81+
- uses: ocaml/setup-ocaml/lint-doc@v3
82+
- uses: actions/upload-artifact@v6
83+
with:
84+
name: documentation
8885
path: _build/default/_doc/_html
8986

90-
- uses: actions/upload-artifact@v4
87+
- name: Notify about failure
9188
if: failure()
89+
uses: ./.github/actions/notify-failure
9290
with:
93-
name: tests-${{ matrix.ocaml-compiler }}
94-
path: _build/default/test/_build/_tests/
91+
webhook: ${{ secrets.ECON_TEAMS_WEBHOOK }}
92+
93+
lint-fmt:
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Checkout tree
97+
uses: actions/checkout@v6
98+
- name: Set-up OCaml
99+
uses: ocaml/setup-ocaml@v3
100+
with:
101+
ocaml-compiler: 5.3.0
102+
- uses: ocaml/setup-ocaml/lint-fmt@v3
103+
104+
- name: Notify about failure
105+
if: failure()
106+
uses: ./.github/actions/notify-failure
107+
with:
108+
webhook: ${{ secrets.ECON_TEAMS_WEBHOOK }}
109+
110+
lint-opam:
111+
runs-on: ubuntu-latest
112+
steps:
113+
- name: Checkout tree
114+
uses: actions/checkout@v6
115+
- name: Set-up OCaml
116+
uses: ocaml/setup-ocaml@v3
117+
with:
118+
ocaml-compiler: 5.3.0
119+
- uses: ocaml/setup-ocaml/lint-opam@v3
95120

96121
- name: Notify about failure
97122
if: failure()
@@ -102,17 +127,20 @@ jobs:
102127
deploy-doc:
103128
name: Deploy documentation
104129
runs-on: ubuntu-latest
105-
needs: [build]
130+
needs: [lint-doc]
106131
if: github.ref == 'refs/heads/main'
107132
environment:
108133
name: github-pages
109134
url: ${{ steps.deploy-doc.outputs.page_url }}
110135
steps:
111136
- name: Checkout code
112-
uses: actions/checkout@v4
137+
uses: actions/checkout@v6
113138

114-
- name: Download all workflow run artifacts
115-
uses: actions/download-artifact@v4
139+
- name: Download documentation artifact
140+
uses: actions/download-artifact@v8
141+
with:
142+
name: documentation
143+
path: documentation
116144

117145
- name: Deploy odoc to GitHub Pages
118146
uses: peaceiris/actions-gh-pages@v4
@@ -132,7 +160,7 @@ jobs:
132160
if: github.ref_type == 'tag'
133161
steps:
134162
- name: Checkout code
135-
uses: actions/checkout@v4
163+
uses: actions/checkout@v6
136164

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

.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version = 0.29.0
12
profile = janestreet
23
parse-docstrings = true
34
wrap-comments = true

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ all:
66

77
.PHONY: deps
88
deps: ## Install development dependencies
9-
opam install -y dune-release ocamlformat ocaml-lsp-server
10-
opam install --deps-only --with-test --with-doc -y .
9+
opam install --deps-only --with-test --with-doc --with-dev-setup -y .
1110

1211
.PHONY: lock
1312
lock: ## Generate a lock file

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Example usage:
7070

7171
## Development
7272

73-
A guide how to setup the project with devcontainers can be found [here](./.devcontainer/README.md).
73+
A guide how to setup the project with devcontainers can be found in [this README](./.devcontainer/README.md).
7474

7575
### Commands
7676

backend/database_pools.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ module Make (Config : ConfigSig) = struct
4848
; connection : connection [@opaque]
4949
; n_retries : int
5050
}
51-
[@@deriving fields]
51+
52+
let database_label { database_label; _ } = database_label
53+
let connection { connection; _ } = connection
5254

5355
let create ?(required = false) database_label database_url =
5456
{ database_label
@@ -149,8 +151,8 @@ module Make (Config : ConfigSig) = struct
149151
Cache.remove name |> Lwt.return
150152
;;
151153

152-
let initialize ?(additinal_pools : (string * string) list = []) () : unit =
153-
Config.database :: additinal_pools
154+
let initialize ?(additional_pools : (string * string) list = []) () : unit =
155+
Config.database :: additional_pools
154156
|> CCList.filter (fst %> Cache.find_opt %> CCOption.is_none)
155157
|> CCList.iter (CCFun.uncurry (Pool.create ~required:true) %> Cache.replace)
156158
;;
@@ -286,7 +288,8 @@ module Make (Config : ConfigSig) = struct
286288
Connection.rollback ()
287289
|> Lwt_result.map
288290
(CCFun.tap (fun _ ->
289-
Logs.debug (fun m -> m "Successfully rolled back transaction")))
291+
Logs.debug ~src (fun m ->
292+
m "Successfully rolled back transaction")))
290293
|> raise_caqti_error label
291294
in
292295
Lwt.fail error

backend/database_pools_sig.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module type Sig = sig
2-
val initialize : ?additinal_pools:(string * string) list -> unit -> unit
2+
val initialize : ?additional_pools:(string * string) list -> unit -> unit
33

44
val fetch_pool
55
: ?ctx:(string * string) list

backend/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(public_name guardian.backend)
33
(name Guardian_backend)
44
(libraries
5-
base
65
caqti
76
caqti-driver-mariadb
87
caqti-lwt
@@ -11,6 +10,7 @@
1110
containers-data
1211
guardian
1312
logs
13+
lru
1414
lwt
1515
uri)
1616
(preprocess
@@ -21,5 +21,4 @@
2121
ppx_deriving.make
2222
ppx_deriving.ord
2323
ppx_deriving.show
24-
ppx_fields_conv
2524
ppx_string)))

0 commit comments

Comments
 (0)