From 751de5326ca2482abd48bfe93ee71c359b2d133a Mon Sep 17 00:00:00 2001 From: Konstantin Semenenko Date: Thu, 13 Apr 2023 00:04:20 +0200 Subject: [PATCH] js --- action.yml | 31 +++++++++++-------------------- index.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 index.js diff --git a/action.yml b/action.yml index 0601372..293d549 100644 --- a/action.yml +++ b/action.yml @@ -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|()(.*)()|Old: \1\2\3|p' ${{ inputs.csproj }} - sed -rE 's|()(.*)()|${{ inputs.version }}|g' ${{ inputs.csproj }} - sed -rn 's|()(.*)()|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|()(.*)()|Old: \1\2\3|p' ${{ inputs.csproj }} - sed -rE 's|()(.*)()|${{ inputs.displayVersion }}|g' ${{ inputs.csproj }} - sed -rn 's|()(.*)()|New: \1\2\3|p' ${{ inputs.csproj }} - + using: 'node16' + main: 'index.js' \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..d4726c9 --- /dev/null +++ b/index.js @@ -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 followed by any sequence of characters that are not a '<', followed by + const applicationVersionPattern = /[^<]*<\/ApplicationVersion>/g; + const applicationDisplayVersionPattern = /[^<]*<\/ApplicationDisplayVersion>/g; + + if (version && version.trim() !== '') { + // Read the file contents + var fileContents = fs.readFileSync(csproj, 'utf8'); + var updatedApplicationVersion = fileContents.replace(applicationVersionPattern, `${version}`); + // 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, `${displayVersion}`); + // 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); +} \ No newline at end of file