Completed
Push — master ( 915c9b...cca4af )
by Janis
15:20 queued 13:39
created

gitTag.js ➔ patch   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 1
f 0
cc 1
nc 1
nop 1
1
const cp = require('child_process');
2
const path = require('path');
3
4
const appInfo = cp.execSync('grep -oPm1 "(?<=<version>)[^<]+" appinfo/info.xml').toString().trim();
5
6
console.log('AppInfo: ' + appInfo);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
7
8
const appInfoFloat = withoutDot(appInfo);
9
10
let gitTagOld;
11
try {
12
    gitTagOld = cp.execSync('git describe --tags $(git rev-list --tags --max-count=1)').toString().trim();
13
} catch (e) {
14
    gitTagOld = 0;
15
}
16
console.log('Current git tag:' + gitTagOld);
17
18
const gitTagOldFloat = withoutDot(gitTagOld);
19
20
if (appInfoFloat > gitTagOldFloat) {
21
    // git tag with appInfo
22
    console.log('major or minor version step');
23
    cp.execSync('git tag ' + appInfo);
24
} else {
25
    console.log('they equal or git tag version is higher => patch version step');
26
    const newVersion = patch(gitTagOld);
27
    // git tag with newVersion
28
    console.log('New version: '+ newVersion);
29
    cp.execSync('git tag ' + newVersion);
30
    cp.execSync('sed -i \"s\/\\(<version.*>\\)[^<>]*\\(<\\\/version.*\\)\/\\1' + newVersion + '\\2\/\" ' + path.resolve(__dirname, '..\/appinfo\/info.xml'));
31
}
32
33
function patch(v) {
34
    const parts = v.split('.');
35
    parts.push(Number.parseInt(parts.pop()) + 1);
36
    return parts.join('.');
37
}
38
39
function withoutDot(v) {
40
    const parts = v.split('.');
41
    return Number.parseFloat(parts.shift() + '.' + parts.join(''));
42
}