From 0f412948e45ed9f0096834f617d0085741d8a507 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Sun, 1 Oct 2023 15:39:30 +0300 Subject: [PATCH] Update index js Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 99f6a24..afb74bc 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const core = require('@actions/core') const github = require('@actions/github') const fs = require('fs') const axios = require('axios'); +import convert from 'xml-js'; run(); async function run() { @@ -182,10 +183,13 @@ function getProjectInfoFilePath(filePath, relativeToRoot = false) { function getProjectVersion(filePath) { const projectInfoFile = require(filePath); - // Update the version if the file is .csproj - if (filePath.match(/\.csproj/)) - return projectInfoFile.Project.PropertyGroup[0].Version; - else if (filePath.match(/package\.json/)) + if (filePath.match(/\.csproj/)) { + + const convertedToJson = convert.xml2js(projectInfoFile); + // elements[0] -> PropertyGroup -> Version (object) -> text (e.g. 1.2.3) + return convertedToJson.elements[0].elements.find(el => el.name == 'PropertyGroup').elements.find(el => el.name == 'Version').elements.find(el => el.type == 'text').text; + + } else if (filePath.match(/package\.json/)) return projectInfoFile.version; }