Is there an established pattern to inject the git hash at build time into an ionic app?
I'm using https://www.npmjs.com/package/cordova-plugin-appversion to show the build version - but I'd also like to show the short hash (first 7 characters).
Is it hacky to write it out to a properties file in the gulp build (putting that file on .gitignore) and then if the file is present showing it in the app?
I’d say using your build system (i.e. gulp) for this job is exactly the right way to go about this and not “hacky” at all.
Instead of including only the hash in your version string, you might want to include the output of git describe
which also contains the name of the most recent tag and how many revisions have passed since then.
However, if your Gulpfile outputs release assets that are version-controlled, you’ll have a small problem: if you create a commit with the released version (and maybe tag it), the hash you built into the app before won’t point to the commit with the assets you actually built for this release but to the version before it. That’s why most people use tags and version numbers, not hashes, to cross-reference the version of an app binary with the state of the source repository at build time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With