-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b213ee9
commit 751de53
Showing
2 changed files
with
53 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
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'); | ||
|
||
|
||
// 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'); | ||
} | ||
|
||
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'); | ||
} | ||
|
||
if(printFile) { | ||
var fileContents = fs.readFileSync(csproj, 'utf8'); | ||
console.log(fileContents); | ||
} | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} |