-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (60 loc) · 1.62 KB
/
index.js
File metadata and controls
71 lines (60 loc) · 1.62 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const core = require("@actions/core");
const fs = require("fs");
const xpath = require("xpath");
const dom = require("xmldom").DOMParser;
try {
let projectFile = core.getInput("project-file");
let suffix = core.getInput("suffix");
let build = core.getInput("build");
let offset = core.getInput("offset");
var text = fs.readFileSync(projectFile, "utf8");
var doc = new dom().parseFromString(text);
var currentVersion = xpath.select(
"string(/Project/PropertyGroup/AssemblyVersion)",
doc
);
var currentFileVersion = xpath.select(
"string(/Project/PropertyGroup/FileVersion)",
doc
);
let nextVersion = yyyymmdd() + ".";
const versionParts = currentVersion.split(".");
if (!build) {
let revision = versionParts[versionParts.length - 1];
revision++;
nextVersion += revision;
} else {
let wantedBuild = parseInt(build);
if (offset) wantedBuild = parseInt(build) + parseInt(offset);
nextVersion += wantedBuild;
}
text = text.replace(
"<AssemblyVersion>" + currentVersion + "</AssemblyVersion>",
"<AssemblyVersion>" + nextVersion + "</AssemblyVersion>"
);
if (suffix) {
nextVersion = nextVersion + "-" + suffix;
}
text = text.replace(
"<FileVersion>" + currentFileVersion + "</FileVersion>",
"<FileVersion>" + nextVersion + "</FileVersion>"
);
fs.writeFileSync(projectFile, text, "utf8");
core.setOutput("version", nextVersion);
} catch (error) {
core.setFailed(error.message);
}
function yyyymmdd() {
function twoDigit(n) {
return (n < 10 ? "0" : "") + n;
}
var now = new Date();
return (
"" +
now.getFullYear() +
"." +
twoDigit(now.getMonth() + 1) +
"." +
twoDigit(now.getDate())
);
}