ocurrent / ocaml-ci

A CI for OCaml projects
https://ocaml.ci.dev
111 stars 75 forks source link

`lint-fmt` job fails with "Error: Program ocamlformat not found in the tree or in PATH" #936

Closed hannesm closed 3 months ago

hannesm commented 3 months ago

Context

Take a look at the run in https://ocaml.ci.dev/github/robur-coop/caldav/commit/d0d7294ad7f725629877be711249517541260ae8/variant/%28lint-fmt%29 (full output below)

The repository where this is running on is https://github.com/robur-coop/caldav

2024-05-09 17:22.22: New job: test robur-coop/caldav https://github.com/robur-coop/caldav.git#refs/heads/cleanups (d0d7294ad7f725629877be711249517541260ae8) (linux-x86_64:(lint-fmt))
Base: ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480
ocamlformat version: none

To reproduce locally:

git clone --recursive "https://github.com/robur-coop/caldav.git" -b "cleanups" && cd "caldav" && git reset --hard d0d7294a
cat > Dockerfile <<'END-OF-DOCKERFILE'
FROM ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480
USER 1000:1000
RUN cd ~/opam-repository && (git cat-file -e 2a9f6cbdb45bfe024cf3c365630433e406683f7b || git fetch origin master) && git reset -q --hard 2a9f6cbdb45bfe024cf3c365630433e406683f7b && git log --no-decorate -n1 --oneline && opam update -u
RUN opam depext -i dune
WORKDIR /src
COPY --chown=1000:1000 . /src/
RUN opam exec -- dune build @fmt --ignore-promoted-rules || (echo "dune build @fmt failed"; exit 2)

END-OF-DOCKERFILE
docker build .
END-REPRO-BLOCK

2024-05-09 17:22.22: Using cache hint "robur-coop/caldav-ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480-debian-12-4.08_opam-2.1-ocamlformat-2a9f6cbdb45bfe024cf3c365630433e406683f7b"
2024-05-09 17:22.22: Using OBuilder spec:
((from ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480)
 (user (uid 1000) (gid 1000))
 (run (cache (opam-archives (target /home/opam/.opam/download-cache)))
      (network host)
      (shell "cd ~/opam-repository && (git cat-file -e 2a9f6cbdb45bfe024cf3c365630433e406683f7b || git fetch origin master) && git reset -q --hard 2a9f6cbdb45bfe024cf3c365630433e406683f7b && git log --no-decorate -n1 --oneline && opam update -u"))
 (run (cache (opam-archives (target /home/opam/.opam/download-cache)))
      (network host)
      (shell "opam depext -i dune"))
 (workdir /src)
 (copy (src .) (dst /src/))
 (run (shell "opam exec -- dune build @fmt --ignore-promoted-rules || (echo \"dune build @fmt failed\"; exit 2)"))
)

2024-05-09 17:22.22: Waiting for resource in pool OCluster
2024-05-09 17:22.22: Waiting for worker…
2024-05-09 17:28.49: Got resource from pool OCluster
Building on x86-bm-c7.sw.ocaml.org
All commits already cached
HEAD is now at d0d7294 cirrus: minor

(from ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480)
Unable to find image 'ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480' locally
docker.io/ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480: Pulling from ocaml/opam
1a743107bfdb: Pulling fs layer
1a743107bfdb: Verifying Checksum
1a743107bfdb: Download complete
1a743107bfdb: Pull complete
Digest: sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480
Status: Downloaded newer image for ocaml/opam@sha256:e30e92a245a5f284471a3437bd6b19ebfb9ae067e380416fd178b1f6c2290480
2024-05-09 17:28.49 ---> using "ca7a47bb337547622343e1e691b0c92596d0990b9ed28342fd47c7204c2b0a74" from cache

/: (user (uid 1000) (gid 1000))

/: (run (cache (opam-archives (target /home/opam/.opam/download-cache)))
        (network host)
        (shell "cd ~/opam-repository && (git cat-file -e 2a9f6cbdb45bfe024cf3c365630433e406683f7b || git fetch origin master) && git reset -q --hard 2a9f6cbdb45bfe024cf3c365630433e406683f7b && git log --no-decorate -n1 --oneline && opam update -u"))
