forked from mwbowers/assembly-info-version
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (27 loc) · 1.08 KB
/
index.js
File metadata and controls
38 lines (27 loc) · 1.08 KB
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
33
34
35
36
37
38
const fs = require('fs');
const os = require("os");
function run()
{
aip = process.env.AI_PATH || process.env.INPUT_AI_PATH;
if (!fs.existsSync(aip))
throw new Error('AssemblyInfo file not found');
console.log(`AssemblyInfo Path: ${aip}`)
rgx = new RegExp('\\[assembly: AssemblyVersion\\(\\"(.*)\\"\\)\\]', 'm');
ver = rgx.exec(fs.readFileSync(aip, { encoding: 'utf-8' }))[1];
if (!ver)
throw new Error('Failed to get Assembly Version');
vp = process.env.VER_PLACES || process.env.INPUT_VER_PLACES;
console.log(`process.env.VER_PLACES: ${process.env.VER_PLACES}`)
console.log(`process.env.INPUT_VER_PLACES: ${process.env.INPUT_VER_PLACES}`)
console.log(`vp: ${vp}`)
if (vp < 0 || vp > 4)
throw new Error('Invalid version places');
if (vp > 0 && vp < 4){
var verSplit = ver.split('.');
verSplit = verSplit.slice(0, vp);
ver = verSplit.join('.');
}
console.log(`Assembly Version: ${ver}`)
process.stdout.write(`::set-output name=ASSEMBLY_VERSION::${ver}` + os.EOL)
}
run();