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

Check if switch exists before creating #40

Merged
merged 5 commits into from
Sep 10, 2020
Merged

Conversation

tmattio
Copy link
Contributor

@tmattio tmattio commented Sep 9, 2020

Hi!

I noticed that @smorimoto worked on caching on a separate repo and tried to integrate https://github.com/avsm/hello-world-action-ocaml/blob/with-cache/.github/workflows/workflow.yml in Opium (rgrinberg/opium#183)

Unfortunately, it seems that caching the ~/.opam directory does not work with multiple compilers at the moment because ocaml-setup uses opam switch create even if a switch with the same name already exists.

This PR adds a check that will only create a switch if it does not already exist. The check is really basic, maybe there's a better way to do this with opam?

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes need to be made in both the Windows and Unix install scripts (even if the former is not at present using caching).

Just for general reference, the venerable OCaml Travis CI Scripts are a good source of opam fu. The test you're proposing is very verbose to harden to deal with substrings and spaces - the better pattern is opam switch set "$1" || opam switch create "$1" "$1" (cf. https://github.com/ocaml/ocaml-ci-scripts/blob/master/.travis-ocaml.sh#L307)

src/install-ocaml-unix.sh Outdated Show resolved Hide resolved
@tmattio
Copy link
Contributor Author

tmattio commented Sep 9, 2020

the better pattern is opam switch set "$1" || opam switch create "$1" "$1"

Very nice trick! I read Opam's manual in search of such a solution, but didn't figure this one out!

I looked at the Windows installation script and it does not seem to use opam switch create, so I don't think the issue would happen on Windows, even if it could be cached.

@smorimoto
Copy link
Member

Yes, I did, but I don't recommend that users use it. Because at this time, there are very few ways for users to strictly cache using actions/cache.

@tmattio
Copy link
Contributor Author

tmattio commented Sep 9, 2020

@smorimoto Interesting! What kind of issue could happen with this setup?

@smorimoto
Copy link
Member

Well, this change is not bad for hackers. (So I'm not trying to argue against this PR.)

@dra27
Copy link
Member

dra27 commented Sep 9, 2020

I looked at the Windows installation script and it does not seem to use opam switch create, so I don't think the issue would happen on Windows, even if it could be cached.

Oh, good point - it always init's!

Signed-off-by: Sora Morimoto <sora@morimoto.io>
Signed-off-by: Sora Morimoto <sora@morimoto.io>
@smorimoto
Copy link
Member

A possible issue at this point is that actions/cache can sometimes corrupt the cache. We now have an idea to solve it and are already working on it, but if you remove the step runs opam upgrade --fixup from pushed setup right now, the build may fail. I haven't heard of it happening outside of the Rust project yet, but anyway the setup I pushed must be pretty fragile.

@smorimoto
Copy link
Member

It's also fragile without opam lock.

@smorimoto smorimoto requested a review from dra27 September 9, 2020 20:36
@smorimoto
Copy link
Member

This looks good to me. If @dra27 doesn't request additional changes to this, I will merge this and release the new patch version.

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@smorimoto smorimoto merged commit 1fcce69 into ocaml:master Sep 10, 2020
@smorimoto
Copy link
Member

I'm out now, so I'll release a new version when I get home.

@smorimoto
Copy link
Member

Thanks @tmattio!

@tmattio
Copy link
Contributor Author

tmattio commented Sep 10, 2020

Great, thanks for your work on caching 😉

@smorimoto
Copy link
Member

Well, that was important to our company, so anytime!

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

Successfully merging this pull request may close these issues.

3 participants