Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 regression over v2: opam exec now fails with "Exec format error" on shell scripts on Windows #866

Closed
JasonGross opened this issue Sep 20, 2024 · 9 comments
Labels
question Further information is requested upstream

Comments

@JasonGross
Copy link

opam exec -- ./test.sh
Fatal error: exception C:\hostedtoolcache\windows\opam\2.2.1\x86_64\opam.exe: "create_process" failed on ./test.sh: Exec format error

https://github.com/JasonGross/test/actions/runs/10953316111/job/30413386004

logs_28625164728.zip

Full yml file
name: Example Workflow

on: [push, pull_request]

jobs:
  build:

    runs-on: windows-latest
    name: build
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: recursive
    - uses: ocaml/setup-ocaml@v3
      with:
        ocaml-compiler: 4.13.1
    - run: opam exec -- chmod +x test.sh
    - run: opam exec -- cat test.sh
    - run: opam exec -- ./test.sh


  buildv2:

    runs-on: windows-latest
    name: buildv2
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    - uses: ocaml/setup-ocaml@v2
      with:
        ocaml-compiler: 4.13.1
    - run: opam exec -- chmod +x test.sh
    - run: opam exec -- cat test.sh
    - run: opam exec -- ./test.sh
@smorimoto
Copy link
Member

Is it related to this? #815

@smorimoto smorimoto added the question Further information is requested label Oct 4, 2024
@JasonGross
Copy link
Author

You are suggesting that it might be related to #815 (comment) in particular, where perhaps indirecting through ocaml-env exec -- opam.exe exec instead of jumping straight to opam exec might change something? Or that opam exec might sometimes recognize bash scripts depending on what shell its run from? (The problem is that opam is trying to run the bash script as a binary executable, but I don't know what's causing that issue.) Is there a way to disentangle opam version issues from setup-ocaml version issues by changing something at https://github.com/JasonGross/test/blob/d70236be3e6d76e9bcac5a65b68298784b33f44d/.github/workflows/main.yml ?

@smorimoto
Copy link
Member

What happens if you run this with the latest v3?

@JasonGross
Copy link
Author

@smorimoto
Copy link
Member

If I understand correctly, even when using Cygwin, you still need to invoke the shell explicitly. This is because opam is compiled as a native Windows binary (opam.exe) and utilises the Windows CreateProcess API to launch processes. This API does not recognise shell scripts as directly executable files, regardless of whether you’re operating within a Cygwin environment. So, to run your shell script, you must explicitly call an interpreter like bash.

@smorimoto
Copy link
Member

Can you execute it by doing the following?

opam exec -- bash ./test.sh

@JasonGross
Copy link
Author

@JasonGross
Copy link
Author

Can you execute it by doing the following?

opam exec -- bash ./test.sh

Yes, this variant works fine

@smorimoto smorimoto added the documentation Improvements or additions to documentation label Mar 7, 2025
@smorimoto
Copy link
Member

Nice. This is not strictly an issue with this action, as I believe it comes from opam now native rather than regression. I'm going to close this issue.

@smorimoto smorimoto closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2025
@smorimoto smorimoto added upstream and removed documentation Improvements or additions to documentation labels Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested upstream
Projects
None yet
Development

No branches or pull requests

2 participants