Get Git version control and save in a PHP constant

1

Is there a possible way to save the GIT hash within the PHP code or a version number automatically every time you push, or by Javascript, using gulp, save the version in PHP?

I would like to do this so I do not have to manually put the version of the application.

define('VERSION_WEBAPP', '0.6.1');

would be something like:

$git_version = 'pegaria o rash ou número do commit';

define('VERSION_WEBAPP', $git_version);
    
asked by anonymous 17.01.2018 / 12:17

1 answer

0

I discovered a cool way using gulp ...

var gulp = require('gulp');
var fs = require('fs');
var version = '1.2.3.' + (new Date()).getTime();

gulp.task('version', function(cb){
     fs.writeFile('./application/configs/version.ini', '[version]\nversion = '+version, cb);
});

And in PHP:

$version_app = new Zend_Config_Ini(APPLICATION_PATH . '/configs/version.ini', 'version');
$data_version = $version_app->toArray();

define('VERSION_WEBAPP', $data_version['version']);
    
19.01.2018 / 14:14