Skip to content

Commit

Permalink
js
Browse files Browse the repository at this point in the history
  • Loading branch information
KSemenenko committed Apr 12, 2023
1 parent b213ee9 commit 751de53
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
31 changes: 11 additions & 20 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,19 @@ inputs:
default: '1'
version:
description: 'Value for ApplicationVersion property'
required: true
required: false
default: '1'
displayVersion:
description: 'Value for ApplicationVersion property'
required: true
required: false
default: '1.0'
printFile:
description: 'Print file content'
required: false
default: true
#outputs:
# time: # id of output
# description: 'The time we greeted you'
runs:
using: "composite"
steps:
- name: Bump ApplicationVersion (build version)
shell: bash
run: |
echo 'Setting ApplicationVersion (build version) to ${{ inputs.version }}'
sed -rn 's|(<ApplicationVersion>)(.*)(</ApplicationVersion>)|Old: \1\2\3|p' ${{ inputs.csproj }}
sed -rE 's|(<ApplicationVersion>)(.*)(</ApplicationVersion>)|<ApplicationVersion>${{ inputs.version }}</ApplicationVersion>|g' ${{ inputs.csproj }}
sed -rn 's|(<ApplicationVersion>)(.*)(</ApplicationVersion>)|New: \1\2\3|p' ${{ inputs.csproj }}
- name: Bump ApplicationDisplayVersion (build version)
shell: bash
run: |
echo 'Setting ApplicationDisplayVersion (build version) to ${{ inputs.displayVersion }}'
sed -rn 's|(<ApplicationDisplayVersion>)(.*)(</ApplicationDisplayVersion>)|Old: \1\2\3|p' ${{ inputs.csproj }}
sed -rE 's|(<ApplicationDisplayVersion>)(.*)(</ApplicationDisplayVersion>)|<ApplicationDisplayVersion>${{ inputs.displayVersion }}</ApplicationDisplayVersion>|g' ${{ inputs.csproj }}
sed -rn 's|(<ApplicationDisplayVersion>)(.*)(</ApplicationDisplayVersion>)|New: \1\2\3|p' ${{ inputs.csproj }}
using: 'node16'
main: 'index.js'
42 changes: 42 additions & 0 deletions index.js
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);
}

0 comments on commit 751de53

Please sign in to comment.