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

ci/gitTag.js   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 42
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
dl 0
loc 42
rs 10
c 1
b 1
f 0
cc 2
nc 4
mnd 1
bc 6
fnc 2
bpm 3
cpm 2
noi 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A gitTag.js ➔ withoutDot 0 4 1
A gitTag.js ➔ patch 0 5 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
}