diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..55d3bcc --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,3 @@ +[ + inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] +] \ No newline at end of file diff --git a/lib/mix/tasks/bin/db.ex b/lib/mix/tasks/bin/db.ex index b1e2749..de34615 100644 --- a/lib/mix/tasks/bin/db.ex +++ b/lib/mix/tasks/bin/db.ex @@ -4,16 +4,16 @@ defmodule Mix.Tasks.Version.Bin.Db do @shortdoc "Create 'rel/commands' helper scripts for managing database backup / restore" def run([]), do: run([nil, nil]) def run([backup_root]), do: run([backup_root, nil]) - def run([backup_root, dbname]) do + def run([backup_root, dbname]) do [ - "./rel/commands", + "./rel/commands" ] |> Enum.each(fn dirname -> - :ok = dirname |> Path.expand |> File.mkdir_p! - end) + :ok = dirname |> Path.expand() |> File.mkdir_p!() + end) - appname = Mix.Project.config[:app] + appname = Mix.Project.config()[:app] default_root = "/src/#{appname}backup" backup_root = backup_root || default_root dbname = dbname || appname @@ -49,25 +49,25 @@ defmodule Mix.Tasks.Version.Bin.Db do """ |> write!("./rel/commands/restore") - [ "./rel/commands/backup", - "./rel/commands/restore", + "./rel/commands/restore" ] |> Enum.each(fn filename -> - :ok = filename - |> Path.expand - |> File.chmod(0o755) - end) + :ok = + filename + |> Path.expand() + |> File.chmod(0o755) + end) - IO.puts "Installed the following scripts into ./rel/commands" - IO.puts " + backup \# Backup your database (named #{appname})" - IO.puts " + restore \# Restore your database (named #{appname})" - IO.puts "" + IO.puts("Installed the following scripts into ./rel/commands") + IO.puts(" + backup \# Backup your database (named #{appname})") + IO.puts(" + restore \# Restore your database (named #{appname})") + IO.puts("") - IO.puts "To enable those to be part of the release," - IO.puts "then ensure you update your ./rel/config.exs with:" - IO.puts "" + IO.puts("To enable those to be part of the release,") + IO.puts("then ensure you update your ./rel/config.exs with:") + IO.puts("") example = """ release :#{appname} do @@ -79,13 +79,11 @@ defmodule Mix.Tasks.Version.Bin.Db do end """ - IO.puts example - IO.puts "" - + IO.puts(example) + IO.puts("") end defp write!(content, relative_name) do - File.write!(relative_name |> Path.expand, content) + File.write!(relative_name |> Path.expand(), content) end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/bin/ff.ex b/lib/mix/tasks/bin/ff.ex index 0c3597c..fa6b884 100644 --- a/lib/mix/tasks/bin/ff.ex +++ b/lib/mix/tasks/bin/ff.ex @@ -3,17 +3,15 @@ defmodule Mix.Tasks.Version.Bin.Ff do @shortdoc "Add a FeatureFlags (FF) GenServer with release helper scripts to enable/disable them" def run(_) do - [ - "./rel/commands", + "./rel/commands" ] |> Enum.each(fn dirname -> - :ok = dirname |> Path.expand |> File.mkdir_p! - end) - - appname = Mix.Project.config[:app] - module_name = appname |> Atom.to_string |> Macro.camelize + :ok = dirname |> Path.expand() |> File.mkdir_p!() + end) + appname = Mix.Project.config()[:app] + module_name = appname |> Atom.to_string() |> Macro.camelize() """ defmodule #{module_name}.FeatureFlags do @@ -90,7 +88,6 @@ defmodule Mix.Tasks.Version.Bin.Ff do """ |> write!("./lib/#{appname}/feature_flags.ex") - """ #!/bin/bash bin/#{appname} rpc Elixir.#{module_name}.FeatureFlags enable "$1" @@ -103,22 +100,22 @@ defmodule Mix.Tasks.Version.Bin.Ff do """ |> write!("./rel/commands/disable") - [ "./rel/commands/enable", - "./rel/commands/disable", + "./rel/commands/disable" ] |> Enum.each(fn filename -> - :ok = filename - |> Path.expand - |> File.chmod(0o755) - end) - - IO.puts "Installed several release scripts into ./bin/run and ./bin/package" - IO.puts "To enable ./rel/commands/enable and ./rel/commands/disable to be" - IO.puts "part of the release, then ensure you update your ./rel/config.exs with:" - IO.puts "" - IO.puts "" + :ok = + filename + |> Path.expand() + |> File.chmod(0o755) + end) + + IO.puts("Installed several release scripts into ./bin/run and ./bin/package") + IO.puts("To enable ./rel/commands/enable and ./rel/commands/disable to be") + IO.puts("part of the release, then ensure you update your ./rel/config.exs with:") + IO.puts("") + IO.puts("") example = """ release :#{appname} do @@ -130,19 +127,17 @@ defmodule Mix.Tasks.Version.Bin.Ff do end """ - IO.puts example - IO.puts "" - IO.puts "To enable a feature flag 'brb' (for example) you would run the following:" - IO.puts " ./bin/#{appname} enable brb" - IO.puts "" - IO.puts "To later disable that flag you would run the following:" - IO.puts " ./bin/#{appname} disable brb" - IO.puts "" - + IO.puts(example) + IO.puts("") + IO.puts("To enable a feature flag 'brb' (for example) you would run the following:") + IO.puts(" ./bin/#{appname} enable brb") + IO.puts("") + IO.puts("To later disable that flag you would run the following:") + IO.puts(" ./bin/#{appname} disable brb") + IO.puts("") end defp write!(content, relative_name) do - File.write!(relative_name |> Path.expand, content) + File.write!(relative_name |> Path.expand(), content) end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/bin/release.ex b/lib/mix/tasks/bin/release.ex index 79e6c87..f5e47f3 100644 --- a/lib/mix/tasks/bin/release.ex +++ b/lib/mix/tasks/bin/release.ex @@ -3,8 +3,8 @@ defmodule Mix.Tasks.Version.Bin.Release do @shortdoc "Initialize and create some 'bin' helper scripts for managing releases" def run([]), do: run([nil]) - def run([release_root]) do + def run([release_root]) do unless File.exists?("./rel/config.exs") do Mix.Task.run("release.init", []) end @@ -12,17 +12,16 @@ defmodule Mix.Tasks.Version.Bin.Release do [ "./bin/run", "./bin/package", - "./rel/commands", + "./rel/commands" ] |> Enum.each(fn dirname -> - :ok = dirname |> Path.expand |> File.mkdir_p! - end) + :ok = dirname |> Path.expand() |> File.mkdir_p!() + end) - appname = Mix.Project.config[:app] + appname = Mix.Project.config()[:app] default_root = "/src/#{appname}rel" release_root = release_root || default_root - module_name = appname |> Atom.to_string |> Macro.camelize - + module_name = appname |> Atom.to_string() |> Macro.camelize() """ defmodule #{module_name}.ReleaseTasks do @@ -87,7 +86,6 @@ defmodule Mix.Tasks.Version.Bin.Release do """ |> write!("./lib/#{appname}/release_tasks.ex") - """ #!/bin/bash mix deps.unlock --all && \\ @@ -104,7 +102,6 @@ defmodule Mix.Tasks.Version.Bin.Release do """ |> write!("./bin/package/release") - """ #!/bin/bash VERSION=$(mix version.current) @@ -129,7 +126,6 @@ defmodule Mix.Tasks.Version.Bin.Release do """ |> write!("./bin/package/retain") - """ #!/bin/bash @@ -141,7 +137,6 @@ defmodule Mix.Tasks.Version.Bin.Release do """ |> write!("./bin/run/rel") - """ #!/bin/bash @@ -175,7 +170,6 @@ defmodule Mix.Tasks.Version.Bin.Release do """ |> write!("./bin/run/debug") - [ "./bin/package/prerelease", "./bin/package/release", @@ -184,19 +178,20 @@ defmodule Mix.Tasks.Version.Bin.Release do "./bin/run/launch", "./bin/run/debug", "./rel/commands/clear_cache", - "./rel/commands/migrate", + "./rel/commands/migrate" ] |> Enum.each(fn filename -> - :ok = filename - |> Path.expand - |> File.chmod(0o755) - end) - - IO.puts "Installed several release scripts into ./bin/run and ./bin/package" - IO.puts "To enable ./rel/commands/clear_cache and ./rel/commands/migrate to be" - IO.puts "part of the release, then ensure you update your ./rel/config.exs with:" - IO.puts "" - IO.puts "" + :ok = + filename + |> Path.expand() + |> File.chmod(0o755) + end) + + IO.puts("Installed several release scripts into ./bin/run and ./bin/package") + IO.puts("To enable ./rel/commands/clear_cache and ./rel/commands/migrate to be") + IO.puts("part of the release, then ensure you update your ./rel/config.exs with:") + IO.puts("") + IO.puts("") example = """ release :#{appname} do @@ -208,13 +203,11 @@ defmodule Mix.Tasks.Version.Bin.Release do end """ - IO.puts example - IO.puts "" - + IO.puts(example) + IO.puts("") end defp write!(content, relative_name) do - File.write!(relative_name |> Path.expand, content) + File.write!(relative_name |> Path.expand(), content) end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/current.ex b/lib/mix/tasks/current.ex index b980bff..5aff9cb 100644 --- a/lib/mix/tasks/current.ex +++ b/lib/mix/tasks/current.ex @@ -6,14 +6,14 @@ defmodule Mix.Tasks.Version.Current do def run(args) do args |> calc - |> IO.puts + |> IO.puts() end @shortdoc "Calculate the current version" def calc(_ \\ nil) do "mix.exs" - |> File.read - |> invoke(fn ({:ok, content}) -> content end) + |> File.read() + |> invoke(fn {:ok, content} -> content end) |> String.split("\n") |> Enum.map(&find_version/1) |> Enum.reject(&is_nil/1) @@ -44,5 +44,4 @@ defmodule Mix.Tasks.Version.Current do :error -> nil end end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/githooks/deploy.ex b/lib/mix/tasks/githooks/deploy.ex index cafcea7..e688141 100644 --- a/lib/mix/tasks/githooks/deploy.ex +++ b/lib/mix/tasks/githooks/deploy.ex @@ -3,45 +3,49 @@ defmodule Mix.Tasks.Githooks.Deploy do @shortdoc "Install a githook to run ./bin/deploy on a new release" def run([]), do: run(["bin/deploy"]) + def run([deploy_filename]) do post_commit_filename = ".git/hooks/post-commit" + content = """ -#!/bin/bash + #!/bin/bash -if [ "$(MIX_QUIET=true mix version.is_release)" != "" ]; then - ./bin/deploy -else - echo "Continue making the app awesome." -fi + if [ "$(MIX_QUIET=true mix version.is_release)" != "" ]; then + ./bin/deploy + else + echo "Continue making the app awesome." + fi """ + File.write!(post_commit_filename, content) :ok = File.chmod(post_commit_filename, 0o755) unless File.exists?(deploy_filename) do - deploy_filename |> Path.dirname |> Path.expand |> File.mkdir_p! + deploy_filename |> Path.dirname() |> Path.expand() |> File.mkdir_p!() + content = """ -#!/bin/bash - -VERSION=$(MIX_QUIET=1 mix version.current) -echo "=================" -echo "DEPLOYING $VERSION" -echo "Based on script in #{deploy_filename}" -echo "By default it does nothing but runs your tests" -echo "and tags your release. So please update with" -echo "what you need to do" -echo "=================" -mix test && \\ - mix version.tag + #!/bin/bash + + VERSION=$(MIX_QUIET=1 mix version.current) + echo "=================" + echo "DEPLOYING $VERSION" + echo "Based on script in #{deploy_filename}" + echo "By default it does nothing but runs your tests" + echo "and tags your release. So please update with" + echo "what you need to do" + echo "=================" + mix test && \\ + mix version.tag """ + File.write!(deploy_filename, content) :ok = File.chmod(deploy_filename, 0o755) end - IO.puts "Installed #{post_commit_filename}" - IO.puts "which will run #{deploy_filename}" - IO.puts "after a 'mix version.up'" + IO.puts("Installed #{post_commit_filename}") + IO.puts("which will run #{deploy_filename}") + IO.puts("after a 'mix version.up'") post_commit_filename end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/githooks/hexup.ex b/lib/mix/tasks/githooks/hexup.ex index 2b1276a..ac4dcba 100644 --- a/lib/mix/tasks/githooks/hexup.ex +++ b/lib/mix/tasks/githooks/hexup.ex @@ -3,30 +3,32 @@ defmodule Mix.Tasks.Githooks.Hexup do @shortdoc "Install a githook to run mix hex.publish on a new release" def run([]), do: run([""]) + def run([passphrase]) do filename = ".git/hooks/post-commit" + content = """ -#!/bin/bash -if [ "$(MIX_QUIET=true mix version.is_release)" != "" ]; then - echo "=================" - echo "HEX PUBLISH $VERSION" - echo "=================" - mix test && \\ - mix version.tag && \\ - mix hex.publish < File.read - |> invoke(fn ({:ok, content}) -> content end) + |> File.read() + |> invoke(fn {:ok, content} -> content end) |> String.split("\n") |> Enum.map(fn line -> update_fn.(line, current, next) end) |> Enum.join("\n") |> invoke(fn content -> File.write!(filename, content) end) else - IO.puts " -- Skipping missing file #{filename}" + IO.puts(" -- Skipping missing file #{filename}") end end - defp update_mix_version(line, current, next) do line |> String.replace("@version \"#{current}\"", "@version \"#{next}\"") @@ -43,5 +41,4 @@ defmodule Mix.Tasks.Version.Inc do line |> String.replace("~> #{current}", "~> #{next}") end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/is_release.ex b/lib/mix/tasks/is_release.ex index 7710020..0174834 100644 --- a/lib/mix/tasks/is_release.ex +++ b/lib/mix/tasks/is_release.ex @@ -5,15 +5,14 @@ defmodule Mix.Tasks.Version.IsRelease do @shortdoc "Return the name (major|minor|patch) of the version if this is a release, nothing otherwise" def run(_) do - calc() |> IO.puts + calc() |> IO.puts() end def calc() do - if "v#{Current.calc}" == LastCommit.calc do - Name.calc + if "v#{Current.calc()}" == LastCommit.calc() do + Name.calc() else "" end end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/last_commit.ex b/lib/mix/tasks/last_commit.ex index 98c87c0..c6fc3f8 100644 --- a/lib/mix/tasks/last_commit.ex +++ b/lib/mix/tasks/last_commit.ex @@ -6,16 +6,15 @@ defmodule Mix.Tasks.Version.LastCommit do def run(args) do args |> calc - |> IO.puts + |> IO.puts() end @shortdoc "Calculate the last git commit message" def calc(_ \\ nil) do "." - |> Git.new + |> Git.new() |> Git.log(["--format=%B", "-n 1", "HEAD"]) |> invoke(fn {:ok, output} -> output end) - |> String.trim + |> String.trim() end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/major.ex b/lib/mix/tasks/major.ex index 1c2aea1..a1d5911 100644 --- a/lib/mix/tasks/major.ex +++ b/lib/mix/tasks/major.ex @@ -5,10 +5,11 @@ defmodule Mix.Tasks.Version.Major do @shortdoc "Return major number (so return '1' for version '1.2.3'" def run(_) do - calc() |> IO.puts + calc() |> IO.puts() end - def calc(), do: calc(Current.calc) + def calc(), do: calc(Current.calc()) + def calc(version) do version |> String.split(".") @@ -17,5 +18,4 @@ defmodule Mix.Tasks.Version.Major do defp name([major, _, _]), do: major defp name(_), do: "" - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/minor.ex b/lib/mix/tasks/minor.ex index 80084d6..e992b24 100644 --- a/lib/mix/tasks/minor.ex +++ b/lib/mix/tasks/minor.ex @@ -5,10 +5,11 @@ defmodule Mix.Tasks.Version.Minor do @shortdoc "Return minor number (so return '2' for version '1.2.3'" def run(_) do - calc() |> IO.puts + calc() |> IO.puts() end - def calc(), do: calc(Current.calc) + def calc(), do: calc(Current.calc()) + def calc(version) do version |> String.split(".") @@ -17,5 +18,4 @@ defmodule Mix.Tasks.Version.Minor do defp name([_, minor, _]), do: minor defp name(_), do: "" - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/name.ex b/lib/mix/tasks/name.ex index e838e9f..e595e15 100644 --- a/lib/mix/tasks/name.ex +++ b/lib/mix/tasks/name.ex @@ -5,10 +5,11 @@ defmodule Mix.Tasks.Version.Name do @shortdoc "Return the name (major|minor|patch) of this version" def run(_) do - calc() |> IO.puts + calc() |> IO.puts() end - def calc(), do: calc(Current.calc) + def calc(), do: calc(Current.calc()) + def calc(version) do version |> String.split(".") @@ -18,5 +19,4 @@ defmodule Mix.Tasks.Version.Name do defp name([_, "0", "0"]), do: :major defp name([_, _, "0"]), do: :minor defp name(_), do: :patch - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/next.ex b/lib/mix/tasks/next.ex index f736974..6a31ed5 100644 --- a/lib/mix/tasks/next.ex +++ b/lib/mix/tasks/next.ex @@ -7,12 +7,13 @@ defmodule Mix.Tasks.Version.Next do def run(args) do args |> calc - |> IO.puts + |> IO.puts() end def calc([]), do: calc(["patch"]) + def calc([mode]) do - Current.calc + Current.calc() |> String.split(".") |> uptick(mode) end @@ -31,5 +32,4 @@ defmodule Mix.Tasks.Version.Next do {new_val, ""} = Integer.parse(major) "#{new_val + 1}.0.0" end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/patch.ex b/lib/mix/tasks/patch.ex index 1b75d9b..8f53f9c 100644 --- a/lib/mix/tasks/patch.ex +++ b/lib/mix/tasks/patch.ex @@ -5,10 +5,11 @@ defmodule Mix.Tasks.Version.Patch do @shortdoc "Return patch number (so return '3' for version '1.2.3'" def run(_) do - calc() |> IO.puts + calc() |> IO.puts() end - def calc(), do: calc(Current.calc) + def calc(), do: calc(Current.calc()) + def calc(version) do version |> String.split(".") @@ -17,5 +18,4 @@ defmodule Mix.Tasks.Version.Patch do defp name([_, _, patch]), do: patch defp name(_), do: "" - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/release/bin.ex b/lib/mix/tasks/release/bin.ex index 4a98739..866fdfc 100644 --- a/lib/mix/tasks/release/bin.ex +++ b/lib/mix/tasks/release/bin.ex @@ -3,10 +3,7 @@ defmodule Mix.Tasks.Release.Bin do @shortdoc "OBSOLETE... please refer to `mix version.bin.run`" def run(args) do - IO.puts("OBSOLETE... please refer to `mix version.bin.run`") Mix.Tasks.Version.Bin.Release.run(args) - end - end diff --git a/lib/mix/tasks/tag.ex b/lib/mix/tasks/tag.ex index b4eb461..6c20736 100644 --- a/lib/mix/tasks/tag.ex +++ b/lib/mix/tasks/tag.ex @@ -6,13 +6,12 @@ defmodule Mix.Tasks.Version.Tag do @shortdoc "Git tag your project (e.g. v1.2.3)" def run(args) do current_version = Version.Current.calc(args) - repo = Git.new "." - {:ok, _} = Git.tag repo, ["v#{current_version}"] - {:ok, output} = Git.push repo - IO.puts output - {:ok, output} = Git.push repo, ["--tag"] - IO.puts output + repo = Git.new(".") + {:ok, _} = Git.tag(repo, ["v#{current_version}"]) + {:ok, output} = Git.push(repo) + IO.puts(output) + {:ok, output} = Git.push(repo, ["--tag"]) + IO.puts(output) current_version end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/untag.ex b/lib/mix/tasks/untag.ex index fed428c..420259c 100644 --- a/lib/mix/tasks/untag.ex +++ b/lib/mix/tasks/untag.ex @@ -6,12 +6,11 @@ defmodule Mix.Tasks.Version.Untag do @shortdoc "Remove the tag from your project (e.g. v1.2.3)" def run(args) do current_version = Version.Current.calc(args) - repo = Git.new "." - {:ok, output} = Git.tag repo, ["-d", "v#{current_version}"] - IO.puts output - {:ok, output} = Git.push repo, ["origin", ":refs/tags/v#{current_version}"] - IO.puts output + repo = Git.new(".") + {:ok, output} = Git.tag(repo, ["-d", "v#{current_version}"]) + IO.puts(output) + {:ok, output} = Git.push(repo, ["origin", ":refs/tags/v#{current_version}"]) + IO.puts(output) current_version end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/up.ex b/lib/mix/tasks/up.ex index dfe0e95..1cab1ee 100644 --- a/lib/mix/tasks/up.ex +++ b/lib/mix/tasks/up.ex @@ -8,16 +8,16 @@ defmodule Mix.Tasks.Version.Up do next_version = Version.Inc.run(mode) updated_version = Version.Current.calc(mode) - if (next_version == updated_version) do - IO.puts "Committing updates to git" - repo = Git.new "." - {:ok, _} = Git.add repo, ["mix.exs", "README.md"] - {:ok, output} = Git.commit repo, ["-m", "v#{updated_version}"] - IO.puts output + if next_version == updated_version do + IO.puts("Committing updates to git") + repo = Git.new(".") + {:ok, _} = Git.add(repo, ["mix.exs", "README.md"]) + {:ok, output} = Git.commit(repo, ["-m", "v#{updated_version}"]) + IO.puts(output) else - IO.puts "Unable to update version, stopping task. Sorry we couldn't automate better :-(" + IO.puts("Unable to update version, stopping task. Sorry we couldn't automate better :-(") end + updated_version end - -end \ No newline at end of file +end diff --git a/lib/mix/tasks/version.ex b/lib/mix/tasks/version.ex index 297b127..a68931d 100644 --- a/lib/mix/tasks/version.ex +++ b/lib/mix/tasks/version.ex @@ -5,38 +5,56 @@ defmodule Mix.Tasks.Version do @shortdoc "Learn more about the available version tasks" def run(_) do - Shell.info "version_tasks v" <> VersionTasks.version - Shell.info "version_tasks is a set of helper mix tasks to manange your projects version" - Shell.newline + Shell.info("version_tasks v" <> VersionTasks.version()) + Shell.info("version_tasks is a set of helper mix tasks to manange your projects version") + Shell.newline() - Shell.info "Available version tasks:" - Shell.newline + Shell.info("Available version tasks:") + Shell.newline() # Run `mix help --search version.`, and # Run `mix help --search githooks.` to get this output # and paste here - Shell.info "mix version.bin.db # Create 'bin/db' helper scripts for managing database backups" - Shell.info "mix version.bin.ff # Add a FeatureFlags (FF) GenServer with release helper scripts to enable/disable them" - Shell.info "mix version.bin.release # Initialize and create some 'bin' helper scripts for managing releases" - Shell.info "mix version.current # Calculate the current version" - Shell.info "mix version.inc # Inc to the next (major|minor|patch) version of your project" - Shell.info "mix version.is_release # Return the name (major|minor|patch) of the version if this is a release, nothing otherwise" - Shell.info "mix version.last_commit # Calculate the last git commit message" - Shell.info "mix version.name # Return the name (major|minor|patch) of this version" - Shell.info "mix version.next # The next version (e.g v0.9.2)" - Shell.info "mix version.tag # Git tag your project (e.g. v1.2.3)" - Shell.info "mix version.untag # Remove the git tag from your repo (e.g. v1.2.3)" - Shell.info "mix version.up # Inc to next version, and commit changes to git" - Shell.info "mix githooks.hexup # Install a githook to run mix hex.publish on a new release" - Shell.info "mix githooks.deploy # Install a githook to run ./bin/deploy on a new release" - - Shell.newline - - Shell.info "Further information can be found here:" - Shell.info " -- https://hex.pm/packages/version_tasks" - Shell.info " -- https://github.com/aforward/version_tasks" - Shell.newline + Shell.info( + "mix version.bin.db # Create 'bin/db' helper scripts for managing database backups" + ) - end + Shell.info( + "mix version.bin.ff # Add a FeatureFlags (FF) GenServer with release helper scripts to enable/disable them" + ) + + Shell.info( + "mix version.bin.release # Initialize and create some 'bin' helper scripts for managing releases" + ) + + Shell.info("mix version.current # Calculate the current version") + + Shell.info( + "mix version.inc # Inc to the next (major|minor|patch) version of your project" + ) + + Shell.info( + "mix version.is_release # Return the name (major|minor|patch) of the version if this is a release, nothing otherwise" + ) -end \ No newline at end of file + Shell.info("mix version.last_commit # Calculate the last git commit message") + Shell.info("mix version.name # Return the name (major|minor|patch) of this version") + Shell.info("mix version.next # The next version (e.g v0.9.2)") + Shell.info("mix version.tag # Git tag your project (e.g. v1.2.3)") + Shell.info("mix version.untag # Remove the git tag from your repo (e.g. v1.2.3)") + Shell.info("mix version.up # Inc to next version, and commit changes to git") + + Shell.info( + "mix githooks.hexup # Install a githook to run mix hex.publish on a new release" + ) + + Shell.info("mix githooks.deploy # Install a githook to run ./bin/deploy on a new release") + + Shell.newline() + + Shell.info("Further information can be found here:") + Shell.info(" -- https://hex.pm/packages/version_tasks") + Shell.info(" -- https://github.com/aforward/version_tasks") + Shell.newline() + end +end diff --git a/lib/version_tasks.ex b/lib/version_tasks.ex index b740aae..c6fb66b 100644 --- a/lib/version_tasks.ex +++ b/lib/version_tasks.ex @@ -1,6 +1,5 @@ defmodule VersionTasks do - - @moduledoc""" + @moduledoc """ A set of Mix Tasks for managing your version numbers. This is best used in conjunction with your release strategy, and so we also provide some opionated generated code / bash scripts to support you in your quest for @@ -356,7 +355,6 @@ defmodule VersionTasks do ./bin/db/restore # Restore your database """ - def version(), do: unquote(Mix.Project.config[:version]) - def elixir_version(), do: unquote(System.version) - + def version(), do: unquote(Mix.Project.config()[:version]) + def elixir_version(), do: unquote(System.version()) end diff --git a/lib/version_tasks/fn_expr.ex b/lib/version_tasks/fn_expr.ex index 19289f0..03834fa 100644 --- a/lib/version_tasks/fn_expr.ex +++ b/lib/version_tasks/fn_expr.ex @@ -1,6 +1,5 @@ defmodule VersionTasks.FnExpr do - - @moduledoc""" + @moduledoc """ THIS IS A DUPLICATE OF https://hex.pm/packages/fn_expr so that project can leverage this version management (avoiding) a circular @@ -16,9 +15,17 @@ defmodule VersionTasks.FnExpr do quote do defmacro invoke(piped_in_argument, expr) do fun = is_tuple(expr) && elem(expr, 0) + case fun do - :fn -> quote do (unquote(expr)).(unquote(piped_in_argument)) end - _ -> quote do (&(unquote(expr))).(unquote(piped_in_argument)) end + :fn -> + quote do + unquote(expr).(unquote(piped_in_argument)) + end + + _ -> + quote do + (&unquote(expr)).(unquote(piped_in_argument)) + end end end end @@ -33,8 +40,7 @@ defmodule VersionTasks.FnExpr do defmacro unquote(:&&)(piped_in_argument, expr) do quote do - (&(unquote(expr))).(unquote(piped_in_argument)) + (&unquote(expr)).(unquote(piped_in_argument)) end end - end diff --git a/lib/version_tasks/shell.ex b/lib/version_tasks/shell.ex index f21ef66..d3df35d 100644 --- a/lib/version_tasks/shell.ex +++ b/lib/version_tasks/shell.ex @@ -1,13 +1,15 @@ defmodule VersionTasks.Shell do - def info(raw_msg, args \\ %{}) do case parse(raw_msg, args) do - {:quiet, msg} -> msg - {:ok, msg} -> if has_mix?() do - Mix.shell.info(msg) - else - IO.puts(msg) - end + {:quiet, msg} -> + msg + + {:ok, msg} -> + if has_mix?() do + Mix.shell().info(msg) + else + IO.puts(msg) + end end end @@ -19,32 +21,39 @@ defmodule VersionTasks.Shell do def error(raw_msg, args \\ %{}) do case parse(raw_msg, args) do - {:quiet, msg} -> msg - {:ok, msg} -> if has_mix?() do - Mix.shell.error(msg) - else - IO.puts(msg) - end + {:quiet, msg} -> + msg + + {:ok, msg} -> + if has_mix?() do + Mix.shell().error(msg) + else + IO.puts(msg) + end end end def raise(raw_msg, args \\ %{}) do case parse(raw_msg, args) do - {:quiet, msg} -> msg - {:ok, msg} -> if has_mix?() do - Mix.raise(msg) - else - Kernel.raise(msg) - end + {:quiet, msg} -> + msg + + {:ok, msg} -> + if has_mix?() do + Mix.raise(msg) + else + Kernel.raise(msg) + end end end - def newline, do: info "" + def newline, do: info("") defp has_mix?, do: function_exported?(Mix, :shell, 1) defp parse(msg, args), do: _parse(msg |> clean, args) defp _parse(msg, %{quiet: true}), do: {:quiet, msg} + defp _parse(msg, args) when is_list(args) do if Enum.member?(args, "--quiet") do {:quiet, msg} @@ -52,8 +61,8 @@ defmodule VersionTasks.Shell do {:ok, msg} end end + defp _parse(msg, _), do: {:ok, msg} defp clean(msg) when is_binary(msg), do: msg defp clean(msg), do: "#{msg}" - -end \ No newline at end of file +end diff --git a/mix.exs b/mix.exs index 1c38241..2336d7d 100644 --- a/mix.exs +++ b/mix.exs @@ -9,7 +9,7 @@ defmodule VersionTasks.Mixfile do @deps [ {:mix_test_watch, "~> 0.3", only: :dev, runtime: false}, {:git_cli, "~> 0.2"}, - {:ex_doc, "0.16.1", only: [ :dev, :test ]}, + {:ex_doc, "0.16.1", only: [:dev, :test]} ] @package [ @@ -23,31 +23,30 @@ defmodule VersionTasks.Mixfile do # ------------------------------------------------------------ def project do - in_production = Mix.env == :prod + in_production = Mix.env() == :prod + [ - app: @app, + app: @app, version: @version, - elixir: "~> 1.4", + elixir: "~> 1.6", name: "VersionTasks", description: "A suite of mix tasks for managing your libs version numbers with git and hex", package: @package, source_url: @git_url, homepage_url: @home_url, - docs: [main: "VersionTasks", - extras: ["README.md"]], - build_embedded: in_production, - start_permanent: in_production, - deps: @deps, + docs: [main: "VersionTasks", extras: ["README.md"]], + build_embedded: in_production, + start_permanent: in_production, + deps: @deps ] - end def application do [ - extra_applications: [ # built-in apps that need starting + # built-in apps that need starting + extra_applications: [ :logger - ], + ] ] end - end diff --git a/mix.lock b/mix.lock index cd262b7..9162c99 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ -%{"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, +%{"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "fn_expr": {:hex, :fn_expr, "0.1.0", "ef482fa3b355067f78cf7eadb82ea90f29b5d64a21d7d3e3e4a0eefdf4f71b4d", [], [], "hexpm"}, - "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [], [], "hexpm"}, - "git_cli": {:hex, :git_cli, "0.2.3", "052f0ecfc43d86fb4a750741540bdb00ac63354c6588024555be62c8ea1eff33", [], [], "hexpm"}, - "mix_test_watch": {:hex, :mix_test_watch, "0.4.1", "a98a84c795623f1ba020324f4354cf30e7120ba4dab65f9c2ae300f830a25f75", [], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"}, + "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"}, + "git_cli": {:hex, :git_cli, "0.2.4", "43f58045f5d168fa2cff8d2e3822b8c43f294b4b832a419ed8cc01337f1c5b3d", [:mix], [], "hexpm"}, + "mix_test_watch": {:hex, :mix_test_watch, "0.5.0", "2c322d119a4795c3431380fca2bca5afa4dc07324bd3c0b9f6b2efbdd99f5ed3", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"}, "porcelain": {:hex, :porcelain, "2.0.3", "2d77b17d1f21fed875b8c5ecba72a01533db2013bd2e5e62c6d286c029150fdc", [:mix], [], "hexpm"}} diff --git a/test/tasks/name_test.exs b/test/tasks/name_test.exs index a387cef..517e728 100644 --- a/test/tasks/name_test.exs +++ b/test/tasks/name_test.exs @@ -12,6 +12,5 @@ defmodule Mix.Tasks.Version.NameTest do assert :major == Name.calc("1.0.0") assert :major == Name.calc("2.0.0") - end end