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

3.0.0-alpha: Windows: bash script fails with "syntax error: unexpected end of file" #815

Closed
cknitt opened this issue Jun 20, 2024 · 13 comments

Comments

@cknitt
Copy link

cknitt commented Jun 20, 2024

Another 3.0.0-alpha issue, I hope this one makes more sense than my previous one 🙈.

So once correctly configured, setup-ocaml itself works perfectly fine on Windows, and we can use the OCaml 5.2.0 compiler to build our project.

However, after the setup-ocaml step and our successful OCaml build step, we have the following step:

      - name: "Check if syntax subfolder has changed"
        id: syntax-diff
        shell: bash
        run: |
          if git diff --name-only --exit-code HEAD^ HEAD -- jscomp/syntax; then
            echo "syntax_status=unchanged" >> $GITHUB_ENV
          else
            echo "syntax_status=changed" >> $GITHUB_ENV
          fi

This step works fine when using setup-ocaml 2.x.x, but fails with 3.0.0-alpha with the following error message:

Run if git diff --name-only --exit-code HEAD^ HEAD -- jscomp/syntax; then
D:\a\_temp\d426cc8d-884f-4bdc-a18e-a[70](https://github.com/rescript-lang/rescript-compiler/actions/runs/9594206863/job/26456471252?pr=6819#step:18:71)af2c1cc23.sh:
line 6: syntax error: unexpected end of file
Error: Process completed with exit code 2.

So it seems that the setup-ocaml step changes something in the environment, causing this error.

See https://github.com/rescript-lang/rescript-compiler/actions/runs/9601379213/job/26481410755.

@cknitt cknitt changed the title 3.0.0-alpha: bash script fails with "syntax error: unexpected end of file" 3.0.0-alpha: Windows: bash script fails with "syntax error: unexpected end of file" Jun 21, 2024
@smorimoto
Copy link
Member

@smorimoto
Copy link
Member

This issue is probably unrelated to the action.

@smorimoto smorimoto closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2024
@cknitt
Copy link
Author

cknitt commented Jul 1, 2024

Remove this step: https://github.com/rescript-lang/rescript-compiler/actions/runs/9601379213/workflow#L183-L187

I should have mentioned that I have already tried this, but it didn't help. Also, this did work fine with the setup-ocaml 2.x.x.

This is definitely a new issue with 3.0.0-beta.
Here is a standalone repro:

https://github.com/cknitt/setup-ocaml-repro/blob/main/.github/workflows/ci.yml
https://github.com/cknitt/setup-ocaml-repro/actions/runs/9745608001/job/26893980512

So please reopen this issue @smorimoto

@smorimoto smorimoto reopened this Jul 1, 2024
@smorimoto smorimoto added the bug Something isn't working label Jul 1, 2024
@smorimoto
Copy link
Member

The Actions runner may be using the wrong bash:

image

@smorimoto
Copy link
Member

@smorimoto
Copy link
Member

smorimoto commented Jul 2, 2024

You can use >- instead:

- name: Check if syntax subfolder has changed
  id: syntax-diff
  shell: bash
  env:
    SHELLOPTS: igncr
  run: |
    if git diff --name-only --exit-code HEAD^ HEAD -- jscomp/syntax; then
      echo "syntax_status=unchanged" >>"$GITHUB_ENV"
    else
      echo "syntax_status=changed" >>"$GITHUB_ENV"
    fi

@smorimoto smorimoto closed this as not planned Won't fix, can't repro, duplicate, stale Jul 2, 2024
@smorimoto smorimoto removed the bug Something isn't working label Jul 2, 2024
@cknitt
Copy link
Author

cknitt commented Jul 2, 2024

@smorimoto Thanks, but the proposed workaround with >- does NOT solve the problem.

See

https://github.com/cknitt/setup-ocaml-repro/blob/main/.github/workflows/ci.yml
https://github.com/cknitt/setup-ocaml-repro/actions/runs/9761746852/job/26943486150

Why does the 3.0.0 extension need to modify the path in such a way that a different bash binary becomes the default when that obviously wasn't necessary in 2.x.x?

This particular bash issue may not be the only side effect of this new behavior.

@cknitt
Copy link
Author

cknitt commented Jul 2, 2024

Ah, overlooked the SHELLOPTS: igncr, sorry, will try that, too.

However, the question remains: Why this change?

@cknitt
Copy link
Author

cknitt commented Jul 2, 2024

Ok, I can confirm that SHELLOPTS: igncr is the correct workaround.

@smorimoto
Copy link
Member

A better way to set it on Windows only is:

- name: Set SHELLOPTS=igncr on Windows
  if: runner.os == 'Windows'
  run: echo "SHELLOPTS=igncr" >>"$GITHUB_ENV"

@smorimoto
Copy link
Member

The reason you need to do this from v3 is that, until v2, the opam you call was not the real opam:

await io.mkdirP(CYGWIN_ROOT_WRAPPERBIN);
const opamCmd = path.join(CYGWIN_ROOT_WRAPPERBIN, "opam.cmd");
const data = [
"@setlocal",
"@echo off",
"set PATH=%CYGWIN_ROOT_BIN%;%PATH%",
"ocaml-env exec -- opam.exe %*",
].join(os.EOL);
await fs.writeFile(opamCmd, data, { mode: 0o755 });

@cknitt
Copy link
Author

cknitt commented Jul 4, 2024

A better way to set it on Windows only is:

Thanks for the hint!

@ygrek
Copy link

ygrek commented Aug 20, 2024

does it make sense to have igncr as default on windows runners?

talex5 added a commit to talex5/capnp-rpc that referenced this issue Sep 26, 2024
Error was:

    line 1: $'\r': command not found

See: ocaml/setup-ocaml#815 (comment)
talex5 added a commit to talex5/capnp-rpc that referenced this issue Sep 26, 2024
Error was:

    line 1: $'\r': command not found

See: ocaml/setup-ocaml#815 (comment)
talex5 added a commit to talex5/capnp-rpc that referenced this issue Sep 27, 2024
Test with OCaml 5.

Updated setup-ocaml to v3.

Had to add `SHELLOPTS: igncr`, to fix:

    line 1: $'\r': command not found

See ocaml/setup-ocaml#815 (comment)

Removed opam-repository-mingw.git#sunset. It doesn't seem to be needed
now, and was causing ocamlfind to fail to install.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants