forked from vtex/git-tag-match
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (26 loc) · 811 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs')
const path = require('path')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
function getGitVersion() {
return exec('git describe --exact-match HEAD').then(response => {
const version = response.stdout.replace(/v|\n/gi, '')
return version
})
}
function getReferenceFile(fileName) {
const file = fs.readFileSync(path.join(process.cwd(), fileName))
return JSON.parse(file)
}
function matchGitTag(referenceFileName) {
const file = getReferenceFile(referenceFileName)
const referenceVersion = file.version
return getGitVersion().then(gitVersion => {
return {
gitVersion: gitVersion,
referenceVersion: referenceVersion,
match: gitVersion === referenceVersion,
}
})
}
module.exports = matchGitTag