Merge pull request #2361 from thelounge/astorije/version

Add project version in outputs that mention source SHA
This commit is contained in:
Jérémie Astori 2018-04-16 16:22:39 +02:00 committed by GitHub
commit 0797cfad84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -51,7 +51,8 @@ Helper.config = require(path.resolve(path.join(
function getVersion() {
const gitCommit = getGitCommit();
return gitCommit ? `source (${gitCommit})` : `v${pkg.version}`;
const version = `v${pkg.version}`;
return gitCommit ? `source (${gitCommit} / ${version})` : version;
}
let _gitCommit;
@ -61,9 +62,17 @@ function getGitCommit() {
return _gitCommit;
}
if (!fs.existsSync(path.resolve(__dirname, "..", ".git", "HEAD"))) {
_gitCommit = null;
return null;
}
try {
_gitCommit = require("child_process")
.execSync("git rev-parse --short HEAD 2> /dev/null") // Returns hash of current commit
.execSync(
"git rev-parse --short HEAD", // Returns hash of current commit
{stdio: ["ignore", "pipe", "ignore"]}
)
.toString()
.trim();
return _gitCommit;

View File

@ -36,4 +36,20 @@ describe("Helper", function() {
expect(Helper.expandHome(undefined)).to.equal("");
});
});
describe("#getVersion()", function() {
const version = Helper.getVersion();
it("should mention it is served from source code", function() {
expect(version).to.include("source");
});
it("should include a short Git SHA", function() {
expect(version).to.match(/\([0-9a-f]{7,11} /);
});
it("should include a valid semver version", function() {
expect(version).to.match(/v[0-9]+\.[0-9]+\.[0-9]+/);
});
});
});