-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (39 loc) · 1.98 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const core = require('@actions/core');
const github = require('@actions/github');
try {
const fs = require('fs');
const csproj = core.getInput('csproj');
const version = core.getInput('version');
const displayVersion = core.getInput('displayVersion');
const printFile = core.getInput('printFile');
if (version && version.trim() == '') {
core.setFailed("Paramenter csproj is required.");
}
// match <ApplicationVersion> followed by any sequence of characters that are not a '<', followed by </ApplicationVersion>
const applicationVersionPattern = /<ApplicationVersion>[^<]*<\/ApplicationVersion>/g;
const applicationDisplayVersionPattern = /<ApplicationDisplayVersion>[^<]*<\/ApplicationDisplayVersion>/g;
if (version && version.trim() !== '') {
// Read the file contents
var fileContents = fs.readFileSync(csproj, 'utf8');
var updatedApplicationVersion = fileContents.replace(applicationVersionPattern, `<ApplicationVersion>${version}</ApplicationVersion>`);
// Write the updated contents back to the file
fs.writeFileSync(csproj, updatedApplicationVersion, 'utf8');
console.log(`<ApplicationVersion>${version}</ApplicationVersion>`);
}
if (displayVersion && displayVersion.trim() !== '') {
// Read the file contents
var fileContents = fs.readFileSync(csproj, 'utf8');
var updatedApplicationVersion = fileContents.replace(applicationDisplayVersionPattern, `<ApplicationDisplayVersion>${displayVersion}</ApplicationDisplayVersion>`);
// Write the updated contents back to the file
fs.writeFileSync(csproj, updatedApplicationVersion, 'utf8');
console.log(`<ApplicationDisplayVersion>${displayVersion}</ApplicationDisplayVersion>`);
}
if(printFile == true) {
var fileContents = fs.readFileSync(csproj, 'utf8');
console.log('');
console.log(fileContents);
}
}
catch (error) {
core.setFailed(error.message);
}