Skip to content

Commit 751de53

Browse files
committed
js
1 parent b213ee9 commit 751de53

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

action.yml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,19 @@ inputs:
77
default: '1'
88
version:
99
description: 'Value for ApplicationVersion property'
10-
required: true
10+
required: false
1111
default: '1'
1212
displayVersion:
1313
description: 'Value for ApplicationVersion property'
14-
required: true
14+
required: false
1515
default: '1.0'
16+
printFile:
17+
description: 'Print file content'
18+
required: false
19+
default: true
20+
#outputs:
21+
# time: # id of output
22+
# description: 'The time we greeted you'
1623
runs:
17-
using: "composite"
18-
steps:
19-
- name: Bump ApplicationVersion (build version)
20-
shell: bash
21-
run: |
22-
echo 'Setting ApplicationVersion (build version) to ${{ inputs.version }}'
23-
sed -rn 's|(<ApplicationVersion>)(.*)(</ApplicationVersion>)|Old: \1\2\3|p' ${{ inputs.csproj }}
24-
sed -rE 's|(<ApplicationVersion>)(.*)(</ApplicationVersion>)|<ApplicationVersion>${{ inputs.version }}</ApplicationVersion>|g' ${{ inputs.csproj }}
25-
sed -rn 's|(<ApplicationVersion>)(.*)(</ApplicationVersion>)|New: \1\2\3|p' ${{ inputs.csproj }}
26-
27-
- name: Bump ApplicationDisplayVersion (build version)
28-
shell: bash
29-
run: |
30-
echo 'Setting ApplicationDisplayVersion (build version) to ${{ inputs.displayVersion }}'
31-
sed -rn 's|(<ApplicationDisplayVersion>)(.*)(</ApplicationDisplayVersion>)|Old: \1\2\3|p' ${{ inputs.csproj }}
32-
sed -rE 's|(<ApplicationDisplayVersion>)(.*)(</ApplicationDisplayVersion>)|<ApplicationDisplayVersion>${{ inputs.displayVersion }}</ApplicationDisplayVersion>|g' ${{ inputs.csproj }}
33-
sed -rn 's|(<ApplicationDisplayVersion>)(.*)(</ApplicationDisplayVersion>)|New: \1\2\3|p' ${{ inputs.csproj }}
34-
24+
using: 'node16'
25+
main: 'index.js'

index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
const core = require('@actions/core');
3+
const github = require('@actions/github');
4+
5+
try {
6+
7+
const fs = require('fs');
8+
9+
const csproj = core.getInput('csproj');
10+
const version = core.getInput('version');
11+
const displayVersion = core.getInput('displayVersion');
12+
const printFile = core.getInput('printFile');
13+
14+
15+
// match <ApplicationVersion> followed by any sequence of characters that are not a '<', followed by </ApplicationVersion>
16+
const applicationVersionPattern = /<ApplicationVersion>[^<]*<\/ApplicationVersion>/g;
17+
const applicationDisplayVersionPattern = /<ApplicationDisplayVersion>[^<]*<\/ApplicationDisplayVersion>/g;
18+
19+
if (version && version.trim() !== '') {
20+
// Read the file contents
21+
var fileContents = fs.readFileSync(csproj, 'utf8');
22+
var updatedApplicationVersion = fileContents.replace(applicationVersionPattern, `<ApplicationVersion>${version}</ApplicationVersion>`);
23+
// Write the updated contents back to the file
24+
fs.writeFileSync(csproj, updatedApplicationVersion, 'utf8');
25+
}
26+
27+
if (displayVersion && displayVersion.trim() !== '') {
28+
// Read the file contents
29+
var fileContents = fs.readFileSync(csproj, 'utf8');
30+
var updatedApplicationVersion = fileContents.replace(applicationDisplayVersionPattern, `<ApplicationDisplayVersion>${displayVersion}</ApplicationDisplayVersion>`);
31+
// Write the updated contents back to the file
32+
fs.writeFileSync(csproj, updatedApplicationVersion, 'utf8');
33+
}
34+
35+
if(printFile) {
36+
var fileContents = fs.readFileSync(csproj, 'utf8');
37+
console.log(fileContents);
38+
}
39+
}
40+
catch (error) {
41+
core.setFailed(error.message);
42+
}

0 commit comments

Comments
 (0)