pack: no way to retrieve app version during build within pack context
When packing, cartridge CLI copies project into temprorary directory and does some cleanup there. It also removes .git directory.
In my application I'm building multiple artifacts which need to have version tag inside. Right now it seems there is no way to get app version from within pack context.
One way to workaround this is to keep version file in version control. But this is not always convenient. It would be more flexible to provide some context for the app when building (i.e. through environment variables like CARTRIDGE_<VARNAME>)
I was able to workaround this with bypassing environment variables myself (VERSION="1.0.0" cartridge pack ...), but still it would be convenient if cartridge did it for me
I propose to generally reflect packpack's behaviour:
- A user can place (or generate) the
VERSIONfile or can set theVERSIONenvironment variable. - If neither is given, packpack defaults to
git describe --long --always(first three numbers from it). - Whether the
VERSIONenvironment variable is set by a user or packpack itself, it is available in the build context and (if there is noVERSIONfile) is placed to theVERSIONfile (full git describe output, don't know why). - If the VERSION file is tracked by git, it is available in the build context without changes. So, if it is a generated file, one should explicitly call
git addto add it to the build context. - A
VERSIONfile content is not available in the environment variable (as I see from packpack's code), however it looks a bit inconsistent.
The relevant packpack's code:
https://github.com/packpack/packpack/blob/0154f5e5af03126744e3ff35648de7264a011fcd/packpack#L150 https://github.com/packpack/packpack/blob/0154f5e5af03126744e3ff35648de7264a011fcd/packpack#L196 https://github.com/packpack/packpack/blob/0154f5e5af03126744e3ff35648de7264a011fcd/pack/config.mk#L45-L48 https://github.com/packpack/packpack/blob/0154f5e5af03126744e3ff35648de7264a011fcd/pack/tarball.mk#L8-L16
So, in other words, what I propose:
- Read the
--versionoption. - If no option provided, read the
VERSIONenvironment variable. - If neither of them provided, read the
VERSIONfile. - If nothing from those three sources available, try to autodetermine using
git describe --long --always. - If git describe fails, use
0.0.1-1.
/* The format should be the same for all sources. The README states the following: major.minor.patch[-count][-commit] normalized to major.minor.patch-count. Let's use it. */
- Write the
VERSIONfile for the build context (issue a warning and don't touch it if it is already there and differs from the version determined above). - Set the
VERSIONenvironemnt variable for the build context.
@RunsFor Will such approach solve your problem?