setup-ocaml icon indicating copy to clipboard operation
setup-ocaml copied to clipboard

Feature: Create a switch by default when no opam files are present

Open gridbugs opened this issue 1 year ago • 3 comments

I want to make a test that just installs dune and ocamlformat and runs dune fmt. I don't want to install all the dependencies of my project - just dune and ocamlformat.

Currently this doesn't work:

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
    - name: Set-up OCaml
      uses: ocaml/setup-ocaml@v2
      with:
        ocaml-compiler: 4.14.1
    - uses: actions/checkout@v3
    - run: opam install -y dune ocamlformat

The error is:

Run opam install -y dune ocamlformat
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
'opam install -y dune ocamlformat' failed.
Error: Process completed with exit code 50.

This is part of the log here: https://github.com/gridbugs/llama/actions/runs/5687888861/job/15416935603

I think I could work around this by checking out the project before setting up ocaml but that would waste time downloading dependencies that I don't need for this test.

gridbugs avatar Jul 28 '23 03:07 gridbugs

I think I could work around this by checking out the project before setting up ocaml but that would waste time downloading dependencies that I don't need for this test.

I believe the undesired behaviour can be avoided by disabling pinning:

    - name: Set-up OCaml
      uses: ocaml/setup-ocaml@v2
      with:
        ocaml-compiler: 4.14.1
        opam-pin: false

I use a dedicated workflow for formatting here: https://github.com/xapi-project/xen-api/blob/master/.github/workflows/format.yml

psafont avatar Jul 28 '23 13:07 psafont

The next major refactoring will improve the handling of such things, but I've been working on a lot of real world stuff lately and the ETA is still not clear... @psafont's suggestion is the best in the short term.

smorimoto avatar Jul 28 '23 15:07 smorimoto

I tried this but got the same error:

    - name: Set-up OCaml
      uses: ocaml/setup-ocaml@v2
      with:
        ocaml-compiler: 4.14.1
        opam-pin: false
        opam-depext: false

Why would disabling pinning also cause it to create a switch?

gridbugs avatar Jul 29 '23 00:07 gridbugs