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
app_version(opts \\ [])
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.
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.
write_sys_config!(env, config_file, out_file_sfx \\ "sys.config")
Generate system config file (defaults to ${env}.sys.config
) from the Elixir
config_filename
provided in the input.
write_sys_configs!(out_file_sfx \\ "sys.config", exclude_basenames \\ [])
Generate *.config
system config files from the files found in the config
directory.