Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display the git sha in my ionic app

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?

like image 912
dfstandish Avatar asked Nov 08 '22 20:11

dfstandish


1 Answers

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.

like image 171
Raphael Schweikert Avatar answered Nov 15 '22 04:11

Raphael Schweikert