Utix (Utix v0.1.0)

Miscellaneous helper functions

Summary

Functions

Obtain the version of the current application.

If the list length is not greater than max_len, stringify it. Otherwise return the item count in the list as a string.

Generate system config file (defaults to ${env}.sys.config) from the Elixir config_filename provided in the input.

Generate *.config system config files from the files found in the config directory.

Functions

Link to this function

app_version(opts \\ [])

@spec app_version(Keyword.t()) :: String.t()

Obtain the version of the current application.

This function must be called from a Mix project file.

Options

  • verbose: true - Enable printing of application version

You can also set the environment variable SHOW_APP_VERSION=true to print application version instead of passing the keyword list to the function.

Why is this needed?

When a mix project version is hard-coded in the mix.exs file, it is easy to get it out of sync with the latest tag in the git history, or the latest git revision. With this method, the app version is automatically determined either from the hex.pm's metadata or from git history and is used to set the application version in the generated *.app file.

If the project is loaded as a dependency from Hex.pm, then the project contains ".hex" file, which contains the version. If it's loaded from git, then we can use "git describe" command to format the version with a revision.

On the other hand if the dependency tries to use the git describe --tags ... command by itself, the output of the version will be reflecting the version from the parent application's git history, which is wrong.

NOTE

With this method of calculating the version number, you need to make sure that in the Github action the checkout includes:

  - name: Checkout the repository
    uses: actions/checkout@v4
    with:
      fetch-depth: 0

This ensures that the git history is checked out with tags so that git describe --tags returns the proper version number.

Link to this function

str_or_count(list, max_len \\ 10)

@spec str_or_count(list(), non_neg_integer()) :: binary()

If the list length is not greater than max_len, stringify it. Otherwise return the item count in the list as a string.

Link to this function

write_sys_config!(env, config_file, out_file_sfx \\ "sys.config")

@spec write_sys_config!(atom(), String.t(), String.t()) :: String.t()

Generate system config file (defaults to ${env}.sys.config) from the Elixir config_filename provided in the input.

Link to this function

write_sys_configs!(out_file_sfx \\ "sys.config", exclude_basenames \\ [])

@spec write_sys_configs!(String.t(), [String.t()]) :: [String.t()]

Generate *.config system config files from the files found in the config directory.