Is there a programatic way to bump the Elixir version of a Mix project?

Hi! :wave:

I’m fairly new to Elixir, so excuse me if this is a rather basic question.

Is there a programmatic way of upgrading the Elixir version of a mix project? If not, what is the expected way to do so?

For example, in Golang you can run go mod edit -go=1.14 thus effectively setting the Go version of the project to 1.14.

Do you mean upgrading the minimum supported version specified inside the mix.exs file?

I think the best way to achieve what you want is with asdf (link).
Then you can install whatever version is available and meets your requirements:

ERLANG_VERSION=27.1
ELIXIR_VERSION=1.17.3-otp-27

asdf install erlang $ERLANG_VERSION
asdf install elixir $ELIXIR_VERSION

asdf global erlang $ERLANG_VERSION
asdf global elixir $ELIXIR_VERSION
1 Like

Nope, mise all the way. asdf is old news, and is slower.

2 Likes

This can be accomplished by using for example ‘sed’. I wonder what the use case is though……

1 Like

Maybe GitHub - ash-project/igniter: A code generation and project patching framework. could work.

I’d be happy to see these kinds of tools added to igniter :ok_hand:PRs/issues welcome!

1 Like

I wonder about the use case as well. I’d use a proper grammar-aware CLI code searcher and editor like ast-grep though.

Igniter is AST based project patching :slight_smile:

1 Like

Hey, everyone! Thanks a lot for so many responses :smile:

@arcyfelix I really appreciate the answer. I’ve explained myself quite poorly, because what I meant was what @dimitarvp is talking about: upgrading the minimum supported version inside the mix.exs file :raised_hands: Although I learned about mise, so… noice

@dimitarvp the use case, long story short, would be to have a script that can run in a pipeline so that I can periodically upgrade the version in a pipeline (think GitHub, and if after the change the tests pass the PR gets merged without human intervention.

It seems like the way to go is to externally (be it manually, be it via grep-like tools) edit it. Thanks for the clarification!

I will add this mix task to igniter next week :slight_smile: I’ll post here when I do if you want to try it out.

1 Like

Keep in mind that a higher minimum version is not what you should be aiming for. This actually lowers your potential usability. In this case lower is better, and you should only bump that version if you need a language feature from a newer Elixir version.

3 Likes

I am sure I’ll absolutely go through Igniter if I ever get the time and energy for my idea of project generators that can also modify existing code. But the long startup time of the BEAM is always a turn-off for me when it comes to CLI tools. :confused:

Yeah, it’s definitely a drawback, but it’s worth it for the tight language integration. We have project generators(installers) that modify the source code instead of requiring a fresh start.

We’re using them for ash, and beacon will soon have one as well. Working on pushing this into the rest of the ecosystem as we speak :tada:

1 Like

i.e mix igniter.install ash

Actually, this is a good point. We only store the minimum version in mix.exs and bumping that is a net bad. Perhaps I can add things like .tool-versions modifiers.

Oh? Which ones?

the installers for ash, ash_postgres, ash_sqlite, ash_mysql, ash_graphql and ash_json_api are all installers built with igniter. mix igniter.install package_name can be used to install any package, and if an installer exists it will be run. you can add igniter to an elixir project and try it out today :slight_smile:

https://hexdocs.pm/igniter/readme.html

here is the implementation of the ash installer: ash/lib/mix/tasks/install/ash.install.ex at main · ash-project/ash · GitHub

If you want to get started writing your own installer or generator, add igniter to your project and use mix igniter.gen.task your.task.name

1 Like

the idea is that instead of having project generators, we have composable installers for packages so you can get exactly what you want and nothing else. instead of starter kits, the elements of our ecosystem should all be installable into any app :slight_smile:

with that in mind, here is a starter kit for a LV app with api support and postgres set up.

mix igniter.new my_app \
  --with phx.new \ # they don't have installers, so we have to use it as a base
  --install ash,ash_graphql,ash_postgres

the beauty of this approach is that if you later want json api instead of graphql, it’s as easy as mix igniter.install ash_json_api

Igniter is usable for any project, Ash just happens to be its first major adopter, seeing that i made both :joy:

3 Likes

Oh! :thinking: What’s the right way to make sure your Applications continue to use a current version of Elixir, then? If I recall correctly, versions prior to 1.4 do not get security updates anymore.