Current section
Files
Jump to
Current section
Files
lib/mix/tasks/nebula_graph_ex.version.ex
defmodule Mix.Tasks.NebulaGraphEx.Version do
@shortdoc "Bumps the version in mix.exs"
@moduledoc """
Bumps the package version in `mix.exs`.
Usage:
mix nebula_graph_ex.version patch
mix nebula_graph_ex.version minor
mix nebula_graph_ex.version major
If no bump type is provided, the task prompts interactively.
"""
use Mix.Task
alias NebulaGraphEx.Release
@mix_file "mix.exs"
@doc_files ["README.md", "lib/nebula_graph_ex.ex"]
@impl Mix.Task
def run(args) do
Mix.Task.run("app.start")
bump_type =
case args do
[value | _] ->
case Release.normalize_bump_type(value) do
nil ->
Mix.raise("Invalid bump type #{inspect(value)}. Use major, minor, or patch.")
normalized ->
normalized
end
[] ->
prompt_bump_type()
end
content = File.read!(@mix_file)
current_version = Release.current_version_from_mix(content)
next_version = Release.bump_version(current_version, bump_type)
updated_content = Release.replace_version_in_mix(content, next_version)
File.write!(@mix_file, updated_content)
update_dependency_docs!(next_version)
Mix.shell().info("Updated version: #{current_version} -> #{next_version}")
Mix.shell().info("Next step: mix nebula_graph_ex.tag")
end
defp prompt_bump_type do
answer =
Mix.shell().prompt("""
Select version bump:
1. patch
2. minor
3. major
> \
""")
case String.trim(answer) do
"1" -> :patch
"patch" -> :patch
"2" -> :minor
"minor" -> :minor
"3" -> :major
"major" -> :major
_ -> Mix.raise("Invalid selection. Choose 1, 2, 3, patch, minor, or major.")
end
end
defp update_dependency_docs!(version) do
Enum.each(@doc_files, fn path ->
content = File.read!(path)
updated_content = Release.replace_dependency_snippet(content, version)
File.write!(path, updated_content)
end)
end
end