Skip to content

Commit

Permalink
Implemented refs parsing to get latest tag or head ref
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Jan 12, 2016
1 parent 2c02ae5 commit e47c84c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
Expand Up @@ -6,11 +6,15 @@ namespace common.models {

let systemInfoData = {
"latestCommit": {
"commit": seededChance.hash,
"commit": seededChance.hash(),
"author": "John Doe <john.doe@example.com>",
"date": seededChance.date().toISOString(),
"message": seededChance.sentence()
},
"refs": {
"latestTagOrHead": "/heads/feature/" + seededChance.word,
"commitRef": seededChance.hash(),
},
"appBuildDate": seededChance.date().toISOString(),
"ciBuild": {
"id": "%ciBuild.id%",
Expand Down
Expand Up @@ -13,9 +13,15 @@ namespace common.models {
message: string;
}

export interface ICommitRefs {
latestTagOrHead: string;
commitRef: string;
}

export class SystemInformation extends AbstractModel{

public latestCommit: ICommitInfo;
public refs: ICommitRefs;
public appBuildDate:moment.Moment;
public ciBuild:ICIInfo;
public ciDeployment:ICIInfo;
Expand Down
51 changes: 34 additions & 17 deletions gulpfile.js
Expand Up @@ -479,24 +479,41 @@ gulp.task('build:write-log', 'writes git log to file for system information disp
plugins.git.exec({args : '--no-pager log -n 1 --pretty=format:\'{%n "commit": "%H",%n "author": "%an <%aE>",%n "date": "%aI",%n "message": "%f"%n}\''}, function (err, stdout) {
if (err) throw err;

var latestCommit = JSON.parse(stdout);

var systemInfo = {
latestCommit: latestCommit,
appBuildDate: new Date().toISOString(),
ciBuild: {
id: '%ciBuild.id%',
url: '%ciBuild.url%',
date: '%ciBuild.date%'
},
ciDeployment: {
id: '%ciDeployment.deploymentId%',
url: '%ciDeployment.url%',
date: '%ciDeployment.date%'
}
};
plugins.git.exec({args:'describe --abbrev=0 --tags --all && git rev-list -n 1 $(git describe --abbrev=0 --tags --all)'}, function (err, output) {
if (err) throw err;

var latestCommit = JSON.parse(stdout);
var refs = output.split('\n');

var systemInfo = {
latestCommit: latestCommit,
refs: {
latestTagOrHead: refs[0],
commitRef: refs[1]
},
appBuildDate: new Date().toISOString(),
ciBuild: {
id: '%ciBuild.id%',
url: '%ciBuild.url%',
date: '%ciBuild.date%'
},
ciDeployment: {
id: '%ciDeployment.deploymentId%',
url: '%ciDeployment.url%',
date: '%ciDeployment.date%'
}
};

var jsonDocument = JSON.stringify(systemInfo, null, 4);
var fs = require('fs');

// we write the same file twice, to both app and api so we can verify the versions independently as they are
// potentially deployed to separate docker nodes
fs.writeFileSync('app/build/build-info.json', jsonDocument);
fs.writeFileSync('api/storage/app/build-info.json', jsonDocument);

});

require('fs').writeFileSync('app/build/build-info.json', JSON.stringify(systemInfo, null, 4));

});
});
Expand Down

0 comments on commit e47c84c

Please sign in to comment.