From https://github.com/ocaml/opam-repository
 * branch                  master     -> FETCH_HEAD
   4bb8cb8b65..eb2dcab0d8  master     -> origin/master
2a9f6cbdb4 Merge pull request #25816 from hannesm/release-mirage-vnetif-v0.6.1

<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
[default] synchronised from file:///home/opam/opam-repository
default (at file:///home/opam/opam-repository): 
    [INFO] opam 2.1 includes many performance improvements over 2.0; please consider upgrading (https://opam.ocaml.org/doc/Install.html)

Everything as up-to-date as possible (run with --verbose to show unavailable upgrades).
However, you may "opam upgrade" these packages explicitly, which will ask permission to downgrade or uninstall the conflicting packages.
Nothing to do.
# Run eval $(opam env) to update the current shell environment
2024-05-09 17:28.49 ---> using "8a3be403303d61c9a0768759ffb96a51cc969c8895fc3d8bf85d1b0bb1a849d8" from cache

/: (run (cache (opam-archives (target /home/opam/.opam/download-cache)))
        (network host)
        (shell "opam depext -i dune"))
# Detecting depexts using vars: arch=x86_64, os=linux, os-distribution=debian, os-family=debian
# No extra OS packages requirements found.
# All required OS packages found.
# Now letting opam install the packages
The following actions will be performed:
  - install dune 3.15.2

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[dune.3.15.2] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed dune.3.15.2
Done.
# Run eval $(opam env) to update the current shell environment
2024-05-09 17:28.49 ---> using "981ce8f1dd422b89880ef208cd5cad5049e4e0ddb3988ff514999b51c99ec290" from cache

/: (workdir /src)

/src: (copy (src .) (dst /src/))
2024-05-09 17:28.49 ---> saved as "0f0e750067193855b78e4f9f19a155c48169ed6967014c2ba3bb4778b511bb37"

/src: (run (shell "opam exec -- dune build @fmt --ignore-promoted-rules || (echo \"dune build @fmt failed\"; exit 2)"))
Error: Program ocamlformat not found in the tree or in PATH
 (context: default)
-> required by _build/default/mirage/.formatted/config.ml
-> required by alias mirage/.formatted/fmt
-> required by alias mirage/fmt
dune build @fmt failed
"/usr/bin/env" "bash" "-c" "opam exec -- dune build @fmt --ignore-promoted-rules || (echo "dune build @fmt failed"; exit 2)" failed with exit status 2

Expected behaviour

It should succeed.

Technical details

There's no .ocamlformat file in the repository, there's as well no "(formatting disabled)" in dune-project.

shonfeder commented 3 months ago

Thanks for the report! The fix in #937 proposes making the lint-fmt job a no-op when the repo isn't configured for ocamlformat. The other option is to always install ocamlformat in that job and still run dune build @fmt. If you have an opinion one way or the other, I'd be happy to hear it.

hannesm commented 3 months ago

Thanks for your reply, @shonfeder. I don't quite know. What is the lint-fmt check supposed to do, in general? Is it only a ocamlformat check? I also don't quite understand what dune build @fmt is supposed to do, since there's quite a bit of configuration, namely: is .ocamlformat present? does dune-project contain a (formatting disabled) line (and than, this as well depends on the dune lang version). I'm also not sure whether this changed in recent times.

shonfeder commented 3 months ago

What is the lint-fmt check supposed to do, in general? Is it only a ocamlformat check? I also don't quite understand what dune build @fmt is supposed to do, since there's quite a bit of configuration, namely: is .ocamlformat present? does dune-project contain a (formatting disabled) line (and than, this as well depends on the dune lang version). I'm also not sure whether this changed in recent times.

Generally, afaiu, dune build @fmt causes all actions associated with the fmt alias to be built, and these may include custom rules. However, there are a default set of actions associated. As per https://dune.readthedocs.io/en/stable/howto/formatting.html#setting-up-the-environment, three kinds of formatting and configurable by default:

So one may want to run dune build @fmt to format dune files, without having to install ocamlformat, and imo it seems clearly to be an error that this is not currently supported (when .ml files are present). While that is waiting on a fix, however, one of the two alternatives I've proposed should keep the CI job from failing :)